git自动提交脚本
bash脚本
可以用bsah
写命令行脚本。
比如写了个git.sh
,然后用bash git.sh
来运行。
这个是我写来自动提交git的脚本:
#!/bin/bash
echo "================="
echo "auto git by JOEY"
echo "======= 🤪 ========="
echo -e "
▶ \033[33;1mgit add .
\033[0m"
git add .
git status
echo -e "
▶ \033[33;1mcommit message:
\033[37;1m"
read msg
echo -e "
▶ \033[33;1mgit commit -m '$msg'
\033[0m"
git commit -m "$msg"
echo -e "
▶ \033[33;1mgit push
"
echo -e "\033[37;1mstart pushing ...\033[0m
"
git push
echo -e "
\033[37;1mAll Done\033[0m"
echo,是用来打印在命令行上面的

然后是正常的git操作,也可以加点别的东西
echo -n
的作用是,打印完这句话不换行。下一行的
read
会让命令行等待,直至用户输入信息。输入的信息在这里会被放进msg
这个变量里面当然
read -p
也能做到,不过只能输入一个单词,多输入的内容会被执行,就很麻烦。然后把输入的
msg
加到commit的信息里面,就能上传了最后自动push到远端仓库
执行效果

inquirer+simple-git
Simple-git能获取git的信息,比如有哪些没提交、哪些提交了。
const git = require('simple-git');
git()
.status((err, status) => { console.log("status", status) })

而inquirer能打造一个可交互的命令行,来让提交变得更友好。
console.log("=================")
console.log("auto git by JOEY")
console.log("====== 🤪========")
const inquirer = require('inquirer')
const promptList = [
{
type: 'checkbox',
message: 'choose files to add',
name: 'add',
choices: [
"file1.js",
"file2.go"
]
},
{
type: "input",
message: "commit message:",
name: "commit"
}
]
inquirer.prompt(promptList).then((answers) => {
console.log('结果为:')
console.log(answers)
})


这种交互,总比手动输入git add
的文件名要好多了吧
Last updated
Was this helpful?