How can I remove an applied git patch?

TL;DR

You can revert a patch with:

$ git apply -R <patch>

You can generate a patch either by one of the following:

This will generate a patch from a diff

$ git diff --patch > 0001-some-modifications.patch

If you want to generate a patch for just the HEAD commit:

$ git show --patch HEAD^ > 0001-some-modifications.patch

You can generate a patch for the previous 3 commits from HEAD:

$ git show --patch HEAD~3 > 0001-some-modifications.patch

You can apply the patch by:

$ git apply -- 0001-some-modifications.patch

You can revert a patch with:

$ git apply -R <patch>

When you generate a patch it is just a diff with metadata; files, line numbers adds/removes; something along the following:

commit 9dad147cbf16befecdef2e812c1249499bdef5ac
Author: My Name <email@example.org>
Date:   Mon Dec 21 20:46:01 2015 +0000

    Example commit message.

diff --git a/src/example.md b/src/example.md
new file mode 100644
index 0000000..ab73512
--- /dev/null
+++ b/src/example.md
@@ -0,0 +1,3 @@
+# Example document
+
+ Hello World

So when you use git apply you’re essentially applying the edits as per to the tree.

When you then run git apply -R git will simply do the opposite to the patch.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)