Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I git-revert from the command line?

When I do git revert via TortoiseGit, I get this lovely window :

enter image description here

However, when I want to do the same from the command line, the documentation manages to completely confuse me. How do I revert all local uncomitted changes?

like image 899
ripper234 Avatar asked Mar 17 '11 13:03

ripper234


People also ask

What is the command to revert in git?

The git revert command is used for undoing changes to a repository's commit history. Other 'undo' commands like, git checkout and git reset , move the HEAD and branch ref pointers to a specified commit. Git revert also takes a specified commit, however, git revert does not move ref pointers to this commit.

How do I revert a commit in git terminal?

To revert a commit with GitKraken, simply right-click on any commit from the central graph and select Revert commit from the context menu.

How can I revert my commit?

If you want to revert the last commit, you can use git revert head . head refers to the most recent commit in your branch. The reason you use head~1 when using reset is that you are telling Git to "remove all changes in the commits after" ( reset --hard ) "the commit one before head" ( head~1 ).


2 Answers

To discard all local changes, you do not use revert. revert is for reverting commits. Instead, do:

 $ git reset --hard 

Of course, if you are like me, 7 microseconds after you enter that command you will remember something that you wish you hadn't just deleted, so you might instead prefer to use:

 $ git stash save 'Some changes' 

which discards the changes from the working directory, but makes them retrievable.

like image 181
William Pursell Avatar answered Sep 30 '22 01:09

William Pursell


Assuming you haven't committed yet, you can also:

git checkout filename(s) 
like image 22
Marc Hughes Avatar answered Sep 30 '22 01:09

Marc Hughes