git工程批量更新和自动提交

git工程批量更新

用gitbash客户端都有一种不爽,更新多个工程需要很多的fetch,rebase,stash等命令,所以无聊就看了下shell脚本,看能不能批量fetch,rebase,搞了下,还是可以的,不过我这个是直接pull,直接合并到当前工程。

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#/bin/bash
echo '**********选择更新的git项目**********'
echo '0.all'
echo '1.jiaxin_lib_core'
echo '2.jiaxin_lib_dubbox'
echo '3.jiaxin_web_devcenter'
echo '4.jiaxin_web_agent'
echo '5.jiaxin_web_conf'
echo '6.jiaxin_gw_statistics'
echo '7.jiaxin_gw_config'
echo '8.jiaxin_gw_container'
echo '9.jiaxin_gw_order'
read project
#在控制台输入1 2 3,它们之间用空格隔开。
if test $project -eq 0 ;then
echo '------------------------jiaxin_lib_core-----------------------'
cd jiaxin_lib_core && git pull && cd ..
echo '------------------------jiaxin_lib_dubbox-----------------------'
cd jiaxin_lib_dubbox && git pull && cd ..
echo '------------------------jiaxin_web_devcenter-----------------------'
cd jiaxin_web_devcenter && git pull && cd ..
echo '------------------------jiaxin_web_agent-----------------------'
cd jiaxin_web_agent && git pull && cd ..
echo '------------------------jiaxin_web_conf-----------------------'
cd jiaxin_web_conf && git pull && cd ..
echo '------------------------jiaxin_gw_statistics-----------------------'
cd jiaxin_gw_statistics && git pull && cd ..
echo '------------------------jiaxin_gw_config-----------------------'
cd jiaxin_gw_config && git pull && cd ..
echo '------------------------jiaxin_gw_container-----------------------'
cd jiaxin_gw_container && git checkout *.jar && git pull && cd ..
echo '------------------------jiaxin_gw_order-----------------------'
cd jiaxin_gw_order && git pull && cd ..
fi

if test $project -eq 1 ;then
echo '-----------------------jiaxin_lib_core-START-----------------------'

cd jiaxin_lib_core && git pull && cd ..
echo '------------------------jiaxin_lib_core-END-----------------------';
fi
if test $project -eq 2 ;then
echo '------------------------jiaxin_lib_dubbox-START----------------------'
cd jiaxin_lib_dubbox && git pull && cd ..
echo '-----------------------jiaxin_lib_dubbox-END-----------------------';
fi
if test $project -eq 3 ;then
echo '------------------------jiaxin_web_devcenter-START----------------------'
cd jiaxin_web_devcenter && git pull && cd ..
echo '-----------------------jiaxin_web_devcenter-END-----------------------';
fi
if test $project -eq 4 ;then
echo '------------------------jiaxin_web_agent-START----------------------'
cd jiaxin_web_agent && git pull && cd ..
echo '-----------------------jiaxin_web_agent-END-----------------------';
fi
if test $project -eq 5 ;then
echo '------------------------jiaxin_web_conf-START----------------------'
cd jiaxin_web_conf && git pull && cd ..
echo '-----------------------jiaxin_web_conf-END-----------------------';
fi
if test $project -eq 6 ;then
echo '------------------------jiaxin_gw_statistics-START----------------------'
cd jiaxin_gw_statistics && git pull && cd ..
echo '-----------------------jiaxin_gw_statistics-END-----------------------';
fi
if test $project -eq 7 ;then
echo '------------------------jiaxin_gw_config-START----------------------'
cd jiaxin_gw_config && git pull && cd ..
echo '-----------------------jiaxin_gw_config-END-----------------------';
fi
if test $project -eq 8 ;then
echo '------------------------jiaxin_gw_container-START----------------------'
cd jiaxin_gw_container && git checkout *.jar && git pull && cd ..
echo '-----------------------jiaxin_gw_container-END-----------------------';
fi
if test $project -eq 9 ;then
echo '------------------------jiaxin_gw_order-START----------------------'
cd jiaxin_gw_order && git pull && cd ..
echo '-----------------------jiaxin_gw_order-END-----------------------';
fi

git工程push

#/bin/bash
echo '**********选择push的git项目**********'
echo '1.jiaxin_lib_core'
echo '2.jiaxin_lib_dubbox'
echo '3.jiaxin_web_devcenter'
echo '4.jiaxin_web_agent'
echo '5.jiaxin_web_conf'
echo '6.jiaxin_gw_statistics'
echo '7.jiaxin_gw_config'
echo '8.jiaxin_gw_order'

read project
echo '请输入提交参数commit:'
read commit
               #在控制台输入1 2 3,它们之间用空格隔开。
if test $project -eq 1 ;then   
echo '-----------------------jiaxin_lib_core-START-----------------------' 
cd jiaxin_lib_core && git add -A && git commit -m $commit && git push origin HEAD:refs/for/master && cd ..
echo '------------------------jiaxin_lib_core-END-----------------------';
fi
if test $project -eq 2  ;then
echo '------------------------jiaxin_lib_dubbox-START----------------------'
cd jiaxin_lib_dubbox && git add -A && git commit -m $commit && git push origin HEAD:refs/for/master && cd ..
echo '-----------------------jiaxin_lib_dubbox-END-----------------------';
fi
if test $project -eq 3  ;then
echo '------------------------jiaxin_web_devcenter-START----------------------'
cd jiaxin_web_devcenter && git add -A && git commit -m $commit && git push origin HEAD:refs/for/master && cd ..
echo '-----------------------jiaxin_web_devcenter-END-----------------------';
fi
if test $project -eq 4  ;then
echo '------------------------jiaxin_web_agent-START----------------------'
cd jiaxin_web_agent && git add -A && git commit -m $commit && git push origin HEAD:refs/for/master && cd ..
echo '-----------------------jiaxin_web_agent-END-----------------------';
fi
if test $project -eq 5  ;then
echo '------------------------jiaxin_web_conf-START----------------------'
cd jiaxin_web_conf && git add -A && git commit -m $commit && git push origin HEAD:refs/for/master && cd ..
echo '-----------------------jiaxin_web_conf-END-----------------------';
fi
if test $project -eq 6  ;then
echo '------------------------jiaxin_gw_statistics-START----------------------'
cd jiaxin_gw_statistics && git add -A && git commit -m $commit && git push origin HEAD:refs/for/master && cd ..
echo '-----------------------jiaxin_gw_statistics-END-----------------------';
fi
if test $project -eq 7  ;then
echo '------------------------jiaxin_gw_config-START----------------------'
cd jiaxin_gw_config && git add -A && git commit -m $commit && git push origin HEAD:refs/for/master && cd ..
echo '-----------------------jiaxin_gw_config-END-----------------------';
fi
if test $project -eq 8  ;then
echo '------------------------jiaxin_gw_order-START----------------------'
cd jiaxin_gw_order && git add -A && git commit -m $commit && git push origin HEAD:refs/for/master && cd ..
echo '-----------------------jiaxin_gw_order-END-----------------------';
fi  

执行脚本

使用git客户端切换到git的根目录,执行脚本命令即可。

./update.sh

./push.sh

注意事项

  • 脚本放到git根目录,其实不放也可以的。你喜欢,我的脚本位置
  • 根据个人需要修改相应git命令,以免造成代码混乱,容易产生冲突
  • 还有push的时候,也是需要按照个人需要修改的,因为git add的时候是全部的,最好区分一下
  • 相关代码已上传到github 链接
wenthywang wechat
if you have any problems, you can contact me by my public wechat account.
other,please leave your email address.
无论怎么样 我都会继续Share我的一点一滴!