Shell操作git,上传更新文档

        有遇到这样的情况,需要定时修改下git仓库中的一些文件,比如,每周五统计下,本周git上代码发生的变化量,统计每个人的代码的写入量。要是整个部门,或整个公司的人员的代码变化量。靠手工操作就不行了。那么需要下面编写脚本来实现一条。然后配置crontab定时执行,将结果输出到指定的文件中。

# cat git-auto-commit-total.sh
cd /data/citigroup/localgit
echo "git pull citigroup-app-repository"
git pull  http://citigroup:Citi%40bcd6@10.19.14.47:8090/git/citigroup-program/citigroup-app-repository.git
cd /data/citigroup
sh git-auto-commit.sh "liuqiangdong";
sh git-auto-commit.sh "wangqiang";

1.在自己的本地创建一个目录,作文拉取源码的目录

2.要知道自己的git仓库信息。其中,配置成明文用户名:密码的方式。就可以用一个git账号去操作多个账号

3.执行git-auto-commit.sh,添加部门中的所有的人。也可以配置成数组,在数组中循环执行命令。 

我们再来看看git-auto-commit.sh的内容,具体要怎么写。

# cat git-auto-commit.sh
#git_name=$1
gitname=$1
echo $gitname
#rnd=$[$RANDOM%10*60]
rnd=$[$RANDOM%10*60]
echo "======================================================="
echo "休眠"$rnd"秒"
sleep $rnd
echo "正在做"${gitname}"的提交操作"
cd /data/citigroup/localgit/citigroup-app-repository
df -h >> ${gitname}.java
git add ${gitname}.java
git config user.name ${gitname}
git config user.email ${gitname}@citigroup.com
git commit -o ${gitname}.java -m '[tag]:[修改页面格式]'
git push http://citigroup:Citi%40bcd6@10.19.14.47:8090/git/citigroup-program/citigroup-app-repository.git
echo "完成"${gitname}"的提交操作"
echo "======================================================="

1.首先查看操作到哪位,打印出用户名

2.随机休息下一段时间。

3.进入到pull拉取的源码目录下

4.一波具体的操作。

5.git add 将修改的文件add进git中。

6.设置参数,账号名称,账号邮箱

7.提交注释,显示出做了哪些动作

8.推送到远程仓库,push操作。 

执行脚本

sh git-auto-commit-total.sh

Git指令的Shell脚本,能够快速便捷地管理Git库,包括添加修改、提交修改、显示库状态、推送到远程库、从远程库更新到本地、版本恢复等操作。 使用方法: 1. 在Linux系统中,将本文件放在Git库目录下,利用Shell运行本文件; 2.在windows系统中,需下载安装与操作系统相对应的Git软件,并将本文件放在Git库目录下,双击即可运行。 运行示例: Please choose the first letter of options. [Add|Commit|Diff|Fetch|Exit|Help|Log|Push|User|Reset|Status]? h A: Add all changes to repository. C: Commit all changes to repository. D: Show differences between current version with HEAD->. E: Exit shell script. F: Fetch origin/master and merge. L: Show latest two-weeks logs of repository. P: Push commissions to origin/master. U: User command mode(Press ‘Enter’ to exit). R: Reset current version according version_id. S: Show status of repository. Please choose the first letter of options. [Add|Commit|Diff|Fetch|Exit|Help|Log|Push|User|Reset|Status]? s On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: Git.sh modified: PyNote/PyNote_2.md no changes added to commit (use "git add" and/or "git commit -a") Please choose the first letter of options. [Add|Commit|Diff|Fetch|Exit|Help|Log|Push|User|Reset|Status]? a On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD ..." to unstage) modified: Git.sh modified: PyNote/PyNote_2.md
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值