我如何挤压两个不连续的提交? [英] How do I squash two non-consecutive commits?

查看:76
本文介绍了我如何挤压两个不连续的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对git中的整个重新绑定功能有点新鲜。假设我做了以下提交:

  A  - > B  - > C  - > D 

之后,我意识到 D 包含一个修补程序取决于 A 中添加的一些新代码,并且这些提交属于一起。我如何压扁 A & D 在一起并且离开 B &您可以运行 C 单独?

解决方案 git rebase --interactive 并在B之前重新排序D并将D压缩到A中。

Git会打开一个编辑器,这:

  pick aaaaaaa提交A 
pick bbbbbbb提交B
提交ccccccc提交C
选择ddddddd提交D

#将aaaaaaa..dddddd重新映射到1234567(4个命令)

#命令:
#p,pick = use commit
#r,reword =使用提交,但编辑提交消息
#e,edit =使用提交,但停止修改
#s,squash =使用提交,但融入前一提交
#f,fixup = likesquash,但放弃这个提交的日志消息
#x,exec =运行命令(该行的其余部分)使用shell

#这些线可以重新排序;他们从上到下执行。

#如果你在这里删除一行,那么COMMIT将会丢失。

#但是,如果您删除了所有内容,那么rebase将被中止。

#注意空提交被注释掉

现在你改变看起来像这样的文件:

  pick aaaaaaa提交A 
squash ddddddd提交D
pick bbbbbbb提交B
pick ccccccc Commit C

现在git将把A和D的变化融合在一起合并为一个提交,然后放入B和C.当您不想保留D的提交信息时,您也可以使用修复关键字。


I'm a bit new to the whole rebasing feature within git. Let's say that I made the following commits:

A -> B -> C -> D

Afterwards, I realize that D contains a fix which depends on some new code added in A, and that these commits belong together. How do I squash A & D together and leave B & C alone?

解决方案

You can run git rebase --interactive and reorder D before B and squash D into A.

Git will open an editor, and you see a file like this:

pick aaaaaaa Commit A
pick bbbbbbb Commit B
pick ccccccc Commit C
pick ddddddd Commit D

# Rebase aaaaaaa..ddddddd onto 1234567 (4 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# 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

Now you change the file that it looks like this:

pick aaaaaaa Commit A
squash ddddddd Commit D
pick bbbbbbb Commit B
pick ccccccc Commit C

And git will now meld the changes of A and D together into one commit, and put B and C afterwards. When you don't want to keep the commit message of D, you can also use the "fix" keyword.

这篇关于我如何挤压两个不连续的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆