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.
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).
There are two Git commands a developer must use in order to discard all local changes in Git, remove all uncommited changes and revert their Git working tree back to the state it was in when the last commit took place. The commands to discard all local changes in Git are: git reset –hard. git clean -fxd.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With