Saturday, August 6, 2011

How to Revert or Undo a Commit

This is a Clear & StepByStep Guide to Undo a Git Commit:

If you need to Retrograde of Multiple Steps back you will need to Patiently Revert
the Commits One by One and One After the Other Beginning by the Last One

<strong>i) Revert your Commit</strong>

1) If you need to Revert just the Last Commit:
git revert HEAD
2) If you need to Revert just the Next-to-Last Commit:
git revert HEAD^
3) If you need to Revert an Older one Commit:
    a) First you need to find the ID of the Commit you want to revert
   If you don't have to much commits you can directly look at output of:
git log
  they will be printed beginning by the Last Commit.
  If you have some problems in finding your commit's ID but you remember a word on the messag try:
git log --grep=partOfMessage

    b) Proceed to Revert your commit
git revert IDOfCommit
      In the General form Git will ask you a Message for the Operation.
      If you want to proceed to a Faster Reverting you can accept default message by:
git revert --no-edit IDOfCommit

If you Old Commit ha been already Pushed you will need also to
Execute and Push a Revert Commit...


Execute your Commit:
git -am "Revert Commit"
Pushing the Revert Commit:
git push origin master