Questions tagged [git-revert]

Revert changes of a commit in a Git repository

git revert allows you to revert some existing commits within a Git repository.

Popular questions

See also

References

$ git revert --help
493 questions
7611
votes
41 answers

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 Date: Thu Nov 4 18:59:41 2010…
Crazy Serb
  • 76,330
  • 8
  • 35
  • 47
2004
votes
21 answers

How can I remove a commit on GitHub?

I "accidentally" pushed a commit to GitHub. Is it possible to remove this commit? I want to revert my GitHub repository as it was before this commit.
hectorsq
  • 74,396
  • 19
  • 43
  • 46
1580
votes
18 answers

How can I revert multiple Git commits?

I have a Git repository that looks like this: A <- B <- C <- D <- HEAD I want the head of the branch to point to A, i.e., I want B, C, D, and HEAD to disappear and I want head to be synonymous with A. It sounds like I can either try to rebase…
Bill
  • 44,502
  • 24
  • 122
  • 213
1232
votes
2 answers

How do I use 'git reset --hard HEAD' to revert to a previous commit?

I know that Git tracks changes I make to my application, and holds on to them until I commit the changes. To revert to a previous commit, I used: $ git reset --hard HEAD HEAD is now at 820f417 micro How do I then revert the files on my hard drive…
Brian McDonough
  • 13,829
  • 4
  • 19
  • 23
1224
votes
14 answers

How can I revert uncommitted changes including files and folders?

Is there a Git command to revert all uncommitted changes in a working tree and index and to also remove newly created files and folders?
MEM
  • 30,529
  • 42
  • 121
  • 191
975
votes
4 answers

Undo a particular commit in Git that's been pushed to remote repos

What is the simplest way to undo a particular commit that is: not in the head or HEAD Has been pushed to the remote. Because if it is not the latest commit, git reset HEAD doesn't work. And because it has been pushed to a remote, git rebase…
lprsd
  • 84,407
  • 47
  • 135
  • 168
935
votes
13 answers

Rollback to an old Git commit in a public repo

How can I go about rolling back to a specific commit in git? The best answer someone could give me was to use git revert X times until I reach the desired commit. So let's say I want to revert back to a commit that's 20 commits old, I'd have to…
David
  • 9,799
  • 5
  • 28
  • 32
737
votes
9 answers

Revert to a commit by a SHA hash in Git?

I'm not clear on how git revert works. For example, I want to revert to a commit six commits behind the head, reverting all the changes in the intermediary commits in between. Say its SHA hash is 56e05fced214c44a37759efa2dfc25a65d8ae98d. Then why…
JP Silvashy
  • 46,977
  • 48
  • 149
  • 227
430
votes
3 answers

Reset all changes after last commit in git

How can I undo every change made to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files?
Dogbert
  • 212,659
  • 41
  • 396
  • 397
391
votes
1 answer

How to undo local changes to a specific file

I'm trying to undo local changes to a specific file. Nothing has been committed. When I want to revert all changes, I can perform git revert --reset HEAD. However, in this case, I don't want to revert all changes to all files. Its not clear or…
jww
  • 97,681
  • 90
  • 411
  • 885
380
votes
7 answers

What's the difference between Git Revert, Checkout and Reset?

I am trying to learn how to restore or rollback files and projects to a prior state, and don't understand the difference between git revert, checkout, and reset. Why are there 3 different commands for seemingly the same purpose, and when should…
haziz
  • 12,994
  • 16
  • 54
  • 75
334
votes
9 answers

Re-doing a reverted merge in Git

I have run into a bit of a problem here: I had a problem-specific branch 28s in Git, that I merged in the general develop branch. Turns out I had done it too fast, so I used git-revert to undo the merge. Now, however, the time has come to merge 28s…
Toms Mikoss
  • 9,097
  • 10
  • 29
  • 41
308
votes
8 answers

How can I move HEAD back to a previous location? (Detached head) & Undo commits

In Git, I was trying to do a squash commit by merging in another branch and then resetting HEAD to the previous place via: git reset origin/master But I need to step out of this. How can I move HEAD back to the previous location? I have the SHA-1…
timpone
  • 19,235
  • 36
  • 121
  • 211
290
votes
4 answers

Why does git revert complain about a missing -m option?

So I'm working on a project with other people, and there's multiple github forks being worked on. Someone just made a fix for a problem and I merged with his fork, but then I realized that I could find a better solution. I want to revert the commit…
icnhzabot
  • 9,801
  • 5
  • 21
  • 9
267
votes
2 answers

How to undo the last commit in git

By mistake, I did git add . and git commit in the develop branch. But luckily, I did not do git push. So I wanted to revert it back to original state. I tried git reset --soft and git reset HEAD --hard but looks like I have messed it up. How do I…
chintan s
  • 6,170
  • 16
  • 53
  • 86
1
2 3
32 33