How to apply a Git patch to a file with a different name and path?

后端 未结 6 1058
终归单人心
终归单人心 2020-12-04 09:10

I have two repositories. In one, I make changes to file ./hello.test. I commit the changes and create a patch from that commit with git format-patch -1 HE

6条回答
  •  醉酒成梦
    2020-12-04 09:39

    I understand the two files are exactly the same in your situation, thus the patch is likely to succeed.

    However, in case you want to apply a patch to a similar, but not exactly the same file, or you want to do an interactive patching, you will use three way merge.

    Say you modified File A, let's denote A~1 as the previous version, and you want to apply the diff between A~1 to A to File B.

    Open a three way merge tool, for instance Beyond Compare, the path of left panel is A, middle panel is the common ancestor so the path is A~1, the path of right panel is B. Then, the lower panel shows the result of applying the diff between A~1 to A to File B.

    The following figure illustrates the idea.

提交回复
热议问题