写了个 git push 脚本,容易崩溃,有大神给点意见么

2015-12-10 11:21:32 +08:00
 wikinee
# !/bin/bash
# maybe you are using bash,fix the first line.
# Program:
# THIS PROGRAM IS FOR GIT PUSH
# BEFORE USE THIS SCRIPT, YOU MUST ADD YOU GIT PRIVATE KEY,LIKE FOLLOW SHELL COMMAND.
# ssh-add you_ssh_private_key_path,like ssh-add ~/.ssh_github/id_rsa
# History:
# 2015/10 wikinee First release
# ENV
# ubuntu 14.04 LTS
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin/:~/bin
export PATH

echo "===========git config========="
echo "Ignore Permission"
git config core.fileMode false
echo "===========git branch========="
git branch
echo "===========git fetch==========="
echo "Input destination branch, must be already exist in remote.Enter use master:"
read to_branch
echo "Add tmp branch to store diff"
git fetch origin ${to_branch:=master}:tmp
echo "This time will modify following:"
git diff tmp
read -p "Merge it, y or Y?" yn
if [ "$yn" == "Y" ]||[ "$yn" == "y" ] ;then
echo $yn
echo "now merge it."
git merge tmp
else echo "Illeagal Character."
exit
fi

echo "===========git status========="
git status
echo "Input git add parameter,like -A"
read input1
git add $input1
echo "===========git commit========="
read -p "Git commit this changes?(y/n)" yn
if [ "$yn" == "Y" ]||[ "$yn" == "y" ] ;then
echo $yn
echo "Pow you can input commit message:"
elif [ "$yn" == "N" ]||[ "$yn" == "n" ] ;then
echo $yn
echo "Not Committed."
exit
else echo "illeagal character."
exit
fi
read input2
git commit -m "$input2" -a
echo "===========git push==========="
echo "Push to git?(y/n)"
read push_choice
if [ "$push_choice" == "y" ]||[ "$push_choice" == "Y" ] ;then
echo "Now push files,you can give parameter 1,default 'origin'."
read input3
echo "Now push files,you can give parameter 2,default 'master'."
read input4
git push -u $input3 $input4
else
echo "Already Commit, But Not Pushed"
fi
3545 次点击
所在节点    Linux
11 条回复
wlsnx
2015-12-10 12:07:44 +08:00
我建议手打这些命令,可以更自由地调整流程,出了问题也容易发现和修改,合并 PR 之前检查清楚。
wikinee
2015-12-10 12:33:30 +08:00
@wlsnx 目前在使用 alias 简化命令, 脚本是更进一步简化
500miles
2015-12-10 12:55:36 +08:00
太长 太乱 不看 (:教导主任的表情

哈哈
spacewander
2015-12-10 13:14:48 +08:00
崩溃是什么情况?有出错信息吗?
感觉合并和提交可以分开两个脚本来写。另外没必要每次执行的时候都设置 PATH 和`git config`。
KyleMeow
2015-12-10 16:52:47 +08:00
至少每步执行后需要判断返回值 $? 是不是 0 才继续下一步吧,不然一步没成,后面都在做无用功
jackysc
2015-12-10 16:53:54 +08:00
bash -x 调试吧
GNiux
2015-12-10 17:45:15 +08:00
轻轻地说:楼主英语……不敢恭维……蹩脚……如:“ Enter use master ” —— Type Enter to use 'master':"

另,输入 n N 就是非法字符?
—— read -p "Merge it, y or Y?" yn
if [ "$yn" == "Y" ]||[ "$yn" == "y" ] ;then
echo $yn
echo "now merge it."
git merge tmp
else echo "Illeagal Character."
darkbill
2015-12-10 17:53:28 +08:00
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin/:~/bin
export PATH

我觉得开头的这两行语句的写法,要不得~~
人家电脑上面还有 /opt/bin 在 path 的怎么办?都被你洗了。
你要添加~/bin ,可以用字符串连接的方式来添加。。。
wikinee
2015-12-10 20:19:03 +08:00
@spacewander 好建议
@KyleMeow 我现在改成回车就继续,不然就推出
@jackysc 我说的崩溃是指的情况好复杂,太多种可能了
@GNiux 能看懂就好了, enlish 不好,又戳我伤心事
@darkbill path 这两句鸟哥私房菜上抄来的,你一说我都对人生产生怀疑,又去看了一眼,就是这么写的。
估计应该 PATH=xxx:$PATH
yzimhao
2015-12-11 11:08:19 +08:00
自己撸的一个发布代码工具,增量更新代码
代码: https://github.com/yzimhao/shellcode/blob/master/issuecode
说明: https://github.com/yzimhao/shellcode#1-issuecode
zhouyg
2015-12-11 17:07:09 +08:00
建议写成半自动的,经常需要思考的手打,然后固定的操作写成脚本。

一般而言,当我启动一些脚本时,就等它自动完成就好了。顺便喝口水。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/242479

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX