const { execSync } = require('child_process'); const fs = require('fs'); const gitPath = 'D:\\Git\\bin\\git.exe'; 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'); } 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); }