3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

複数コミットをcherry-pick

Posted at

1コミットをもってくる場合

branch-1のコミット履歴
$ git log --oneline
je903h92 commit 3
03843h90 commit 2
09459090 commit 1
87436843 first commit

たとえば、branch-2に1つのコミットをもっていきたい場合は、git cherry-pick {commit number}で解決できます。

$ git checkout branch-2
$ git log --oneline
349fi29u new commit

$ git cherry-pick je903h92 # commit 3をもってくる

$ git log --oneline
je903h92 commit 3 # コミットが追加されている
349fi29u new commit

複数コミットをもってくる場合

例えばcommit 1、commit 2、commit 3をbranch-2へもってくる場合は、git cherry-pick {start commit number}..{end commit number}を叩けばもってくることができます。
ですが、start commit numberの部分は、もってきたい始めのコミットの1つ前のコミット番号を指定しなくてはいけません。

$ git checkout branch-2
$ git log --oneline
349fi29u new commit

$ git cherry-pick 87436843..je903h92 # commit 1~3をもってくる

$ git log --oneline
je903h92 commit 3
03843h90 commit 2
09459090 commit 1
349fi29u new commit
3
6
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
3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?