我如何删除应用的git补丁? [英] How can I remove an applied git patch?

查看:174
本文介绍了我如何删除应用的git补丁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git repo,我们在测试环境中应用了许多补丁。

  git apply --stat --check --ignore-whitespace /home/kent/Desktop/patches/test.patch --exclude .gitignore 

git am -s --ignore-whitespace / home / kent / Desktop / patches / test。 patch --exclude .gitignore --exclude .gitignore

如果我必须删除补丁并应用新的,我现在克隆现场内容并重新应用所有的测试补丁并再次推送。
这个过程有点麻烦,而且有时候我还会错过一两个补丁。



我想知道是否有办法删除一个补丁,并应用新的补丁



另外,如果我们每次都提交补丁,然后可以使用:

  git revert<< commit id>> 

以上所有内容对我来说都不适用。


$ b
$ b

  $ git apply -R< patch> 






您可以通过其中一个以下内容:

这将从diff中生成一个补丁

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

如果您想为HEAD提交生成补丁:

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

您可以为以前的 3 提交HEAD:

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

您可以通过以下方式应用该补丁:

  $ git apply  -  0001-some-modifications.patch 

您可以使用以下格式恢复修补程序:

  $ git apply -R< patch> 

当您生成一个补丁时,它只是一个带有元数据的diff;文件,行号添加/删除;以下内容:

 提交9dad147cbf16befecdef2e812c1249499bdef5ac 
作者:我的名字< email@example.org>
日期:星期一12月21日20:46:01 2015 +0000

示例提交消息。

diff --git a / src / example.md b / src / example.md
新文件模式100644
索引0000000..ab73512
--- / dev / null
+++ b / src / example.md
@@ -0,0 +1,3 @@
+#示例文件
+
+ Hello World

所以当你使用 git apply git apply -R 时,你将基本上应用编辑到树中。

> git只会做与修补程序相反的操作。


I have a git repo, where we apply many patches in test environment.

git apply --stat --check --ignore-whitespace /home/kent/Desktop/patches/test.patch --exclude .gitignore

git am -s --ignore-whitespace /home/kent/Desktop/patches/test.patch --exclude .gitignore --exclude .gitignore

If I have to remove the patch and apply a new one, at present I clone the live content and reapply all the test patches and push again. This process is somehow cumbersome and also leads to errors at times I also miss one or two patches.

I wanted to know if there is a way to remove a patch and apply the new one

Also, to add one way is there if we commit each time to the patch and then i can use:

git revert <<commit id>>

The above does not work for me at all times.

解决方案

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.

这篇关于我如何删除应用的git补丁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆