Git rewriting local history - update previous (but not the last) commit
Suppose you haven't done any merge or push, and there is no change in the stage.
Now you realize you want to make some change in one of your previous commit you haven't pushed yet.
1. Start interactive rebase process with the last 3 commit, suppose the oldest 3th commit is the one you want to update.
git rebase -i HEAD~3
2. Edit the rebase command in the poped editor.
From:
pick f7f3f6d changed my name a bit
pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file
# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# Commands:
# p, pick = use commit
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
To:
edit f7f3f6d changed my name a bit
pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file
# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# Commands:
# p, pick = use commit
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
3. Save and close the editor
4. Take a look of git log, you see you are now in the history just after you commited f7f3f6d.
5. Amend whatever you would like to update in this commit f7f3f6d
git commit --amend
6. Continue with git rebase process to finish rebaseing the remaining commits
git rebase --continue
Resources: http://git-scm.com/book/en/Git-Tools-Rewriting-History
Now you realize you want to make some change in one of your previous commit you haven't pushed yet.
1. Start interactive rebase process with the last 3 commit, suppose the oldest 3th commit is the one you want to update.
git rebase -i HEAD~3
2. Edit the rebase command in the poped editor.
From:
pick f7f3f6d changed my name a bit
pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file
# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# Commands:
# p, pick = use commit
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
To:
edit f7f3f6d changed my name a bit
pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file
# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# Commands:
# p, pick = use commit
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
3. Save and close the editor
4. Take a look of git log, you see you are now in the history just after you commited f7f3f6d.
5. Amend whatever you would like to update in this commit f7f3f6d
git commit --amend
6. Continue with git rebase process to finish rebaseing the remaining commits
git rebase --continue
Resources: http://git-scm.com/book/en/Git-Tools-Rewriting-History
评论
发表评论