在 git 中创建一个包含特定文件的补丁
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9939952/
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
Create a patch including specific files in git
提问by vasilakisfil
Let's say that I am 7 commits ahead of the origin/master repo. I would like to create a patch that includes in the patch specific files that were changed, not all the files. Or equivalent exclude specific files from the patch that were changed. How can I achieve that?
假设我在原始/主存储库之前提交了 7 次。我想创建一个补丁,其中包含已更改的补丁特定文件,而不是所有文件。或等效地从已更改的补丁中排除特定文件。我怎样才能做到这一点?
回答by Mark Longair
You can restrict the output of git diff
by listing paths at the end of the command (after a --
to avoid any potential clashes between path names and branch names). For example, you could do the following:
您可以git diff
通过在命令末尾列出路径来限制输出(在 a 之后--
以避免路径名称和分支名称之间的任何潜在冲突)。例如,您可以执行以下操作:
git diff origin/master HEAD -- app/models/region.rb doc/ > changes.patch
... to generate a patch that only shows the differences within a particular file and a particular directory.
...生成一个补丁,只显示特定文件和特定目录中的差异。
回答by lars
You can include files in the patches with:
您可以在补丁中包含文件:
git format-patch <rev> <files...>
Example
例子
git format-patch HEAD^^^ Makefile
Will give you three files 0001-[commit] ... 0003-[commit] only containing the Makefile.
会给你三个文件 0001-[commit] ... 0003-[commit] 只包含 Makefile。