I have the commit history as below:
* 8cd26ba 2013-06-26 | history server-side (HEAD, noXHR)
* bffd858 2013-06-25 | popups and modals
* d95c5f4 2013-06-21 | Map update for new interaction
...
And when I've already committed '8cd26ba' I've found a bug in modal mechanism and want to fix it. I've tried to amend 'bffd858' (because fix is related to it) as it described here. I've did the following steps:
typed
$ git rebase -i bffd858
git shows me (in nano)
pick 6fa566b history server-side
# Rebase bffd858..6fa566b onto bffd858
#
# 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
# x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
I've replaced 'pick' with 'edit'
git said me:
Stopped at 8cd26ba... history server-side
You can amend the commit now, with
git commit --amend
Once you are satisfied with your changes, run
git rebase --continue
I've apply my bug-fix and typed
$ git commit -a --amend
typed
git rebase --continue
And then I've found my bug-fix in '8cd26ba' (last commit)!
What have I done wrong?
Your error is that when you do a rebase, you want to give the id of the parent of the earliest commit you want to modify. In your case, you wanted to modify bffd858
, whose parent is d95c5f4
also known as bffd858^
or bffd858~1
(I prefer that last syntax since it works with shell that do interpret ^
as a special character).
You should instead have done:
$ git rebase --interactive bffd858~1
and changed the file so that it read:
pick bffd858 popups and modals
fixup 6fa566b history server-side
# Rebase bffd858..6fa566b onto bffd858
#
# 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
# x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
and then saved and closed the file.
Usually the easiest way to apply a bug fix and to correct the history is to:
git commit --fixup=bffd858
when committing your fix,git rebase --interactive --autosquash bffd858~1
to rebase,Your original commit will then have been patched with the fix.
In your case, you only did a rebase with a single commit that you then amended. The rebase part, just rewinded the history to the point after you submitted your fix (ie. did nothing).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With