Create patch or diff file from git repository and apply it to another different git repository

前端 未结 4 1572
青春惊慌失措
青春惊慌失措 2020-12-12 09:33

I work on WordPress based project and I want to patch my project at each new release version of WP. For this, I want generate a patch between two commits or tags.

For

相关标签:
4条回答
  • 2020-12-12 10:00

    As a complementary, to produce patch for only one specific commit, use:

    git format-patch -1 <sha>
    

    When the patch file is generated, make sure your other repo knows where it is when you use git am ${patch-name}

    Before adding the patch, use git apply --check ${patch-name} to make sure that there is no confict.

    0 讨论(0)
  • 2020-12-12 10:02

    To produce patch for several commits, you should use format-patch git command, e.g.

    git format-patch -k --stdout R1..R2
    

    This will export your commits into patch file in mailbox format.

    To generate patch for the last commit, run:

    git format-patch -k --stdout HEAD^
    

    Then in another repository apply the patch by am git command, e.g.

    git am -3 -k file.patch
    

    See: man git-format-patch and git-am.

    0 讨论(0)
  • 2020-12-12 10:05

    you can apply two commands

    1. git diff --patch > mypatch.patch // to generate the patch
    2. git apply mypatch.patch // to apply the patch
    0 讨论(0)
  • 2020-12-12 10:14

    You can just use git diff to produce a unified diff suitable for git apply:

    git diff tag1..tag2 > mypatch.patch
    

    You can then apply the resulting patch with:

    git apply mypatch.patch
    
    0 讨论(0)
提交回复
热议问题