How do I revert a Git repository to a previous commit?




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]](/cdn-cgi/l/email-protection)>
Date:   Thu Nov 4 18:59:41 2010 -0400

blah blah blah...

commit 25eee4caef46ae64aa08e8ab3f988bc917ee1ce4
Author: Me <[[email protected]](/cdn-cgi/l/email-protection)>
Date:   Thu Nov 4 05:13:39 2010 -0400

more blah blah blah...

commit 0766c053c0ea2035e90f504928f8df3c9363b8bd
Author: Me <[[email protected]](/cdn-cgi/l/email-protection)>
Date:   Thu Nov 4 00:55:06 2010 -0400

And yet more blah blah...

commit 0d1d7fc32e5a947fbd92ee598033d85bfc445a50
Author: Me <[[email protected]](/cdn-cgi/l/email-protection)>
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".


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. 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.



```
# This will create three separate revert commits:
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
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](https://schacon.github.com/git/git-revert.html) actually covers a lot of this in its description. Another useful link is [this git-scm.com section discussing git-revert](https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_undoing_merges).


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](https://ask4knowledgebase.com/questions/34519665/how-can-i-move-head-back-to-a-previous-locationdetached-headundo-commits)
hey,

if you want restart the refer to this -

[image]

[how to do git reset?](https://forum.crio.do/t/how-to-do-git-reset/9567) [setup and git](/c/common-faqs/setup-and-git)

hi there,

looks like you are facing challenges and you want to reset your git repository.

great. let me help you here.

there are three scenarios where you would require to reset … If all you want to change is a single file, do that and commit it.


Then you can use `git rebase -i` to rearrange commits. In particular, you can move the change to the license file to the beginning of history, as if it had always been there. what to do::

docker exec -it gitlab /bin/bash

then

apt install update-manager-core

then

do-release-upgrade hi there, can you pm me your uphold email address? i can look into your account and issue you a refund. :slight\_smile: Hello,
  

  
You will not be able to use another number to open your account. You wouldn’t first have to log in to change it. However, you can use the alternative email address and your security questions to recover your account. [See this article](https://ccm.net/faq/9225-how-to-recover-gmail-account#you-have-not-registered-alternate-recovery-options) for instructions to get started at the recovery page. 
  

  
If you do not have an alternate email address registered or security questions, you will not be able to recover your account.
  

  
Regards, http://community.spiceworks.com/help/how\_do\_i\_send\_spiceworks\_my\_log\_files%3f hello [@cjiang1](/u/cjiang1),

welcome to gitlab forum - thanks for your first contribution :slightly\_smiling\_face:

i think this is most probably caused by a misconfiguration - here’s an [example](https://gitlab.com/gitlab-org/gitlab-ce/issues/48349#note_129188834), fyi. hi mike, thanks for bringing this to our attention, i can confirm that i’m aware of this issue and a fix is in progress. i expect the latest version to be available the debian/rpm repositories in the coming days.

one short term work around would be to download the .deb or .rpm file directly from th… The only people who can help you are GMail:
  

  
Here is the link to gmail support website : 
  

  
<https://support.google.com/mail/?hl=en#topic=3394212>
  

  
or use this account recovery [form](https://accounts.google.com/signin/recovery?hl=fr&ard=AHwGkRn_INMwM1maYDEUIHVZNP2OO33Anf9X_3sYq47TUs9Cf0K0IB4M1yZT79Q7tGqRtj6I5pU_YOJStf9xC56SlvhqWQChjjt1VG7X120zprR1Mdv5kGAWPQxPv-CIeEO1l4gGKbVhqD0LvkrQ7xMKE_xYOy6Gow&fpOnly=1)
  

  
On the other hand, if you have not used your Gmail account for over 30 days, it may have been deleted. You must then create a new one, insuring that you note your password and security question and store it a safe place, remembering where the safe place is.
  

  
Best regards [image] sgenter:

is there another way to zip off a chapter with the new version of bookdown? alternatively, how would i revert to the previous version?

this is a pretty specific use case and don't know yet about. so i don't think you can "zip" the way you want

[image] sgenter:

i do reali…