Git – Undo the Last Commit

undefined

Sometimes you found that you have committed some wrong files for in-completed code in your local git repository. The following command will revert last commit in your current working repository. If you just want to change last commit message, you can use this article to do it.

Undo the Last Commit:-

$ git reset --soft HEAD~

In above command HEAD is a reference to the last commit in the current checked out branch.

Commit Files Again:-

Now edit your files and make necessary changes and add them again using git add command. After that commit files as you do always but you can reuse the old commit message using -c ORIG_HEAD. This will open last commit message in editor.

$ git add ...
$ git commit -c ORIG_HEAD

If You Appreciate What We Do Here On Mimastech, You Should Consider:

  1. Stay Connected to: Facebook | Twitter | Google+
  2. Support us via PayPal Donation
  3. Subscribe to our email newsletters.
  4. Tell other sysadmins / friends about Us - Share and Like our posts and services

We are thankful for your never ending support.

Leave a Reply

Your email address will not be published. Required fields are marked *