简体   繁体   English

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

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

I'm trying to amend changes to previous commit, as described here: How to modify a specified commit in git? 我正在尝试修改对先前提交的更改,如下所述: 如何在git中修改指定的提交?

So I have my changes in 'changes to be comitted' state, and I want to 'amend' them to a previous commit, so I go 所以我将自己的更改更改为“要提交的更改”状态,并且我想将其“修改”为先前的提交,所以我去了

git rebase -i HEAD~3

but getting the following error: 但出现以下错误:

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

I can't understand what Git is complaining about, since this is the state which the changes are supposed to be in, right? 我不明白Git在抱怨什么,因为这是应该处于更改状态的状态,对吗?

What am I doing wrong? 我究竟做错了什么?

I'm using v1.9.3 我正在使用v1.9.3

Well as it says 就像它说的

Cannot rebase: Your index contains uncommitted changes. 无法重新设置基准:您的索引包含未提交的更改。 Please commit or stash them. 请提交或隐藏它们。

So first commit your changes: 因此,首先提交您的更改:

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

and then try again 然后再试一次

git rebase -i HEAD~4

Then while rebase you can use the ready to rebase commit to meld into previous one. 然后,在重新设置基准时,您可以使用ready to rebase以将提交融合到上一个。

Say you have those four commits something like 假设您有这四个承诺,例如

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

then change that to 然后将其更改为

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

will result in 将导致

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

meaning of option f is 选项f含义是

f, fixup = like "squash", but discard this commit's log message f,fixup =类似于“ squash”,但丢弃此提交的日志消息

s, squash = use commit, but meld into previous commit s,squash =使用提交,但可以合并到先前的提交中

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

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