为多个樱桃采摘创建一次提交

时间:2018-10-17 10:49:25

标签: git

我试图在for循环中挑选一份提交列表,而这样做的时候,我遇到了很多合并冲突,如下所述。

git checkout target_branch
for cpHash in "some random list of commits"; do
   git chery-pick --no-commit $cpHash
   git ls-files -u | cut -f2 | sort -u | xargs -i{} git checkout --. 
   theirs {}
   git add -A .
   git commit -m "some text"
done

如上所述,循环内的git commit只是为了清理存储库,以便在该版本上进行下一个选择,但是这很简单,只是git历史记录。 我需要在for循环中将所有这些提交合并到一个单一的提交中,这将在我们的应用程序中进行跟踪。

我该如何实现? 我不打算使用git rebase,因为回购在多个团队之间共享。

谢谢。 库玛吉特

1 个答案:

答案 0 :(得分:0)

一种方法可能是修改for循环内的提交,例如

git checkout target_branch
git commit --allow-empty -m "final commit message"
for cpHash in "some random list of commits"; do
   git chery-pick --no-commit $cpHash
   git ls-files -u | cut -f2 | sort -u | xargs -i{} git checkout --. 
   theirs {}
   git add -A .
   git commit --amend --no-edit
done

顺便说一下,rebase只是一些随之而来的小问题。