How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?

前端 未结 1 599
慢半拍i
慢半拍i 2020-11-30 16:08

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 acces

相关标签:
1条回答
  • 2020-11-30 16:52

    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
    
    0 讨论(0)
提交回复
热议问题