本文介绍了如何挤压分支中的所有合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有这样一个分支: A --- B --- B1 --- B2 --- D --- E --- E1 --- E2 --- G --- H \ / \ / C1 --- C2 ---'F1 --- F2- - ' 我想重写它,并使其如下所示: A --- B --- B1 --- B2 --- D --- E --- E1 --- E2 --- G --- H 这意味着,压缩所有合并。 分支很长。这如何自动完成? 编辑 这不是历史线性化。我想压扁所有的合并,比如D和G. 解决方案由于我们是樱桃选择提交消息,作者和作者日期将与原始提交相同,包括合并。 或者,您可以获取提交消息以及在合并前最后一次提交到分支的作者信息,即合并的第二个父代,方法是在第一个条件中添加以下行: git commit --amend -C $(git rev-parse $ rev ^ 2) 结帐基本提交$ b git checkout A〜0 Cherry pick所有提交: $ pre $ code $ for rev in $(git rev-list HEAD..branch-name --first-parent --reverse ) do if [[$(git show --summary --format =%P$ rev | wc -w)-gt 1]] then git cherry-pick $ rev --mainline 1 #git commit --amend -C $(git rev-pars e $ rev ^ 2) else git cherry-pick $ rev fi 完成 强制旧分支和结帐: git分支-f分支名称HEAD git checkout分行名称 I have a branch like this:A---B---B1---B2---D---E---E1---E2---G---H \ / \ / C1---C2---’ F1---F2---’I want to rewrite it and make it like this:A---B---B1---B2---D---E---E1---E2---G---HThat means, squashing all merges.The branch is very long. How can this be done automatically?EditThis is not a history linearization. I want to squash all merges, like D and G. 解决方案 This should do the trick. Since we are cherry picking the commit message, author, and author date will be the same as the original commits, including the merges.Alternatively, you can get the commit message and authorship information from the last commit to the branch before the merge, i.e., the merge's second parent, by adding the following line to the first condition:git commit --amend -C $(git rev-parse $rev^2)These commands can easily converted to a script if you do this often.Checkout base commit (in detached state):git checkout A~0Cherry pick all commits:for rev in $(git rev-list HEAD..branch-name --first-parent --reverse)do if [[ $(git show --summary --format="%P" $rev | wc -w ) -gt 1 ]] then git cherry-pick $rev --mainline 1 # git commit --amend -C $(git rev-parse $rev^2) else git cherry-pick $rev fidoneForce old branch and checkout:git branch -f branch-name HEADgit checkout branch-name 这篇关于如何挤压分支中的所有合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-04 20:36