Git 将补丁应用到工作目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8753056/
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-19 06:19:05  来源:igfitidea点击:

Git apply a patch to the working directory

git

提问by Omar

I have a patch that contains a lot of changes that I would like to split into multiple commits and potentially modify some of the changes.

我有一个补丁,其中包含许多更改,我想将这些更改拆分为多个提交并可能修改其中的一些更改。

I want to apply this patch to my working directory and then manually commit the changes. Is it possible to apply a patch to the working directory in git?

我想将此补丁应用到我的工作目录,然后手动提交更改。是否可以将补丁应用于 git 中的工作目录?

回答by Greg Hewgill

You can use git applywhich applies a patch:

您可以使用git applywhich 应用补丁:

git apply < patchname.patch

This does not create any commits. In fact, without any options the git applycommand doesn't even need to have a Git repository. It just applies patches to files.

这不会创建任何提交。事实上,如果没有任何选项,该git apply命令甚至不需要拥有 Git 存储库。它只是将补丁应用于文件。

回答by kenorb

You can use a patchcommand, e.g.:

您可以使用patch命令,例如:

patch -p1 < path/file.patch

When using patchcommand, it will usually auto-detect the format. This is useful when you're trying to apply patch to the working directory which isn't a local checkout of the project you wish to patch.

使用patch命令时,通常会自动检测格式。当您尝试将补丁应用到工作目录时,这非常有用,该目录不是您希望修补的项目的本地检出。

Otherwise use git applyif your patch was created specifically for the project, otherwise it will fail to do anything when used within a local checkout of a git repository.

否则,git apply如果您的补丁是专门为项目创建的,则使用,否则在 git 存储库的本地检出中使用时将无法执行任何操作。

回答by Mark Shust at M.academy

Try this command line

试试这个命令行

git am < patchname.patch