Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rollback uncommitted changes in GitHub Desktop (or Github for Windows)

I'm using Github Desktop (previously called GitHub for Windows) and I made a bunch of changes to my local files. It became such a mess that I decided I just want to rollback my local files to where they were the last time I made a commit. I haven't committed the new changes - I just want to get rid of them. How can I do this?

like image 967
Mark Cramer Avatar asked Jul 26 '14 20:07

Mark Cramer


1 Answers

When you open GitHub for Windows v2.0 (ancestor of GitHub Desktop) and select your repository in the leftmost column, you'll see all your previous commits in the 2nd column from the left. If you select one of those commits, in the right column at the top you'll see "Revert" which says, when you mouse over, "Create a new commit that reverts the changes in this commit." I don't think this is what you want to do since you don't want to revert the changes in that commit but rather revert the changes that haven't been committed yet. So don't do that. (When you select "Uncommitted changes" in the 2nd column, the "Revert" link is not there.

"Revert" link in GUI

There are two options - the first is easy and the second is super-easy:

Easy - Select your repository in the leftmost column then click the gear icon in the upper right and choose "Open in Git Shell". The shell should open and be in the directory of your repository. From there you can type git reset --hard to revert files modified since the last commit and then git clean -fd to remove all files added since the last commit. Obviously, you may enter other git commands here as well.

Git Shell for entering CLI

Super easy - Select your repository in the leftmost column and then click "Uncommitted Changes" in the 2nd column to display your changed files at the right. If you right-click on any file you'll have an option to "Discard changes". (How one would know to right-click is beyond me.) If you right-click in the space next to "Files to commit" you'll have an option to "Discard all changes." Click that and presto, all your changes are wiped out and your local files will be back to where they were the last time you made a commit.

enter image description here

like image 126
Mark Cramer Avatar answered Oct 11 '22 06:10

Mark Cramer