如何在给定拉号时应用 git 补丁
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7827002/
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
How to apply a git patch when given a pull number
提问by Homunculus Reticulli
I downloaded a trunk version of a codebase from git, and there are build errors. Aparently a patch is now available, and I received an email :
我从 git 下载了一个代码库的主干版本,并且存在构建错误。显然现在有一个补丁可用,我收到了一封电子邮件:
see https://github.com/JustinTulloss/zeromq.node/pull/47 for patch
见 https://github.com/JustinTulloss/zeromq.node/pull/47 补丁
I am new to git so I'm not quite sure what to do with this 'patch' especially, since the page looks more like a discussion thread.
我是 git 的新手,所以我不太确定如何处理这个“补丁”,特别是,因为该页面看起来更像是一个讨论线程。
Does anyone know how I can obtain/apply this patch to my locally cloned git repository?
有谁知道我如何获取/将此补丁应用于我本地克隆的 git 存储库?
回答by Andrew
Save the patch somewhere. If you're using linux you can use curl:
将补丁保存在某处。如果您使用的是 linux,则可以使用 curl:
curl -L https://github.com/JustinTulloss/zeromq.node/pull/47.patch > /tmp/47.patch
To apply the patch use git apply
. You can see if the patch will apply cleanly with the check
option. Change to your git directory and run:
要应用补丁,请使用git apply
. 您可以使用该check
选项查看补丁是否可以干净地应用。切换到您的 git 目录并运行:
git apply --check /tmp/47.patch
If it looks like you want to apply the patch remove the check option
如果看起来您想应用补丁,请删除检查选项
git apply /tmp/47.patch
回答by manojlds
Just add a .patch
at the end to get the patch:
只需.patch
在末尾添加一个即可获得补丁:
https://github.com/JustinTulloss/zeromq.node/pull/47.patch
https://github.com/JustinTulloss/zeromq.node/pull/47.patch
You can do something like below:
您可以执行以下操作:
$ git checkout master
$ curl http://github.com/JustinTulloss/zeromq.node/pull/47.patch | git am
$ git push origin master
回答by gasolin
The rule seems recently changed.
规则似乎最近发生了变化。
Previously we took a PR and add a .patch
at the end to get the patch
之前我们拿了一个 PR 并.patch
在最后添加一个以获得补丁
http://github.com/[group]/[project]/pull/30583.patch
But now the link is redirect(301) to
但现在链接重定向(301)到
https://patch-diff.githubusercontent.com/raw/[group]/[project]/pull/30583.patch
So if you use curl
, you could pipe with git apply
command to apply a git patch from the Pull Request
因此,如果您使用curl
,则可以使用git apply
命令通过管道从拉取请求中应用 git 补丁
curl https://patch-diff.githubusercontent.com/raw/[group]/[project]/pull/30583.patch | git apply
If the patch is not right for you now, use git apply -R
command to rollback the change.
如果补丁现在不适合您,请使用git apply -R
命令回滚更改。
回答by thakis
To let git download pull request 47 and patch it into mylocalbranch
locally, run:
要让 git 下载 pull request 47 并将其修补到mylocalbranch
本地,请运行:
git checkout -b mylocalbranch
git pull origin pull/47/head
If the pull request isn't on the origin repo, run
如果拉取请求不在原始存储库中,请运行
git remote add patchremote https://github.com/JustinTulloss/zeromq.node
git pull patchremote pull/47/head
回答by Halton Huo
git fetch -q origin +refs/pull/47/merge:
git checkout -qf FETCH_HEAD