0

I'm trying to amend changes to previous commit, as described here: How to modify a specified commit in 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?

What am I doing wrong?

I'm using v1.9.3

Community
  • 1
  • 1
Kludge
  • 2,653
  • 4
  • 20
  • 42

1 Answers1

2

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.

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, fixup = like "squash", but discard this commit's log message

s, squash = use commit, but meld into previous commit

Community
  • 1
  • 1
caramba
  • 21,963
  • 19
  • 86
  • 127