繁体   English   中英

尝试使用git rebase -i向以前的提交添加更改

[英]Attempt to add changes to previous commit using git rebase -i fails

我正在尝试修改对先前提交的更改,如下所述: 如何在git中修改指定的提交?

所以我将自己的更改更改为“要提交的更改”状态,并且我想将其“修改”为先前的提交,所以我去了

git rebase -i HEAD~3

但出现以下错误:

Cannot rebase: Your index contains uncommitted changes.
Please commit or stash them.

我不明白Git在抱怨什么,因为这是应该处于更改状态的状态,对吗?

我究竟做错了什么?

我正在使用v1.9.3

就像它说的

无法重新设置基准:您的索引包含未提交的更改。 请提交或隐藏它们。

因此,首先提交您的更改:

git add .
git commit -m 'ready to rebase'

然后再试一次

git rebase -i HEAD~4

然后,在重新设置基准时,您可以使用ready to rebase以将提交融合到上一个。

假设您有这四个承诺,例如

pick 3396a30 commit one
pick 3396a31 commit two
pick 3396a32 commit three
pick 3396a33 ready to rebase

然后将其更改为

pick 3396a30 commit one
pick 3396a31 commit two
f 3396a32 ready to rebase      # this line changed from "pick" to "f"
pick 3396a33 commit three

将导致

commit one
commit two       # this will include "ready to rebase"
commit three

选项f含义是

f,fixup =类似于“ squash”,但丢弃此提交的日志消息

s,squash =使用提交,但可以合并到先前的提交中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM