Git revert to specific revision
Asked by Jaex:

I'm new to Git and trying to find how to revert to specific revision in SourceTree. I was using svn before and it was like this in svn: <https://dl.dropbox.com/u/14076298/ShareX/2013/10/EsnebIR63J.png>

[Reverse commit](https://dl.dropbox.com/u/14076298/ShareX/2013/10/hJiTsIfRrp.png) doing nearly what i want in SourceTree but it is only for one revision and i want all revisions from HEAD to target revision like how it works in svn. I can do one by one reverse commit but i prefer to have all revert changes in one commit instead of 10 different commits for them. (Maybe be able to select multiple revisions and having reverse commit button clickable in menu would be good solution to what i want?)

Then i give up using gui for this and searched about commands and found this command:

git revert -n sha1..HEAD

It works perfectly and doing what i want. But i don't like to use commands so still keep tried to find solution in gui. And finally found this workaround:

<https://dl.dropbox.com/u/14076298/ShareX/2013/10/1OKocrPrni.mp4>

[Hard reset](https://dl.dropbox.com/u/14076298/ShareX/2013/10/ojMowVKwSl.png) to specific revision and after that soft reset to head revision. I'm not sure how it works but giving same results as "git revert -n sha1..HEAD" i think. Is it proper way to do what i want? Is there a better solution to this? I don't understand why right click menu of SourceTree don't have Revert to revision option.


Answers:
author: alextretyak
body: Checkout in git has many different forms, but mentioned "`git checkout <commit> -- <filename>`" does **not** move HEAD. (See detailed explanation [here](http://git-scm.com/blog/2011/07/11/reset.html), and pay attention to the table at the end.)  
To revert all files to specific revision use "`git checkout <sha1> .`" or "`git checkout <sha1> \*`".  
So, if you want SourceTree UI do exactly that what "Revert to this revision" in TortoiseSVN does, just add this Custom Action to SourceTree for Windows:

*Menu caption:* Revert to this revision  
*Script to run:* `cmd`  
*Parameters:* /c %LOCALAPPDATA%\\Atlassian\\SourceTree\\git_local\\bin\\git.exe checkout $SHA `.`

Or for Mac:

*Script to run:* `git`  
*Parameters:* checkout $SHA` .`

After that you can simply use it like this:

screenshot2.png

Please note, that it will not commit automatically (just like "Revert to this revision" in TortoiseSVN).  
[](https://community.atlassian.com/t5/Sourcetree-questions/Git-revert-to-specific-revision/qaq-p/195409?attachment-id=959){#link_116c1859ec6f5d}  
[](/tnckb94959/attachments/tnckb94959/sourcetree-questions/40126/1/screenshot.png){#display_116c1859ec6f5d_0}  
[](https://community.atlassian.com/t5/Sourcetree-questions/Git-revert-to-specific-revision/qaq-p/195409?attachment-id=960){#link_116c1859ec6f5d_0}  
[](/tnckb94959/attachments/tnckb94959/sourcetree-questions/40126/2/screenshot2.png){#display_116c1859ec6f5d_2}

comments: author: adliss@deloitte.com
body: Hey man, this works super well! Just a quick note, for my particular use case I wanted to be able to checkout a specific file from a specific commit, but to do that all I had to do was change the Parameters to (on a Mac):

checkout $SHA -- $FILE


author: MB
body: Oh I see, well, then try [git reset](http://stackoverflow.com/questions/7368824/is-there-a-git-revert-similar-to-svn-revert-i-need-a-single-command-to-erase-e). I hope that helps.

comments: author: Jaex
body: I told i want to use SourceTree ui for do what i want, I can already do it using revert command and i don't think reset is what i want.


author: Jaex
body: Checkout not creating reverse commit and also it moving HEAD to back but not MASTER to back therefore it not helps at all. And i don't want force push. I want reverse commit so history will be intact.


author: MB
body: From your description, what appears is that you need git checkout instead of git revert. Try reading the [documentation page for git revert](https://www.kernel.org/pub/software/scm/git/docs/git-revert.html) and there is a line that says:
> If you want to extract specific files as they were in another commit, you should see [git-checkout(1)](https://www.kernel.org/pub/software/scm/git/docs/git-checkout.html), specifically the \<tt\>git checkout \<commit\> -- \<filename\>\</tt\> syntax.

So, try using git checkout instead.

comments: author: Jaex
body: Checkout not creating reverse commit and also it moving HEAD to back but not MASTER to back therefore it not helps at all. And i don't want force push. I want reverse commit so history will be intact.


Tags: git

revert