git create patch with diff

后端 未结 4 1927
慢半拍i
慢半拍i 2021-02-01 13:32

I tried doing

git diff 13.1_dev sale_edit > patch.diff

Then I tried doing git apply patch.diff in another branch, but I got pa

4条回答
  •  抹茶落季
    2021-02-01 14:10

    You can apply the patch as a 3-way merge:

    git diff 13.1_dev sale_edit > patch.diff
    git apply -3 patch.diff
    

    It should bring up the conflict so that you can resolve manually. Or you could go with a one-liner, piping the patch to git-apply directly:

    git diff 13.1_dev sale_edit | git apply -3
    

    To reverse the patch:

    git diff 13.1_dev sale_edit | git apply -3 -R
    

    (note: this is same as the commands above, without the two-stage process of creating the patch file)

    git help apply
    
    -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, possibly leaving 
    the conflict markers in the files in the working tree for the user 
    to resolve...
    

提交回复
热议问题