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
446 questions
10374
votes
37 answers

How do I undo 'git add' before commit?

I mistakenly added files to Git using the command: git add myfile.txt I have not yet run git commit. Is there a way to undo this, so these files won't be included in the commit?
paxos1977
  • 143,025
  • 26
  • 88
  • 126
7620
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,390
  • 8
  • 33
  • 46
1331
votes
16 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
  • 40,612
  • 24
  • 117
  • 207
1174
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
  • 29,041
  • 40
  • 118
  • 191
1131
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
  • 12,769
  • 4
  • 18
  • 22
917
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
  • 79,731
  • 47
  • 132
  • 166
884
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
  • 9,267
  • 5
  • 25
  • 32
395
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
  • 197,339
  • 40
  • 364
  • 376
343
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
  • 11,917
  • 15
  • 49
  • 74
311
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
  • 89,369
  • 79
  • 366
  • 801
290
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,451
  • 10
  • 27
  • 39
253
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,861
  • 32
  • 106
  • 204
247
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,482
  • 14
  • 44
  • 78
246
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,111
  • 5
  • 19
  • 9
107
votes
5 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
  • 8,129
  • 6
  • 35
  • 65
1
2 3
29 30