Initial commit

This commit is contained in:
jiapengyu
2026-07-27 13:38:37 +08:00
parent ecba71e2a5
commit 7955038435
2 changed files with 30 additions and 46 deletions
+26 -46
View File
@@ -1,50 +1,30 @@
const simpleGit = require('simple-git')
const path = require('path')
const { execSync } = require('child_process');
const fs = require('fs');
const git = simpleGit(path.join(__dirname))
const gitPath = 'D:\\Git\\bin\\git.exe';
const run = async () => {
try {
console.log('=== 初始化Git仓库 ===')
await git.init()
console.log('=== 设置用户信息 ===')
await git.addConfig('user.name', 'jiapengyu')
await git.addConfig('user.email', 'jiapengyu@example.com')
console.log('=== 设置远程仓库 ===')
const remoteUrl = 'git@git.torchcloud.cn:jiapengyu/huishou.git'
await git.addRemote('origin', remoteUrl)
console.log('=== 添加所有文件 ===')
await git.add('.')
console.log('=== 提交代码 ===')
await git.commit('Initial commit - huishou project')
console.log('=== 推送代码 ===')
await git.push('origin', 'main', { '--set-upstream': null })
console.log('=== 推送成功 ===')
} catch (error) {
console.error('=== 推送失败 ===')
console.error(error.message)
// 如果main分支不存在,尝试创建
if (error.message.includes('fatal: A branch named')) {
try {
console.log('=== 创建main分支 ===')
await git.checkoutLocalBranch('main')
await git.add('.')
await git.commit('Initial commit - huishou project')
await git.push('origin', 'main', { '--set-upstream': null })
console.log('=== 推送成功 ===')
} catch (err) {
console.error('=== 仍然失败 ===')
console.error(err.message)
}
}
try {
console.log('=== Remove lock file ===');
const lockFile = 'D:\\Trae\\huishou\\.git\\index.lock';
if (fs.existsSync(lockFile)) {
fs.unlinkSync(lockFile);
console.log('Lock file removed');
}
}
run()
console.log('=== Add all files ===');
execSync(`${gitPath} add .`, { stdio: 'inherit', cwd: __dirname });
console.log('=== Commit code ===');
execSync(`${gitPath} commit -m "Initial commit"`, { stdio: 'inherit', cwd: __dirname });
console.log('=== Add remote ===');
execSync(`${gitPath} remote add origin git@git.torchcloud.cn:jiapengyu/huishou.git`, { stdio: 'inherit', cwd: __dirname });
console.log('=== Push to remote ===');
execSync(`${gitPath} push -u origin master`, { stdio: 'inherit', cwd: __dirname });
console.log('=== Success ===');
} catch (error) {
console.error('=== Failed ===');
console.error(error.message);
}
+4
View File
@@ -0,0 +1,4 @@
@echo off
D:\Git\bin\git.exe commit -m "Initial commit"
D:\Git\bin\git.exe remote add origin git@git.torchcloud.cn:jiapengyu/huishou.git
D:\Git\bin\git.exe push -u origin master