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

前端 未结 25 1614
慢半拍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:23

    I had the exact same problem as mentioned by you above. But I found this clearer in explaining the answer.

    Summary:

    • Check out the path(s) from the branch you want to merge,

       $ git checkout source_branch -- ...
      
      Hint: It also works without `--` like seen in the linked post.
      
    • or to selectively merge hunks

       $ git checkout -p source_branch -- ...
      

    Alternatively, use reset and then add with the option -p,

        $ git reset ...
        $ git add -p ...
    
    • Finally commit

       $ git commit -m "'Merge' these changes"
      

提交回复
热议问题