我怎样才能将两个提交合并成一个? [英] How can I merge two commits into one?

查看:261
本文介绍了我怎样才能将两个提交合并成一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图合并2个提交到1,所以我跟着压扁承诺与rebase”从git ready

我跑了

  git rebase --interactive HEAD〜2 

在结果编辑器中,我更改 pick 到 squash ,然后保存退出,但是rebase失败并显示错误消息


如果没有以前的提交,就不能'挤压'

现在我的工作树已经达到这个状态,米有麻烦恢复。 $ b


命令 git rebase --interactive HEAD〜2 失败开始


git rebase --continue 失败并带有


如果没有以前的提交,就不能'压扁'


解决


$ b

  $ git rebase --abort 

假设您的记录是

  $ git log --pretty = oneline 
a931ac7c808e2471b22b5bd20f0cad046b1c5d0d c
b76d157d507e819d7511132bdb5a80dd421d854f b
df239176e1a2ffac927d8b496ea00d5488481db5 a

也就是说,a是第一次提交,然后是b,最后是c。提交c之后,我们决定将b和c一起压缩:

运行 git rebase --interactive HEAD〜2 给出你是一个编辑器

  pick b76d157 b 
pick a931ac7 c

#将df23917..a931ac7重新映射到df23917

#命令:
#p,pick =使用提交
#r,reword =使用提交,但编辑提交消息
#e,edit =使用提交,但停止修改
#s,squash =使用提交,但融入前一提交
#f,fixup =像squash,但丢弃这个提交的日志消息

#如果你在这里删除一行,那么这个提交将会丢失。
#但是,如果您删除了所有内容,rebase将会中止。
$
$ / code>

更改b的选择 squash 会导致你看到的错误,但是如果你改变文本为b

  pick b76d157 b 
squash a931ac7 c

并保存退出编辑器,您将得到另一个编辑器,其内容为

 #这是2个提交的组合。 
#第一个提交的信息是:

b

#这是第二个提交信息:

c

当您保存并退出时,编辑文件的内容将成为新组合提交的提交消息:

  $ git log --pretty = oneline 
18fd73d3ce748f2a58d1b566c03dd9dafe0b6b4f b和c
df239176e1a2ffac927d8b496ea00d5488481db5 a


I am trying to merge 2 commits into 1, so I followed “squashing commits with rebase” from git ready.

I ran

git rebase --interactive HEAD~2

In the resulting editor, I change pick to squash and then save-quit, but the rebase fails with the error

Cannot 'squash' without a previous commit

Now that my work tree has reached this state, I’m having trouble recovering. The command git rebase --interactive HEAD~2 fails with

Interactive rebase already started

and git rebase --continue fails with

Cannot 'squash' without a previous commit

解决方案

Get back to where you started with

$ git rebase --abort

Say your history is

$ git log --pretty=oneline
a931ac7c808e2471b22b5bd20f0cad046b1c5d0d c
b76d157d507e819d7511132bdb5a80dd421d854f b
df239176e1a2ffac927d8b496ea00d5488481db5 a

That is, a was the first commit, then b, and finally c. After committing c we decide to squash b and c together:

Running git rebase --interactive HEAD~2 gives you an editor with

pick b76d157 b
pick a931ac7 c

# Rebase df23917..a931ac7 onto df23917
#
# 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
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

Changing b's pick to squash will result in the error you saw, but if instead you squash c into b (newer into the older) by changing the text to

pick   b76d157 b
squash a931ac7 c

and save-quitting your editor, you'll get another editor whose contents are

# This is a combination of 2 commits.
# The first commit's message is:

b

# This is the 2nd commit message:

c

When you save and quit, the contents of the edited file become commit message of the new combined commit:

$ git log --pretty=oneline
18fd73d3ce748f2a58d1b566c03dd9dafe0b6b4f b and c
df239176e1a2ffac927d8b496ea00d5488481db5 a

这篇关于我怎样才能将两个提交合并成一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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