git: how do I merge between branches while keeping some changesets exclusive to one branch?

前端 未结 9 554
情书的邮戳
情书的邮戳 2020-12-24 15:38

There\'s a special place in hell for people who hardcode absolute paths and database credentials into multiple random places in web applications. Sadly, before they go to he

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 16:06

    My solution to this problem uses rebase rather than merge

    Starting with a commit tree like this:

    a-b-c <-- master
     \
      d <-- local
       \
        e-f-g <-- dev
    

    $ git rebase --onto master local dev

           master 
           V 
       a-b-c-e'-f'-g' <-- dev
         \
          d <-- local
    

    $ git checkout master

    $ git merge dev

                   master 
                   V 
       a-b-c-e'-f'-g' <-- dev
         \
          d <-- local
    

    $ git rebase --onto master master local

                   master 
                   V 
       a-b-c-e'-f'-g' <-- dev
                    \
                     d' <-- local
    

    $ git branch -f dev local

                   master 
                   V 
       a-b-c-e'-f'-g'
                    \
                     d' <-- local
                     ^
                     dev
    

提交回复
热议问题