为了代码评审的目的,我想
这样我就可以把分支网址给同行看了。
我想创建一个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但被困在几个地方。
AGW-<somenumber>我是不是错采樱桃了?此外,请建议任何修改,以使此脚本健壮。
发布于 2015-02-26 07:35:59
正如@小说家的评论中所指出的那样,你的选择是错误的。默认情况下,git日志将从最近一次提交输出到第一次提交。为此,可以将git log --oneline输出中的提要输入到tac,或者使用--reverse标志:
git log --oneline | tac
git log --oneline --reverse第二个选项显然更好,因为这可以确保逐行输出,而第一个选项(使用tac)需要一次输入所有输入。
另外,当您执行git checkout -b $branchname时,因为您正在从Master中创建一个新的分支。
当您这样做时,当前分支的所有历史记录都是从中选择的。
因此,您需要创建一个孤立的git分支,like mentioned here。
https://stackoverflow.com/questions/28735942
复制相似问题