LoginSignup
35
32

More than 5 years have passed since last update.

別ブランチの一部の変更のみをmasterに取り込みたい時

Posted at
  • <begin>を別ブランチ内の取り込みたい部分の根本となるhash
  • <end>を別ブランチ内の取り込みたい部分の終端となるhash

として、以下のように打てば良い。

git rebase --onto master <begin> <end>

もちろん、安全のためにも、

git checkout -b <topic-name>
git rebase --onto master <begin> <end>

と新しいブランチを作ってからやると、やりたいことが定まったブランチ名でpull requestが送れるしとても良い。

ちなみに、このやり方はgit help rebaseの以下の部分を見て学んだ。よく出来たマニュアルで助かる。

git-rebase
First let's assume your topic is based on branch next. For example, a feature developed in topic depends on some functionality which is found in
       next.

               o---o---o---o---o  master
                    \
                     o---o---o---o---o  next
                                      \
                                       o---o---o  topic


       We want to make topic forked from branch master; for example, because the functionality on which topic depends was merged into the more stable
       master branch. We want our tree to look like this:

               o---o---o---o---o  master
                   |            \
                   |             o'--o'--o'  topic
                    \
                     o---o---o---o---o  next


       We can get this using the following command:

           git rebase --onto master next topic
35
32
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
32