前言
Hi,xdm!我实在太懒了,每次提交到Git仓库都要输入好多行命令,我麻了...
So,我写了一个JS脚本,一行命令提交代码到自己的仓库中。
跟我一起node index.js 提交吧!
看源码
const git1 = require('simple-git/promise')
const path = `提交的路径`
const commitMessage = '提交消息'
const target_git = 'git路径'
const target_ssh = 'ssh路径'
async function submit() {
console.log('开始读取路径');
let sg = git1(path)
console.log('路径已读取'+ path);
console.log('开始拉取');
await sg.pull(target_ssh)
console.log('路径已拉取' + 'git pull ' + target_ssh);
console.log('开始添加文件');
await sg.add('./*')
console.log('已添加新增文件');
console.log('开始提交消息');
await sg.commit(commitMessage)
console.log('已提交消息');
console.log('开始push');
await sg.push(target_ssh)
console.log('提交成功' + '已提交至' + target_ssh);
}
submit()
使用手册
你需要先安装一个simple-git包
yarn add simple-git
然后设置4个参数
-
path提交路径,是你仓库的文件夹,不是当前文件夹 -
commitMessage消息,不多bb了 -
target_gitgit的提交路径 -
target_sshssh的提交路径
代码用的是ssh的提交路径,相比git,我还是觉得ssh提交的快,不过你要在你的电脑上生成rsa证书,这个还是比较麻烦的
设置好之后,你就可以一行命令提交啦!