Git How to Fix/Amend Commit

October 25, 2011 | By Regaz | Filed in: Uncategorized.

If you just Executed your Commit and after you find some new Changes to Add, you can Easy Fixing or Amending the Latest Commit with:

git commit --amend

To Execute a Fast Fixing leaving Untouched the Message use:

git commit --amend -C HEAD

This will Add New Changes to the Latest Commit and leave Unchanged the Commit Message.
Indeed the Flag -C serve right to leave untouched the Commit Message when Fixing.

But if you Prefer Instead, Removing the Latest Commit for after Executing a New one:

git reset --hard HEAD^

When you need to Edit a Commit Other than the Latest one you can use the Interactive Rebase Command.
In this Example we wanto to Edit the Second Commit before HEAD (HEAD=Latest Commit):

git rebase -i HEAD~2

This will launch the Message’s Editor, so you Edit Message and Save.
After you make the Changes you want to your Commit, then:

commit --amend
git rebase --continue
Problems?

Try to Fix with a Fetch and Rebase like that:

git commit -a
git fetch
git rebase origin

Tags: , ,

QuickChic Theme • Powered by WordPress