In general, you can go back to a commit in your history with git reset.


This is not possible with GitHub Desktop. GitHub Desktop is more of a tool to synchronize your repositories and not a full featured GUI client.
But that doesn't mean you have to use the command line, since there are alternatives. You can find a list here. To mention a few (that support git reset):

  • TortoiseGit (Windows)
  • SourceTree (Mac, Windows)

Here is how you do it on command line. Most clients provide this in their UI using the same vocabulary (usually, you are able to select a commit and reset to it via context menu).

You will go back to the previous commit with

git reset HEAD^

or some more commits (for example 3) by

git reset HEAD^3

or to a specific commit by

git reset f7823ab

Have in mind that, by default, the option --mixed is passed to git reset. So, all changes made, since that commit you reset to, will still be there.

To get the original state of the commit that you want to 'revert', you have to pass --hard. For example:

git reset f7823ab --hard
Answer from SevenEleven on Stack Overflow
🌐
GitHub
docs.github.com › en › desktop › managing-commits › reverting-a-commit-in-github-desktop
Reverting a commit in GitHub Desktop - GitHub Docs
You can use GitHub Desktop to revert a specific commit to remove its changes from your branch. ... When you revert to a previous commit, the revert is also a commit.
Discussions

How to revert to a previous commit?
Ran into some issues after expanding the dialogue system way further and want to revert to a previous commit and I do not know how to. I saw on Youtube people using the terminal but I do not really understand how to. Is there any other way to GitHub Desktop Client or something else? More on community.gamedev.tv
🌐 community.gamedev.tv
1
0
April 15, 2024
Revert commit on Website
Select Topic Area Question Body Hello there! I'm beginner on GitHub, and can't resolve one problem - on desktop version i can "Revert changes in commit" in history without problem... More on github.com
🌐 github.com
8
18
Resetting HEAD To a Previous Commit in Time
The ability reset my head to a previous state would be great 😄 Please describe the problem you think should be solved As part of my workflow sometimes I jump to a previous point in time on my branc... More on github.com
🌐 github.com
14
October 9, 2018
how to go back to a state at a commit?
Copy the git sha of the commit you wanna go back to. Checkout that sha with git checkout. If it’s not too far back you could do a git reset head. Come to think of it you might be able to git restore to just restore everything to that sha. Anyhow after all that you would need to force push to overwrite the branch. Now that I answered your question let me ask the real question. Why not just fix the bug with a new commit? Why undo all the work you have already done? More on reddit.com
🌐 r/github
12
2
January 5, 2024
🌐
Reddit
reddit.com › r/github › how to go back to a state at a commit?
r/github on Reddit: how to go back to a state at a commit?
January 5, 2024 -

I have GitHub Desktop and I have been making regular commits. Now a bug was introduced and I want to go back and get the whole project as it was in time at a previous commit.

How to do that is not entirely intuitive. How do you go back to a previous state of the entire project at the point of a single commit?

There are no local changes according to Github Desktop....

no changes

The commit that I want to go back to is the 3rd commit down on the left. I figure that (according to their instructions) I would revert the two latest commits and I'd be back where I want to be.

a simple plan

But Github protets and claims there are changes.....

only there aren't any changes

But, there aren't any changes.

WTF Github?

I'm not worried about the code......

I'm just irritated that a versioning system so widely used would be so poorly designed.

Top answer
1 of 3
4
Copy the git sha of the commit you wanna go back to. Checkout that sha with git checkout. If it’s not too far back you could do a git reset head. Come to think of it you might be able to git restore to just restore everything to that sha. Anyhow after all that you would need to force push to overwrite the branch. Now that I answered your question let me ask the real question. Why not just fix the bug with a new commit? Why undo all the work you have already done?
2 of 3
1
Sounds like you were just confused with terminology, which is entirely understandable. Git involves a lot of words that mean very specific things within the context of Git, but are more flexible in ordinary language. In this case, you thought "revert" would do what you wanted, but what that actually means is to permanently revert something going forward. You use it when you decide that some changes you made before are inappropriate and should be undone (and they were in a shared branch that you want to keep using, so you can't merely ignore the last few commits; you need the reversion to explicitly exist in history). What you really want is to "check out" an old commit. Think of it like checking out a book at your local library. You want to read it for a while, and then return to what you were doing before. This is a read-only operation in terms of version history; you're not modifying history by adding a new event to it the way that revision does. You're only browsing through history, observing what it looked like at various moments by modifying only your local working copy.
🌐
GitHub
docs.github.com › en › desktop › managing-commits › undoing-a-commit-in-github-desktop
Undoing a commit in GitHub Desktop - GitHub Docs
You can undo multiple sequential commits up to a commit that has already been pushed to the remote repository by selecting a previous commit and using the "reset to commit" option.
Find elsewhere
🌐
GitHub
github.com › orgs › community › discussions › 60023
Revert commit on Website · community · Discussion #60023
Hey. If you don't want to revert a commit using the console, the easiest way is to go to Github Desktop (which is UI-based rather than terminal), set current repo to the specific repo, click on history, and right click on a commit.
🌐
GitHub
github.com › desktop › desktop › issues › 5860
Resetting HEAD To a Previous Commit in Time · Issue #5860 · desktop/desktop
October 9, 2018 - The ability reset my head to a previous state would be great 😄 Please describe the problem you think should be solved As part of my workflow sometimes I jump to a previous point in time on my branch. I can be: Rewriting history Debugging...
Author   desktop
🌐
Medium
pavolkutaj.medium.com › revert-changes-in-the-commit-with-github-desktop-e08854c27b8
Revert Changes in the Commit with GitHub Desktop - Pavol Z. Kutaj - Medium
January 29, 2021 - The concern is documenting the GUI approach to a simple revert of a commit. I could not come up with an elegant git CLI solution, the easiest is to use the GUI of GitHub Desktop
🌐
Git
git-scm.com › cheat-sheet
Git Cheat Sheet
Then change "pick" to "fixup" for any commit you want to combine with the previous one · git reflog BRANCHNAME · Then manually find the right commit ID in the reflog, then run: git reset --hard <commit> git commit --amend · git log main git log --graph main git log --oneline ·
🌐
Quora
quora.com › How-do-I-revert-a-local-git-repository-using-a-GitHub-Windows-client-back-to-a-certain-commit
How to revert a local git repository using a GitHub Windows client back to a certain commit - Quora
Answer (1 of 2): This depends a lot on what you mean by "revert". Temporarily switch to a different commit If you want to temporarily go back to it, fool around, then come back to where you are, all you have to do is check out the desired commit: [code]# This will detach your HEAD, that is, le...
Top answer
1 of 10
111

The safest and probably cleanest way to go is to rebase interactively.

git rebase -i HEAD^^

Or,

git rebase -i baf8d5e7da9e41fcd37d63ae9483ee0b10bfac8e^

From there you can squash commits, which puts one or more commits together into the previous commit. To completely delete a commit from the history, delete the line from the list.

You can revert a commit with git revert but its going to add more commit messages to the history, which may be undesirable. Use the -n parameter to tell Git not to commit the revert right away. You can rebase interactively and squash those on up to a previous commmit to keep things clean.

If the two commits you're working with here affect the same file(s), you may see a merge conflict.

Resetting the repository with git reset --hard should be done with care, as it cannot be undone.

Rewriting history should be done with care.

2 of 10
70

This if from http://nakkaya.com/2009/09/24/git-delete-last-commit/ and it worked for me

Git Delete Last Commit

Once in a while late at night when I ran out of coffee, I commit stuff that I shouldn't have. Then I spend the next 10 - 15 minutes googling how to remove the last commit I made. So after third time I wanted to make a record of it so I can refer to it later.

If you have committed junk but not pushed,

git reset --hard HEAD~1

HEAD~1 is a shorthand for the commit before head. Alternatively you can refer to the SHA-1 of the hash you want to reset to. Note that when using --hard any changes to tracked files in the working tree since the commit before head are lost.

If you don't want to wipe out the work you have done, you can use --soft option that will delete the commit but it will leave all your changed files "Changes to be committed", as git status would put it.

Now if you already pushed and someone pulled which is usually my case, you can't use git reset. You can however do a git revert,

git revert HEAD

This will create a new commit that reverses everything introduced by the accidental commit.

🌐
Claude Code Docs
code.claude.com › reference › checkpointing
Checkpointing - Claude Code Docs
3 days ago - Claude Code automatically tracks Claude’s file edits as you work, allowing you to quickly undo changes and rewind to previous states if anything gets off track.
🌐
GitHub
github.com › apps › desktop
GitHub Desktop | Simple collaboration from your desktop · GitHub
Copy commits from one branch to another, combine multiple commits in your branch history, or alter your commit history with an intuitive drag and drop functionality unique to GitHub Desktop. ... Manage your work-in-progress by saving changes that you’re not ready to commit to quite yet. This will maximize your efficiency, flexibility, and creativity. Make adjustments to update messages, incorporate new changes, or revert to earlier states when needed.
🌐
GitHub
docs.github.com › en › repositories › releasing-projects-on-github › managing-releases-in-a-repository
Managing releases in a repository - GitHub Docs
You can create new releases with release notes, @mentions of contributors, and links to binary files, as well as edit or delete existing releases. You can also create, modify, and delete releases by using the Releases API.
🌐
GitHub
gist.github.com › 3ad19d7f48e946f1aff0
git revert to a previous commit · GitHub
http://stackoverflow.com/quest... Move the branch pointer back to the previous HEAD git reset --soft HEAD@{1} git commit -m "Revert to 56e05fced" # Update working copy to reflect the new commit git reset --hard...
🌐
Quora
quora.com › How-do-I-revert-a-specific-git-commit
How to revert a specific git commit - Quora
Answer (1 of 2): You can either do git reset or git revert to roll back your commit changes. I suggest using git revert and then pushing your modified changes [code]# Reset the index and working tree to the desired tree # Ensure you have no uncommitted changes that you want to keep git reset ...
🌐
Appsmith
old-community.appsmith.com › t › how-do-i-revert-to-a-previous-commit-of-my-app › 2191
How do I revert to a previous commit of my app?
We talked to DevRel folks at DevRelCon who are building with AI every day—what they’ve learned and where they think things are headed. From agents and evals to database infra and open source, it’s all in here. Here are their hot takes on AI · Need help?