0

当我运行类似我的提交列表的东西时,git rebase -i --rebase-merges eeb1425e0我的提交列表是倒置的,即第一个提交是最后一个,最后一个提交是第一个:

pick A Penultimate commit
pick B Penult commmit
pick C Latest commit

# Rebase eeb1425e..5a3f045b onto eeb1425e (288 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

然后,当 squash 选项显示时squash = use commit, but meld into previous commit,我按squash如下方式推送:

pick A Penultimate commit
squash B Penult commmit
pick C Latest commit

之前的提交Bis Aor C? B将与Aor合并C/挤压?

相关:

  1. 如果我已经开始变基,如何将两个提交合并为一个?
  2. git 的“rebase --preserve-merges”到底做了什么(为什么?)
4

1 回答 1

1

提交顺序确实与您通常看到的相反git log,因此:

pick A Penultimate commit
pick B Penult commmit
pick C Latest commit

如果您将第二行更改为 read squash,Git 将:

  • cherry-pick commitA开始进行新的提交,但尚未提交;
  • B在实际进行新提交之前将提交压缩到其中;和
  • 樱桃选择提交C以进行第二次新提交;

给你我喜欢画的东西,如:

          A--B--C   [abandoned]
         /
...--o--o--AB--C'   <-- branch-name

这里A-B-C链是原始的三个提交,最后一个绘制在右侧(而不是顶部或底部),新AB-C'链是两个新提交,最后一个绘制在右侧。您的分支名称用于标识提交C,现在标识新副本C'


旁注:倒数第三个词是antepenultimate。“倒数第二个”字面意思是“倒数第二个”。如果您需要确定倒数第四个,这是倒数第二个。“倒数第五”似乎没有英文单词。以下链接到达propreantepenultimate,但请参阅柯林斯词典中的状态。

另一个注意事项:交互式 rebase 愿意做出然后取消提交,所以上面的描述(“在实际提交之前挤压”)只是你在查看结果时会看到的简写,而不是对底层机械。实际的提交集可能包括额外放弃的临时提交。Git 最终会自行清理所有这些。

于 2020-05-02T09:10:58.900 回答