How to discard uncommitted changes in SourceTree?

MacosGitBitbucketAtlassian Sourcetree

Macos Problem Overview


I'm new to the Git environment, and I'm using BitBucket with SourceTree on Mac. All I want to do now is to discard the changes since last commit. How should I do this? I haven't found anything like "discard changes", and directly pulling from the last commit doesn't seem to work. Solutions done with either the GUI or command line will be good.

Macos Solutions


Solution 1 - Macos

On SourceTree for Mac, right click the files you want to discard (in the Files in the working tree list), and choose Reset.

On SourceTree for Windows, right click the files you want to discard (in the Working Copy Changes list), and choose Discard.

On git, you'd simply do:

git reset --hard to discard changes made to versioned files;

git clean -xdf to erase new (untracked) files, including ignored ones (the x option). d is to also remove untracked directories and f to force.

Solution 2 - Macos

I like to use

git stash

This stores all uncommitted changes in the stash. If you want to discard these changes later just git stash drop (or git stash pop to restore them).

Though this is technically not the "proper" way to discard changes (as other answers and comments have pointed out).

SourceTree: On the top bar click on icon 'Stash', type its name and create. Then in left vertical menu you can "show" all Stash and delete in right-click menu. There is probably no other way in ST to discard all files at once.

Solution 3 - Macos

On the unstaged file, click on the three dots on the right side. Once you click it, a popover menu will appear where you can then Discard file.

Solution 4 - Macos

Follow steps to discard multiple uncommited changes in Sourcetree.

> New version of Sourcetree does not have -Reset Button- as mentioned previous answer. Thus, please follow these 5 steps for solution.

  1. Right click "File status" and click "Reset...".

enter image description here

> 2. Select files. If you want, you can select all of them like the below image.

enter image description here

> 3. Click "Reset All".

enter image description here

> 4. Again click "Reset All".

enter image description here

> 5. Click "Reset".

enter image description here

> Welldone..! No more 302 files to discard.

enter image description here

Solution 5 - Macos

Ok I just noticed that my question was already answered in the question title.

To unstage files use

git reset HEAD /file/name

And to undo the changes to a file

git checkout -- /file/name

If you have a batch of files inside a folder you can undo the whole folder

git checkout -- /folder/name

Note that all these commands are already displayed when you git status

Here I created a dummy repo and listed all 3 possibilities

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   test
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   test2
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       test3

Solution 6 - Macos

From sourcetree gui click on working directoy, right-click the file(s) that you want to discard, then click on Discard

Solution 7 - Macos

Ok so in Windows sourcetree that is simple, on macOS I looked as well for a while..

Click Command + Shift + R while in source tree a hidden popup will be shown that will let you discard individual files OR ALL! Why is this hidden? We will never know.. but it works!

enter image description here

Solution 8 - Macos

Do as follow,

  • Click on commit
  • Select all by pressing CMD+A that you want to delete or discard
  • Right click on the selected uncommitted files that you want to delete
  • Select Remove from the drop-down list

Solution 9 - Macos

Its Ctrl + Shift + r

For me, there was only one option to discard all.

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiongoldfrapp04View Question on Stackoverflow
Solution 1 - MacosRobertoView Answer on Stackoverflow
Solution 2 - MacosMaxView Answer on Stackoverflow
Solution 3 - MacosNYC Tech EngineerView Answer on Stackoverflow
Solution 4 - MacosNamelessView Answer on Stackoverflow
Solution 5 - MacosMohammad AbuShadyView Answer on Stackoverflow
Solution 6 - MacosgiuseView Answer on Stackoverflow
Solution 7 - MacosItaiRodedView Answer on Stackoverflow
Solution 8 - MacosFrostmourneView Answer on Stackoverflow
Solution 9 - MacosSharutkarshView Answer on Stackoverflow