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
+20 -40
View File
@@ -1,50 +1,30 @@
const simpleGit = require('simple-git') const { execSync } = require('child_process');
const path = require('path') const fs = require('fs');
const git = simpleGit(path.join(__dirname)) const gitPath = 'D:\\Git\\bin\\git.exe';
const run = async () => {
try { try {
console.log('=== 初始化Git仓库 ===') console.log('=== Remove lock file ===');
await git.init() const lockFile = 'D:\\Trae\\huishou\\.git\\index.lock';
if (fs.existsSync(lockFile)) {
fs.unlinkSync(lockFile);
console.log('Lock file removed');
}
console.log('=== 设置用户信息 ===') console.log('=== Add all files ===');
await git.addConfig('user.name', 'jiapengyu') execSync(`${gitPath} add .`, { stdio: 'inherit', cwd: __dirname });
await git.addConfig('user.email', 'jiapengyu@example.com')
console.log('=== 设置远程仓库 ===') console.log('=== Commit code ===');
const remoteUrl = 'git@git.torchcloud.cn:jiapengyu/huishou.git' execSync(`${gitPath} commit -m "Initial commit"`, { stdio: 'inherit', cwd: __dirname });
await git.addRemote('origin', remoteUrl)
console.log('=== 添加所有文件 ===') console.log('=== Add remote ===');
await git.add('.') execSync(`${gitPath} remote add origin git@git.torchcloud.cn:jiapengyu/huishou.git`, { stdio: 'inherit', cwd: __dirname });
console.log('=== 提交代码 ===') console.log('=== Push to remote ===');
await git.commit('Initial commit - huishou project') execSync(`${gitPath} push -u origin master`, { stdio: 'inherit', cwd: __dirname });
console.log('=== 推送代码 ===') console.log('=== Success ===');
await git.push('origin', 'main', { '--set-upstream': null })
console.log('=== 推送成功 ===')
} catch (error) { } catch (error) {
console.error('=== 推送失败 ===') console.error('=== Failed ===');
console.error(error.message) 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)
} }
}
}
}
run()
+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