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

3

16

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?

Hemostat answered 26/7, 2014 at 20:1 Comment(0)
H
4

In keeping up with the times, Github for Windows has had a huge makeover, so here's a new answer. It's now called Github Desktop and the version numbers have started back at v1.0.0. So if you're running Github Desktop v1 then your UI is going to look a little different.

This super-handy, always-hidden little feature, however, is still there.

First, select your repository in the far-left dropdown in the black area. Make sure you then select the tab that says "Changes". Now you can right-click anywhere in the rectangle that contains "{#} changed files" and you'll get a pop-up that says "Discard all changes..." Click that and, presto, you're back to where you were the last time you made a commit.

Bonus: You can also right-click any of the changed files to get a pop-up that will enable you to "Discard changes..." for only that file. Click that and only that file will revert back to where it was at the last commit.

enter image description here

The Github Desktop documentation now includes information on how to discard changes. It is, however, incorrect! When you right-click an individual file the pop-up does not give the option to "Discard all changes..." as their screen shot seems to indicate. To discard all changes you need to do as I describe above.

Hemostat answered 22/11, 2017 at 18:24 Comment(0)
H
15

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

Hemostat answered 26/7, 2014 at 20:1 Comment(6)
I would recommend limiting your answer to just the "easiest" solution. The first part of your answer has already been answered here. Your "easiest" solution is much appreciated and would benefit from being on its own.Deadman
Thanks. Just trying to be complete.Hemostat
@Deadman In fact, his answer is perfect as it is. The super easy answer failed on my machine, so the easy answer was needed. And since it is right here, I am able to execute it without trying to find the other place you linked.Eirene
@Eirene did the super easy method fail because you're using v3? if so, try https://mcmap.net/q/724004/-rollback-uncommitted-changes-in-github-desktop-or-github-for-windows.Hemostat
@MarkCramer Thanks. I just revisited this one and yes, I imagine that it failed because I was already on the Electron app. The new app is excellent for many things, but fails in a few areas as well. One that really bugs me is that on Windows it now offers "open in command prompt" rather than "open in git shell". The latter was always incredibly useful, while the former is decidedly not.Eirene
@MarkCramer Is this answer still applicable to the latest GitHub Desktop? If no, then please add a link or message on top of your answer to say something along the lines of "Hey, this answer is obsolete, please look at this other answer for the newer practice"Skill
H
10

GitHub for Windows v3 has made the "super easy" answer above obsolete and, once again, figuring out what to do is just not obvious. This time, select your repository in the leftmost column and then click the "{#} uncommitted changes" link at the top just to the left of "History". This should give you a middle column like the one below. To discard your uncommitted changes you need to right click the "{#} changes" text above the list of list of modified files. (Clicking in the white space around that text does nothing.) Click "Discard all changes" and, once again, 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. (By the way, right clicking any one of those listed files will enable you to discard the uncommitted changes for just that file.)

Screen shot of GitHub for Windows v3

Hemostat answered 27/9, 2015 at 19:29 Comment(0)
H
4

In keeping up with the times, Github for Windows has had a huge makeover, so here's a new answer. It's now called Github Desktop and the version numbers have started back at v1.0.0. So if you're running Github Desktop v1 then your UI is going to look a little different.

This super-handy, always-hidden little feature, however, is still there.

First, select your repository in the far-left dropdown in the black area. Make sure you then select the tab that says "Changes". Now you can right-click anywhere in the rectangle that contains "{#} changed files" and you'll get a pop-up that says "Discard all changes..." Click that and, presto, you're back to where you were the last time you made a commit.

Bonus: You can also right-click any of the changed files to get a pop-up that will enable you to "Discard changes..." for only that file. Click that and only that file will revert back to where it was at the last commit.

enter image description here

The Github Desktop documentation now includes information on how to discard changes. It is, however, incorrect! When you right-click an individual file the pop-up does not give the option to "Discard all changes..." as their screen shot seems to indicate. To discard all changes you need to do as I describe above.

Hemostat answered 22/11, 2017 at 18:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.