Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3332396
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:41:02+00:00 2026-05-17T23:41:02+00:00

How do I revert from my current state to a snapshot made on a

  • 0

How do I revert from my current state to a snapshot made on a certain commit?

If I do git log, then I get the following output:

$ git log
commit a867b4af366350be2e7c21b8de9cc6504678a61b`
Author: Me <me@me.com>
Date:   Thu Nov 4 18:59:41 2010 -0400

blah blah blah...

commit 25eee4caef46ae64aa08e8ab3f988bc917ee1ce4
Author: Me <me@me.com>
Date:   Thu Nov 4 05:13:39 2010 -0400

more blah blah blah...

commit 0766c053c0ea2035e90f504928f8df3c9363b8bd
Author: Me <me@me.com>
Date:   Thu Nov 4 00:55:06 2010 -0400

And yet more blah blah...

commit 0d1d7fc32e5a947fbd92ee598033d85bfc445a50
Author: Me <me@me.com>
Date:   Wed Nov 3 23:56:08 2010 -0400

Yep, more blah blah.

How do I revert to the commit from November 3, i.e. commit 0d1d7fc?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:41:03+00:00Added an answer on May 17, 2026 at 11:41 pm

    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:

    # This will detach your HEAD, that is, leave you with no branch checked out:
    git checkout 0d1d7fc32
    

    Or if you want to make commits while you’re there, go ahead and make a new branch while you’re at it:

    git checkout -b old-state 0d1d7fc32
    

    To go back to where you were, just check out the branch you were on again. (If you’ve made changes, as always when switching branches, you’ll have to deal with them as appropriate. You could reset to throw them away; you could stash, checkout, stash pop to take them with you; you could commit them to a branch there if you want a branch there.)

    Hard delete unpublished commits

    If, on the other hand, you want to really get rid of everything you’ve done since then, there are two possibilities. One, if you haven’t published any of these commits, simply reset:

    # This will destroy any local modifications.
    # Don't do it if you have uncommitted work you want to keep.
    git reset --hard 0d1d7fc32
    
    # Alternatively, if there's work to keep:
    git stash
    git reset --hard 0d1d7fc32
    git stash pop
    # This saves the modifications, then reapplies that patch after resetting.
    # You could get merge conflicts, if you've modified things which were
    # changed since the commit you reset to.
    

    If you mess up, you’ve already thrown away your local changes, but you can at least get back to where you were before by resetting again.

    Undo published commits with new commits

    On the other hand, if you’ve published the work, you probably don’t want to reset the branch, since that’s effectively rewriting history. In that case, you could indeed revert the commits. In many enterprise organisations, the concept of "protected" branches will even prevent history from being rewritten on some major branches. In this case, reverting is your only option.

    With Git, revert has a very specific meaning: create a commit with the reverse patch to cancel it out. This way you don’t rewrite any history.

    First figure out what commits to revert. Depending on the technique chosen below, you want to either revert only the merge commits, or only the non-merge commits.

    # This lists all merge commits between 0d1d7fc and HEAD:
    git log --merges --pretty=format:"%h" 0d1d7fc..HEAD | tr '\n' ' '
    
    # This lists all non merge commits between 0d1d7fc and HEAD:
    git log --no-merges --pretty=format:"%h" 0d1d7fc..HEAD | tr '\n' ' '
    

    Note: if you revert multiple commits, the order matters. Start with the most recent commit.

    # This will create three separate revert commits, use non merge commits only:
    git revert a867b4af 25eee4ca 0766c053
    
    # It also takes ranges. This will revert the last two commits:
    git revert HEAD~2..HEAD
    
    # Similarly, you can revert a range of commits using commit hashes (non inclusive of first hash):
    git revert 0d1d7fc..a867b4a
    
    # Reverting a merge commit. You can also use a range of merge commits here.
    git revert -m 1 <merge_commit_sha>
    
    # To get just one, you could use `rebase -i` to squash them afterwards
    # Or, you could do it manually (be sure to do this at top level of the repo)
    # get your index and work tree into the desired state, without changing HEAD:
    git checkout 0d1d7fc32 .
    
    # Then commit. Be sure and write a good message describing what you just did
    git commit
    

    The git-revert manpage actually covers a lot of this in its description. Another useful link is this git-scm.com section discussing git-revert.

    If you decide you didn’t want to revert after all, you can revert the revert (as described here) or reset back to before the revert (see the previous section).

    You may also find this answer helpful in this case:
    How can I move HEAD back to a previous location? (Detached head) & Undo commits

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you detect the current SCAN state and revert it after changing it?
ExecuteNonQuery requires an open and available Connection. The connection's current state is closed. What
How can I revert a modified file to its previous revision at a specific
I messed up on my SVN repository and now need to revert the entire
I read the following in an article Immutable objects are particularly handy for implementing
In a Linq Statement like the following (narrowed down to relevant parts for the
I would like to write a transition where all the elements from State1 rotate
Note that the order can go either way (erase first then push back, just
I am attempting to open a document from access, execute a mail merge, and
I've always thought of git reset and git checkout as the same, in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.