How can I selectively merge or pick changes from another branch in Git?

前端 未结 25 1956
慢半拍i
慢半拍i 2020-11-22 02:53

I\'m using Git on a new project that has two parallel -- but currently experimental -- development branches:

  • master: import of existing codebase pl
25条回答
  •  耶瑟儿~
    2020-11-22 03:18

    You use the cherry-pick command to get individual commits from one branch.

    If the change(s) you want are not in individual commits, then use the method shown here to split the commit into individual commits. Roughly speaking, you use git rebase -i to get the original commit to edit, then git reset HEAD^ to selectively revert changes, then git commit to commit that bit as a new commit in the history.

    There is another nice method here in Red Hat Magazine, where they use git add --patch or possibly git add --interactive which allows you to add just parts of a hunk, if you want to split different changes to an individual file (search in that page for "split").

    Having split the changes, you can now cherry-pick just the ones you want.

提交回复
热议问题