git.sh
799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#/bin/bash
function usage(){
echo "----------------------------------"
echo "参数说明:"
echo "-t : 操作类型"
echo "-f : 父路径"
echo "-c : 文件名"
echo ""
echo "举例:sh git.sh -t \"reset_pull\" -f /opt/jmeter/script -c test.jmx"
echo "----------------------------------"
}
if [[ $# -lt 1 ]];then
usage
exit 1
fi
while getopts "t:f:c:" arg
do
case $arg in
t)
gittype=$OPTARG
;;
f)
fatherPath=$OPTARG
;;
c)
filename=$OPTARG
;;
h)
usage
exit 1
;;
?)
echo "未知的参数!"
exit 1
;;
esac
done
if [[ "$gittype" == "reset_pull" && -n "$fatherPath" ]];then
cd $fatherPath
pwd
git reset --hard origin/master
git pull
fi
if [[ "$gittype" == "add_push" && -n "$fatherPath" && -n "$filename" ]];then
cd $fatherPath
pwd
git add $filename
git commit -m "commit by shell"
git push
fi