how to apply a git patch as if the author committed to my repo?

落花浮王杯 提交于 2019-12-05 17:40:26

问题


Lets suppose there is a central repository where commits from satellite ones are pushed some time. Developer A makes some commits on his repo while B makes some on his own too.

Now, A wants to incorporate one of B's commits into his repo (which he cannot access directly to pull).

One way is to have B create a patch and send it to A but in that case there are two problems: 1. The patch will appear as local modifications to A who have then to commit it (with its own name) 2. Once the central repo is updated the changes will conflict (being pushed by two different authors).

Is there a way to have the patch applied directly "as a commit" on local A repo so that it will appear to him as if it were pulled from the central repo (i.e. origin)?

PS: (this might not apply: see comments: is there a way to strike text until verified?) After some more investigation and testing looks like also git am < git-formatted-patch would make it so that the patch appears committed to the local master (then I hope it will be recognized as the same commit when B pushes it to the central repo). It looks like it is git apply that leaves the patch uncommitted...


回答1:


B could create and send a bundle rather than a patch. This allows sending commits when none of the transports available for push or fetch will work.




回答2:


git am is what you're looking for. Ask him to commit locally and do git format-patch. This will create a patch. You can then use git am to add it to your repo.



来源:https://stackoverflow.com/questions/15551298/how-to-apply-a-git-patch-as-if-the-author-committed-to-my-repo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!