Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I revert a file in SourceTree? or Where is the missing user manual for SourceTree?

Deleted user June 18, 2015

I'm used to SVN and new to GIT. I installed and am using SourceTree with Git and do Push/Pulls to SVN repo from my local Git repo.

I made some changes to a file but now want to return to the state they were last in prior to my changes. I have not made any commit of the changes yet. I can't find any clue how to revert the changes back to the way the file was.

One internet source says to:

use "git checkout -- <file>..." to discard changes in working directory

but I don't know how that translates to SourceTree.

I then looked for documentation on SoureTree and so far can't find any. (Really? I think to myself)

3 answers

1 accepted

2 votes
Answer accepted
sreekumar_menon
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 18, 2015

if you ahv not committed yet,  you an right click on the file and select discard to discard all local changes and revert to what is in origin.

1 vote
Tim Crall
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 18, 2015

If you have not made any changes to any other files that you want to retain, and simply want to reverse everything you've done since your last commit, you can use "reset".  Just right-click the last commit and select "reset <branch> to this commit".  In the dialog box that comes up, select "Hard - discard all working copy changes".

 

If you made other changes that you want to retain and only want to reset an individual file, you can right-click on that file in the directory tree (lower left corner) and select "Reset to commit"

0 votes
Deleted user June 19, 2015

Tim, Someone else in our company told me to use Reset but in my Windows version of ST I can't find a Reset. Then I found out he was on a Mac version. Are you on the Mac version too? Not sure why they would make the tool with different commands based on which platform you are on.

 

Sreekumar, Thanks for the help. Discard is apparently the right action on Windows anyway. It just seemed scarey to use as it's not clear if it discards the changes or the file. But then there is a Remove option as well so while I'm learning the tool and Git, it's all a bit confusing.

Tim Crall
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2015

I do use a Mac normally. And 'reset' is the git command you would use at a command line (if you wanted to revert the entire commit - not just to revert one file). My Windows SourceTree also gives a "reset current branch to this commit" option when I right-click on a commit and a "Reset to commit" option when I right click on a file - if I have a commit selected above. If I have 'Uncommited changes' selected above, then I see the 'Discard' option you're talking about. Either way works. The first way (selecting a commit, thenr right-clicking on the file and selecting 'Rest to commit') allows you to reset the file to the version found in any arbitrary commit. The second way (selecting 'Uncommitted changes'), right-clicking on the file, and selecting 'Discard' only discards the changes in the uncommitted file, setting it back to the last commit on the branch. Just as a note: it's better to put responses to answers as a comment rather than as a separate answer.

Deleted user June 19, 2015

Sorry about not using Comment on your response instead of posting as an answer. As to the question at hand, I find having multiple ways that all approx do the same thing very confusing... Reset, Discard, Checkout... got to know which one to use when under which circumstances. SVN just has Revert, plain and simple. I understand Checkout and I think I understand Discard now. It sounds like Reset is for when changes have been committed but Discard is when uncommitted changes exist. If true, then Reset must default to reverting back to the previous committed changes, essentially tossing the most recent commit? I would also assume that you can specify how far back in the commit history to go for doing a Reset?

Tim Crall
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2015

I agree. 'Discard' in SourceTree is a bit confusing as it is not, to my knowledge, analogous to a git command. SourceTree does tend to offer at least three ways to perform any given task, and that can be a bit confusing. In your situation, either Discard or Reset would have worked. If you had committed the unwanted changes, you're correct that you would have had to use Reset. Reset defaults to whatever commit you have selected on the tree graph and yes, you can use it to go further back in time.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events