出于代码审查的目的,我想
- 樱桃选择特定提交
- 与他们一起创建一个新分支并
- 将该分支推送到远程
这样我就可以将分支 url 提供给同行进行审核。
我想创建一个 shell 脚本并发出简单的命令,例如
git-review <trackingID>
它给出的输出如下
Branch <currentgitusername>_<trackingID> created and pushed to remote.
我编写了一个执行上述步骤的脚本。
#!/bin/bash
if [ -z $1 ]; then
echo "Rationale: Cherry pick all commits in master, matching the tracking ID and create a new branch.";
echo "";
echo "Usage: $0 traackingID";
echo "";
exit 1;
fi
#If $1 doesn't match a AGW-<number> pattern, thrown an error
#Best of luck if you did not add add tracking ID in commits.
user="$(id -u -n)" > /dev/null
echo "You are - $user"
branchname=$user"_"$1"_review"
echo "Creating branch - $branchname"
git checkout -b $branchname > /dev/null
git log master --pretty=%H --grep="$1" | while read rev
do
echo $rev
# git cherry-pick $rev > /dev/null
done
#git push &> /dev/null
echo "Created branch, cherry picked, pushed to remote. Now switching back to master. Bye."
git checkout master
但卡在几个地方。
- 我想验证 TrackingID 格式。它应该是
AGW-<somenumber>
-
看起来樱桃精选有合并问题。
myname@mymachine ~/myproj
$ ../git-review.sh AGW-1234
You are - myname
Creating branch - myname_AGW-1234_review
Switched to a new branch 'myname_AGW-1234_review'
2dfafa89e10062e7cfccb1d7a947ebb848c40cc6
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:
git commit --allow-empty
Otherwise, please use 'git reset'
1e295000bc3d80880518c9cac5e34ef3b28fc29e
error: Your local changes to the following files would be overwritten by merge:
rest-service/src/main/java/package/HealthCheckDAOImpl.java
Please, commit your changes or stash them before you can merge.
我采摘樱桃的方式错了吗?另外,请提出任何更改建议,以使该脚本更加健壮。
正如@novelocrat 的评论中已经指出的那样,您以错误的顺序挑选樱桃。默认情况下,git log 会从最新的提交输出到第一次提交。为此,要么输入以下输出git log --oneline
to tac
,或使用--reverse
flag:
git log --oneline | tac
git log --oneline --reverse
显然第二个选项是首选,因为这确保了逐行输出,而第一个(使用tac
)需要一次性输入所有输入。
另外,由于您正在从 master 中创建一个新分支,因此当您这样做时git checkout -b $branchname
.
当您这样做时,当前分支的所有历史记录都会从中选取。
所以你需要创建一个孤立的 git 分支,就像这里提到的 https://stackoverflow.com/a/4288660/1860929.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)