使用repo 批量回退到某个时间点,并同步至gerrit服务器
作者:互联网
项目组需求例如从master分支拉取从某个时间点之前的代码为base,新建一个branch 为 test
第一步创建分支
执行create_branch.bash脚本如下
#!/bin/sh
cat ./default.xml | grep \<project | while read line
do
local_path=$(echo $line|awk -F"\"" '{print $2}')
pro=$(echo $line|awk -F"\"" '{print $4}')
echo "local_path: $local_path"
echo "remote_path: $pro"
echo $pro
ssh -p 29418 远程服务器xxx gerrit create-branch "xxx/xxx/"$pro test master &
wait
done
第二步下载代码
repo init -u ssh://xx@192.168.xx.xx:29418/xxxxx/xxx/platform/manifest -b yourbranch --repo-url=ssh://xxx@192.168.xx.xx:29418/tools/repo
repo sync -dcq
第三步批量回退
repo forall -c 'commitID=git log --before "2018-09-10 23:59:59" -1 --pretty=format:"%H"; git reset --hard $commitID'
第四步同步代码到gerrit
push_code.sh脚本如下:
#!/bin/bash
cat ./default.xml | grep \<project | while read line
do
local_path=$(echo $line|awk -F"\"" '{print $2}')
pro=$(echo $line|awk -F"\"" '{print $4}')
echo "local_path: $local_path"
echo "remote_path: $pro"
cd ${local_path}
git remote add xx ssh://xxxxxxxxx/$pro
git fetch xx
git push xx HEAD:test -f
cd -
done
标签:pro,gerrit,echo,repo,xx,回退,path,local 来源: https://blog.csdn.net/Nemo1210/article/details/120494307