This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
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 <[email protected]>
Date: Thu Nov 4 18:59:41 2010 -0400
blah blah blah…
commit 25eee4caef46ae64aa08e8ab3f988bc917ee1ce4
Author: Me <[email protected]>
Date: Thu Nov 4 05:13:39 2010 -0400
more blah blah blah…
commit 0766c053c0ea2035e90f504928f8df3c9363b8bd
Author: Me <[email protected]>
Date: Thu Nov 4 00:55:06 2010 -0400
And yet more blah blah…
commit 0d1d7fc32e5a947fbd92ee598033d85bfc445a50
Author: Me <[email protected]>
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?
This depends a lot on what you mean by \”revert\”. If you want to go back to it, fool around, then return to where you are, all you have to do is check out the commit: # This will detach your HEAD, that is, leave you with no branch checked out: git checkout 0d1d7fc32.\n\ngit checkout -b old-state 0d1d7fc32: If you want to commit while you\’re there, go ahead and make a new branch.\n\nIf you want to go back to where you were, just look at the branch you\’re on. (If you have made the changes, as always when you switch branches, you will have to deal with them as appropriate. You could reset them to throw them away; stash, checkout, stash pop to take them with you; if you’ve done any of these commits since then you can’t really get them rid of any local changes.’ One is a one that has not published any uncommitted commit, but has just reset.\n\nIf there\’s work to keep: \”git stash git reset –hard 0d1d7fc32 GitHub stash pop # # This saves the changes, then reapplies that patch after reset; # You\’ll get merge conflicts when you\’ve changed things that were # since the commit you reset to.\”\n\nIf you have messed up, you’re [[] — [……——it’s [ [t]h]—[[…]––—rere—to – [re]] [to]t–re–to–…–’’t—was [the] so-called [meme—–their—what] was [ad–e–n’–h–d—did [very] on [d] in a []queque—stuffuff—d [—h—…’—–—a–[—t’hh [–-—n—or—in—out—and—the—r–s—o—–—me–o–”—on—e—I–][–it—not—an—off—for—thing—all—you—i–.”—had—p—’…[ [’.—échec—_—que–I—].–“–“.“.\n\n# # 0d1d7fc and HEAD: git log –no-merges — –pretty=format:\”%h\” 0-d1,d6fce..HEAD | tr \’n\’ .\n\nNote: If you revert multiple commits, the order matters. Start with the most recent commit. # ### This will make three separate, use non merge commit only: git Revert a867b4af 25Eee4ca 0766c053\n\nThe last two commits will be reversed: git revert HEAD2..HEAD: # # It also takes ranges.\n\nSimilarly, you can reverse a sequence of commits with commit hashes (non inclusive of first hash): git revert 0d1d7fc..a867b4a.\n\nYou can also use a variety of merge commits here, as well as git revert -m 1 merge_commit_sha>.\n\nIf you have rebase -i to squash them after # Or, you can do it manually (be sure to do so at the top level of the repo) # get your index and work tree into the desired state without changing HEAD: git checkout 0d1d7fc32 .\n\n# Then commit. Be sure and write a good message about what you just did git commit .\n\nThis is a good description of this in the git-revert manpage.’ Another useful link is this section on GitHub-scm.com for \’reverted\’ (as described here) or reset back to before revers (see previous section) & Undo commits if you decided you didn\’t want to reset after all.