Git:“在没有先前提交的情况下不能'挤压'"重新设置时出错 [英] Git: "Cannot 'squash' without a previous commit" error while rebase

查看:174
本文介绍了Git:“在没有先前提交的情况下不能'挤压'"重新设置时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在git rebase -i HEAD~2的待办事项中有以下内容:

I have the following in the to-do text of git rebase -i HEAD~2:

pick 56bcce7 Closes #2774
pick e43ceba Lint.py: Replace deprecated link

# Rebase 684f917..e43ceba onto 684f917 (2 command(s))
#
...

现在,当我尝试挤压第一个(56bcce7)并通过在第一个之前添加"s"来选择第二个时,出现以下错误:

Now, when I try to squash the first one(56bcce7) and pick the second one by adding "s" before the first, I get the following error:

Cannot 'squash' without a previous commit

有人可以解释我的意思吗,我该怎么做?

Can someone explain me what it means, and how do I do it?

我要压缩第一个提交(56bcce7)并选择并重写"第二个(e43ceba)提交

I want to squash the first commit(56bcce7) and "select and reword" the second(e43ceba) commit

推荐答案

交互式rebase以与使用git log时相反的顺序显示提交. git rebase -i以精确的顺​​序(从上至下)重播选定的提交,它们在已保存的变基指令文件中列出.压缩时,为压缩选择的提交与(已编辑)列表中在其之前的提交(即来自上一行的提交)组合在一起.您的情况-56bcce7没有先前的提交.您必须执行以下任一操作

Interactive rebase presents commits in the reverse order of what you are used to when using git log. git rebase -i replays the selected commits in the exact (top-down) order they are listed in the saved rebase instructions file. When squashing, the commit selected for squashing is combined with the commit that precedes it in the (edited) list, i.e. the commit from the previous line. In your case - there is no previous commit for 56bcce7. You have to do one of the following

  • git rebase -i HEAD~3(如果您想将56bcce7压入684f917)
  • 如果您打算将56bcce7e43ceba组合在一起,并且e43ceba不依赖于56bcce7,则只需对其重新排序:

  • git rebase -i HEAD~3 (if you want to squash 56bcce7 into 684f917)
  • If you mean to combine 56bcce7 with e43ceba, and e43ceba doesn't depend on 56bcce7, then simply reorder them:

r e43ceba Lint.py: Replace deprecated link
s 56bcce7 Closes #2774

更新: Gus的答案提出了一种更好的方法,无需重新排序这两个提交:

UPDATE: Gus's answer below suggests a better way of doing the same, without reordering the two commits:

r 56bcce7 Closes #2774
s e43ceba Lint.py: Replace deprecated link

这会将两个提交压缩/合并为一个.当交互式rebase要求为56bcce7提供改写的提交消息时,请提供描述56bcce7e43ceba的并集的提交消息.

This will squash/merge the two commits into one. When the interactive rebase asks for a reworded commit message for 56bcce7, provide the commit message that describes the union of 56bcce7 and e43ceba.

这篇关于Git:“在没有先前提交的情况下不能'挤压'"重新设置时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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