git 单个文件的格式补丁

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7885075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:09:26  来源:igfitidea点击:

format-patch for a single file

git

提问by ant2009

I have a file called test_module.c that has some differences that I want to apply to my local working copy.

我有一个名为 test_module.c 的文件,它有一些我想应用于我的本地工作副本的差异。

I tried to create patch file from the remote by doing the following. However, git didn't complain about any errors. And didn't create any patch file either.

我尝试通过执行以下操作从远程创建补丁文件。然而,git 并没有抱怨任何错误。并且也没有创建任何补丁文件。

git format-patch master/dev_branch test/test_module.c

It is possible to create a patch of a single file, that I can apply?

可以创建单个文件的补丁,我可以应用吗?

(Using git version 1.7.5.4)

(使用 git 版本 1.7.5.4)

回答by Mark Longair

If you give git format-patcha single revision, it will produce patches for each commit sincethat revision. If you see no output from that command, then I suspect that there were no changes to that file between origin/masterand your current HEAD. As an alternative, you can provide a revision range (e.g. origin/master~3..origin/master) which covers the changes introduced to that file. Or, if the changes you want to produce a patch for are just contained in the single commit at the tip of origin/master, you can use the -1parameter, as in:

如果您提供git format-patch单个修订,它将为该修订以来的每次提交生成补丁。如果您没有看到该命令的输出,那么我怀疑该文件origin/master与您当前的HEAD. 作为替代方案,您可以提供一个修订范围(例如origin/master~3..origin/master),其中涵盖了对该文件引入的更改。或者,如果要为其生成补丁的更改仅包含在 提示的单个提交中,则origin/master可以使用该-1参数,如下所示:

git format-patch -1 origin/master test/test_module.c

回答by Ondrej Slinták

You can use following syntax for creating patch for single file:

您可以使用以下语法为单个文件创建补丁:

git format-patch [commit_hash] [file]