git create patch with diff

后端 未结 4 1922
慢半拍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 13:57

    With git version 1.9.1, I am seeing similar complaints when use 'git apply' to apply the patch created using 'git diff'.

    It seems 1.9.1 git is having problem dealing with mixture of spaces & tabs in the patch file.

    warning: squelched 1 whitespace error warning: 6 lines add whitespace errors.

    @VonC's answer does not help and I am still getting the same warnings.

    The easiest solution is to simply use the 'patch' command which successfully applies all changes captured in 'git diff' output to the target git directory.

    $ patch --version GNU patch 2.7.1

    0 讨论(0)
  • 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...
    
    0 讨论(0)
  • 2021-02-01 14:17

    Try a:

    git apply --ignore-space-change --ignore-whitespace patch.diff
    

    As mentioned in "git: patch does not apply", this can be caused by:

    • the line endings differing between the local file system and the remote repo.
      User core.eol in .gitattributes file is a good approach (see "git force file encoding on commit")
    • the execution bit ('x').
      That can lead you to set git config core.filemode false, followed by a git reset --hard HEAD (make sure you don't have uncommitted changes, or they would be lost).
    0 讨论(0)
  • 2021-02-01 14:18

    Here you have to try it with the branch you have diff with.

    git diff 13.1_dev sale_edit > patch.diff yourBranch()
    
    0 讨论(0)
提交回复
热议问题