103

I've pushed a commit and I want to revert changes introduced by this commit by applying and committing a reversed patch. How do I do it?

Dziamid
  • 11,225
  • 12
  • 69
  • 104

3 Answers3

146

Use

git revert HEAD

This will create a patch that reverts the last commit and commit that patch as a new commit.

If you want to revert a specific earlier version, use

git revert <revision>

see also: http://schacon.github.com/git/git-revert.html

Tom
  • 4,742
  • 25
  • 32
pilif
  • 12,548
  • 5
  • 34
  • 31
51

Sounds like you want to use git-revert.

https://www.kernel.org/pub/software/scm/git/docs/git-revert.html

Laith Shadeed
  • 4,271
  • 2
  • 23
  • 27
Kris K.
  • 998
  • 9
  • 7
  • 1
    This is not a good option if you use a PR flow; in those cases you will want to make a new commit that put the changes from one commit back to what they were. – b01 Aug 23 '17 at 01:19
4

simply use

for committed file:

git revert <SHA1 ID>

for non-committed file:

git reset --hard HEAD
Amit
  • 1,841
  • 1
  • 19
  • 36