LoginSignup
163
113

More than 5 years have passed since last update.

gitで他ブランチの特定のコミットを取り込む方法

Last updated at Posted at 2016-09-17

git cherry-pickを使用することで実現することができる!

対象のコミット履歴を持っているブランチに移動する

$ git checkout hoge_a

コミット履歴を確認する(commit id をコピーしておく)

$ git log

commit hogehogehogehogehogehoge
Author: Boku <>
Date:   Sat Sep 17 21:43:15 2016 +0900

色々修正

コミットを取り込みたいブランチに移動する

$ git checkout hoge_b

先ほどコピーしたコミットIDを付与しcherry-pickコマンドを実行する

$ git cherry-pick hogehogehogehogehogehoge

コミット履歴でコミットが反映されているのを確認できていればOK

$ git log

commit hogehogehogehogehogehoge
Author: Boku <>
Date:   Sat Sep 17 21:43:15 2016 +0900

色々修正

ちなみに、反映させたいコミットがマージコミットだった場合optionで-mを用いて親番号を指定する必要がある

git cherry-pick -m 親番号 hogehogehogehogehogehoge

以上

163
113
2

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
163
113