How to discard all changes made to a branch?
I'm working in a branch (i.e. design
) and I've made a number of changes, but I need to discard them all and reset it to match the repository version. I thought git checkout design
would do it, but it just tells me I'm already in branch design
and that I have 3 modified files.
How would I discard those changes and get the branch as it stands now on the remote server?
Solution 1:
Note: You CANNOT UNDO this.
Try git checkout -f
this will discard any local changes which are not committed in ALL branches and master.
Solution 2:
git reset --hard can help you if you want to throw away everything since your last commit
Solution 3:
git diff master > branch.diff
git apply --reverse branch.diff
Solution 4:
If you don't want any changes in design
and definitely want it to just match a remote's branch, you can also just delete the branch and recreate it:
# Switch to some branch other than design
$ git br -D design
$ git co -b design origin/design # Will set up design to track origin's design branch