How can i undo my last Commits on Git?


I have committed some files on my Git using Visual Studio, which i want to undo now, as the code and i want to change it without pushing it to server, i haven't pushed the committed files on server yet, so how can i achieve it using Visual Studio or with some other source?

 


Asked by:- bhanu
1
: 76 At:- 9/11/2017 2:09:35 PM
git git-commit git-undo-commit git-revert






2 Answers
profileImage Answered by:- jaya

You need to run this command using Git terminal:

git reset HEAD~

If you don't want the changes and remove everything, run this :

git reset --hard HEAD~

Or if you don't want to write code using terminal check post below or it's source, briefly explained here

http://www.coding-issues.com/2017/03/how-to-undo-or-revert-last-commits-in-git.html

The above solution can be achieved using Git Extensions. You can download it from here link1 or from here link2

Once this is done Git Extensions will show you all the commits. Select any specific commit and right click on it. Then select revert commit. Check the below screenshot for reference

reverse-commit-using-git-extension

Once you select the Revert Commit option, it opens a pop-up, from pop-up select "Automatically create a commit" if you want to directly commit the reverted changes or if you want to manually commit the reverted changes keep the box un-selected and click on "Revert this commit" button.

2
At:- 9/12/2017 3:08:27 PM
great, for me the second alternative was good, as I don't want to run commands and it looks easier also. 0
By : bhanu - at :- 9/16/2017 9:50:42 AM


profileImage Answered by:- Vinnu

You can undo the last commit:

git reset --soft HEAD~

Or you can undo the time before last time commit:

git reset --soft HEAD~2

Or you can undo any previous commit:

git reset --soft <commitID>

(you can get the commitID using git reflog)

When you undo a previous commit, remember to clean the workplace with

git clean

You can find more details in the docs: git-reset

hope this helps

0
At:- 9/14/2017 2:05:23 PM





Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use
Related Articles
Related Questions