I want to do a "checkout --" on a number of files in SourceTree (that is, discard all changes since the last commit).
So I selected those files in SourceTree under Working Copy Changes and right clicked on the selection, hoping to see a menu item that would let me discard the changes.
However, it gives me two scary looking options: Remove and Discard. Don't want to delete those files by mistake.
Which of these options does a "checkout --" ?
If neither does this, how do I do a "checkout --" in SourceTree on a number of files?
Is there any documentation where I could have found the answer to this question?
You're right not to use Remove/Discard:
If you want to return the file to a previous state, there are a number of ways to do this.
Note, you can also do this in the main log view (right-click the file in a commit and pick "Reset To Commit", but it's easier to find the commit you want when you use the file-specific log.
You can Reverse file changes made to a file in a commit, undoing them in your working copy. This is more selective than resetting the entire file back to a previous point.
The 'Reverse' buttons are available in the Log Selected single-file window too. Please note that this 'Reverse' feature actually applies an 'inverse patch' to your working copy, so although in theory you can reverse any previous change at any level of detail, the more the file has changed content since the commit you're trying to reverse, the more chance the patch won't apply any more and you'll have to back the changes out manually instead, or use the more severe Option 1).
I'm a bit confused between "Discard" (discard uncommittted changes) and "reset to commit". Sounds to me they do the same if you reset to the last commit.
Take these events:
1) make change A to a file
2) make change B to the same file
3) locally commit the file
4) make change C to the file
If I now right click on the file and choose Discard, will that essentially get rid of change C (so it is back to where it was when I committed it locally in step 3)?
Reason I'm asking:
Sometimes I have a number of files that I've messed with, and where I want to get rid of my uncommitted changes before committing. Would be very handy if I could select them all and get rid of the uncommitted changes by right clicking the entire selection and choosing "Discard", instead of having to do this one by one.
Yes, if you select a file in the previous commit and choose Reset to this Commit it's the same as Discard. But discard is quicker and more accessible (you can even do it per hunk/line).
You can already discard many files at once. Multi-select them in the working copy (selecting either the File Status View with Ctrl-1 or the Uncommitted Changes line in the log view), then right-click and select Discard.
Alternatively, click Discard on the toolbar and then check the files you want to discard. Or, if you want to quick-discard absolutely everything, use Discard from the toolbar then select the Reset All tab and click OK.
I found this comment thread confusing because the above two comments seem to contradict each other. As far as I can tell Steve is right. I.e. "Reset to [most recent] Commit" is the same as Discard. But I'm new to SourceTree. Can someone who knows please confirm?
(This thread seems to be the best resource on this topic, but it will be much better with a definitive resolution to the contradiction.)
I, too, was looking to find out how to 'Undo' a change in SourceTree and came across this thread. I tried the 'Reset to Commit' command and whilst this did reverse the change, it left the file listed in the 'Unstaged files' area. Yet when I 'Discarded' the file, it disappeared from the 'Unstaged' area which is the behaviour I would expect when 'Undoing' a change.
Perhaps the difference is that with 'Reset to Commit' you can choose a Commit - it doesn't necessarily have to be the previous Commit and thus the file may still be changed/different from the latest Commit.
Sooo, if you simply want to 'Undo' current changes and go back to the latest 'Committed' version use 'Discard'
But if you want to go back further use 'Reset to Commit'?
Dunno, just my thoughts on my observations on SourceTree.
Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events