简体   繁体   English

Git将补丁应用到工作目录

[英]Git apply a patch to the working directory

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的工作目录中应用补丁?

You can use git apply which applies a patch: 您可以使用git apply来应用补丁:

git apply < patchname.patch

This does not create any commits. 这不会创建任何提交。 In fact, without any options the git apply command doesn't even need to have a Git repository. 实际上,没有任何选项, git apply命令甚至不需要Git存储库。 It just applies patches to files. 它只是将补丁应用于文件。

You can use a patch command, eg: 您可以使用patch命令,例如:

patch -p1 < path/file.patch

When using patch command, it will usually auto-detect the format. 使用patch命令时,通常会自动检测格式。 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. 当您尝试将补丁应用到工作目录而不是您希望补丁的项目的本地签出时,这很有用。

Otherwise use git apply if 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信息库的本地检出中使用它时,它将无法执行任何操作。

试试这个命令行

git am < patchname.patch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM