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
404 questions
7624
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,496
  • 8
  • 33
  • 46
1190
votes
15 answers

How to 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
  • 38,492
  • 24
  • 114
  • 205
1131
votes
14 answers

How to 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
  • 27,721
  • 40
  • 115
  • 190
1055
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 it holds on to them until I commit the changes, but here's where I'm hung up: When I want to revert to a previous commit I use: git reset --hard HEAD And Git returns: HEAD is now at…
Brian McDonough
  • 11,931
  • 4
  • 16
  • 22
862
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…
Lakshman Prasad
  • 76,135
  • 46
  • 128
  • 164
851
votes
11 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
  • 8,917
  • 5
  • 23
  • 31
360
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
  • 188,810
  • 39
  • 339
  • 353
313
votes
6 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
  • 11,199
  • 14
  • 48
  • 69
271
votes
8 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
  • 8,091
  • 10
  • 26
  • 39
270
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
  • 83,594
  • 69
  • 338
  • 732
230
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
  • 5,052
  • 13
  • 40
  • 71
215
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
  • 8,591
  • 5
  • 19
  • 9
212
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
  • 17,029
  • 31
  • 103
  • 200
98
votes
3 answers

I need to pop up and trash away a "middle" commit in my master branch. How can I do it?

For example, in the following master branch, I need to trash just the commit af5c7bf16e6f04321f966b4231371b21475bc4da, which is the second due to previous rebase: commit 60b413512e616997c8b929012cf9ca56bf5c9113 Author: Luca G. Soave…
Luca G. Soave
  • 11,195
  • 10
  • 55
  • 105
88
votes
4 answers

Revert a merge after being pushed

Steps i performed: I have two branches branch1 and branch2, $git branch --Initial state $branch1 $git checkout branch2 $git pull origin branch1 --Step1 I resolve the conflicts and did a $git commit -m "Merge resolved" then $git checkout…
Bijendra
  • 7,429
  • 5
  • 32
  • 60
1
2 3
26 27