简体   繁体   English

git am从分支到主

[英]git am from branch to master

I'm working together with a college of mine in git. 我正在与我的git大学合作。 I'm working on a branch, and he's working on the master. 我在分支机构工作,而他在主管工作。 I've done some work related to his files on my branch, and I decided to send him a patch file. 我已经完成了与他的分支上的文件有关的一些工作,因此决定将补丁文件发送给他。 I created the patch with git format-patch , and sent it to him. 我使用git format-patch创建了补丁,并将其发送给他。 when he tries to apply the patch using git am he get's the following message: previous release directory 当他尝试使用git am应用补丁git am ,会收到以下消息: previous release directory

It's probably because the patch arrived from a different branch. 可能是因为补丁来自其他分支。

Is there a way for him to use the patch on the master branch ? 他有办法在master分支上使用补丁吗?

Note: I'm using git am , and not git apply to keep commit-id that is generated for jetty. 注意:我使用的是git am ,而不是git apply来保留为码头生成的commit-id。 I still want the commiter to be me on his local repository. 我仍然希望提交者在我的本地存储库中成为我。

Consider using one of the two solutions when dealing with patches that fails to apply properly : 在处理无法正确应用的补丁时,请考虑使用以下两种解决方案之一:
(article from bugdromer ): (来自bugdromer的文章):


The simplest way for dealing with it would be to: 处理它的最简单方法是:

  • git am --abort , git am --abort
  • apply the patch manually by patch -p1 < PATCH , 通过patch -p1 < PATCH手动应用补丁
  • resolve the conflict by hand, 手工解决冲突,
  • and finally commit with git commit -a . 最后使用git commit -a

But in this case you'll have to rewrite the commit message, which is not very nice. 但是在这种情况下,您将不得不重写提交消息,这不是很好。 There is a more clever way. 还有一种更聪明的方法。


You can find the corresponding patch file stored in .git/rebase-apply , and named " 0001 " (the name of the dir where the patch is stored changed recently, this is tested with 1.7.4.1). 您可以在.git/rebase-apply找到相应的修补程序文件,并将其命名为“ 0001 ”(存储修补程序的目录名称最近已更改,已使用1.7.4.1进行了测试)。
At this point: 这一点:

  • you can use git apply for applying the patch, which is the git equivalent of the patch command , 您可以使用git apply来应用补丁,这与patch命令的git等价
  • and fix the conflicting files the usual way (you check the .rej files, compare them with the conflicting files and finally add the fixed files to the index): 并以通常的方式修复冲突的文件(您检查.rej文件,将它们与冲突的文件进行比较,最后将已修复的文件添加到索引中):

Example: 例:

$ git apply PATCH --reject
$ edit edit edit
$ git add FIXED_FILES
$ git am --resolved

and you're done! 完成了!
In other words, since git am didn't change the index, you need to 换句话说,由于git am并没有更改索引,因此您需要

  • git apply --reject the patch (stored in .git/rebase-apply ), git apply --reject补丁(存储在.git/rebase-apply ),
  • fix conflicts by hand, 手动解决冲突,
  • add the changed files and 添加更改的文件并
  • finally tell git that you resolved the trouble. 最后告诉git您解决了麻烦。

The advantage in this case is that: 在这种情况下的优点是:

  • you don't need to re-edit the commit message, 您不需要重新编辑提交消息,
  • and in the case you're applying a set of patches (that is you're using git am PATCHES , where PATCHES is a mailbox), you don't have to git abort and run git am again. 并且如果您要应用一组补丁程序(即您正在使用git am PATCHES ,其中PATCHES是邮箱),则不必git abort并再次run git am

Try the --3way option of git am : 尝试git am--3way选项:

 -3, --3way When the patch does not apply cleanly, fall back on 3-way merge if the patch records the identity of blobs it is supposed to apply to and we have those blobs available locally. 

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

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