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

后端 未结 6 1043
终归单人心
终归单人心 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:36

    You could create the patch using git diff and then apply it using the patch utility, which allows you to specify the file you want to apply the diff to.

    For example:

    cd first-repo
    git diff HEAD^ -- hello.test > ~/patch_file
    
    cd ../second-repo
    patch -p1 blue/red/hi.test ~/patch_file
    

提交回复
热议问题