Using GIT, how can I selectively merge changes from one commit on another 'fork'?

后端 未结 4 1159
傲寒
傲寒 2020-12-07 08:08

Take this scenario:

  1. I decide to \'fork\' a codebase on github.com, and start doing my routine: Edit - Commit - Push; aka hack hack hack.
  2. After I made
4条回答
  •  误落风尘
    2020-12-07 08:29

    I really like Tim's solution, however sometimes I like tinkering in vimdiff. My solution to this problem is crude, but it works for me because I like vim.

    I have vimdiff set as my difftool, and then to selectively merge I diff the branch:

    git difftool  
    

    Then I go to the pane with the current branch's version and edit the original in vim (sometimes this isn't necessary, but sometimes vimdiff opens a version in /tmp) and disable read-only mode:

    :e 
    :set readonly!
    

    Now I can use vim's patch tools such as do and dp to apply what I want, and make other little edits as I go. When I am done, I save the file, exit out of vim, and then stage and commit the file in git like a regular edit.

    As I said, this isn't particularly sophisticated, but it is very powerful, and still purely in the command line. Just be sure to add a clear commit message, as git won't automatically include a merge message for you.

    vimdiff example http://j.mp/1dZVllt

提交回复
热议问题