git create commit from diff between two branches

后端 未结 3 1769
终归单人心
终归单人心 2021-01-30 00:57

I have two branches which have very little similar history, but are related to each other.

I want the changes between those two in one git commit.

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-30 01:06

    If you have two branches:

    1. has-changes
    2. needs-changes

    And you want to move the changes from has-changes onto needs-changes, then do the following:

    git checkout -b deleteme has-changes # Create temporary branch to build commit on
    git reset --soft needs-changes       # Move diff into index
    git commit                           # Create the diff patch commit
    git checkout needs-changes           # Switch to branch that needs changes
    git cherry-pick deleteme             # Apply the diff to the needs-changes
    git branch -D deleteme               # Delete the temporary branch
    

提交回复
热议问题