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)
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"
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.
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.
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?
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.
Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs