Wednesday 30 January 2013

How to undo your local git commit

Suppose if you are planning to do undo changes your local commit this article will help you about that process.

If you committed some files and you made some commit messages after that if you are planning to do undo those commits because you did something wrong in the commit(may be you added unwanted files or changes which raise some errors). Before doing undo your local commits you have to think which ways you want that.

If you are planning undo local commit entirely whatever you changes you did on the commit, if you dont worry anything about that just do the following command.

git reset --hard HEAD^1 (This command will ignore your entire commit and your changes will be lost completely from your local working tree).

If you want undo your commit but you want changes you did on the commit into staging area(before commit just like after git add called staging area) then do the following command

git reset --soft HEAD^1

Now your committed files comes into staging area suppose if you want to unstage the files because you need to edit some wrong conent than do the following command

git reset HEAD

Now committed files comes into staged area into unstaged area now files are ready to edit so whatever you changes you want go edit and added it and make a fresh/new commit.

Hopefully this article helps you about how to undo your local git commit (not committed into remote repository).

No comments :

Post a Comment