你如何获得一个git diff文件,并将它应用到同一个存储库副本的本地分支? [英] How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?

查看:452
本文介绍了你如何获得一个git diff文件,并将它应用到同一个存储库副本的本地分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由同事创建的.diff文件,并希望将差异文件中列出的更改应用到完全相同存储库的本地分支。我无法访问用于生成此diff文件的该工作人员的pc或分支。



显然,我可以一行一行地重新输入所有内容,但是我会而不是使系统受到人为错误的影响。

解决方案

将diff文件复制到存储库的根目录下,然后执行: p>

  git apply yourcoworkers.diff 

有关 apply 命令的更多信息可在手册页



顺便说一句:按文件交换整个提交的更好方法是接收者上的命令 git format-patch ,然后在接收者上输入 git am ,因为它也传输作者信息如果补丁程序失败,并且如果提交的差异是由您生成的,实际上是在您的repo中,您可以使用消息。

-3 选项应用,它试图在变更中合并。



使用Unix管道,如下所示:

  git diff d892531 8 15a3b5 | git apply 


I have a .diff file created by a coworker, and would like to apply the changes listed in that diff file to my local branch of the exact same repository. I do not have access to that worker's pc or branch that was used to generate this diff file.

Obviously I could go line by line and retype everything, but i'd rather not subject the system to human error. What's the easiest way to do this?

解决方案

Copy the diff file to the root of your repository, and then do:

git apply yourcoworkers.diff

More information about the apply command is available on its man page.

By the way: A better way to exchange whole commits by file is the combination of the commands git format-patch on the sender and then git am on the receiver, because it also transfers the authorship info and the commit message.

If the patch application fails and if the commits the diff was generated from are actually in your repo, you can use the -3 option of apply that tries to merge in the changes.

It also works with Unix pipe as follows:

git diff d892531 815a3b5 | git apply

这篇关于你如何获得一个git diff文件,并将它应用到同一个存储库副本的本地分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆