cherry-pickの動作確認してみた

結論としてはcherry-pickはオプションなしでやると
コミットまでしてしまうので、使うなら 

```
    -n, --no-commit       don't automatically commit
```

$ git cherry-pick -n [HASH]

でcherry-pickして、diffったりして確認してからcommitするのが良さそう。

### opiディレクトリにopiというファイルをつくってmasterにコミット

```
$ pwd
/tmp
$ mkdir opi
$
$
$ cd opi/
$ ls -a
.	..
$ 
$ echo "opi1" > op1
$ 
$ git init
Initialized empty Git repository in /private/tmp/opi/.git/
$ 
$ git add op1 
$ 
$ git commit -m "opi1"
[master (root-commit) 0e74249] opi1
 1 file changed, 1 insertion(+)
 create mode 100644 op1
$ 
$ 
$ git log
commit 0e74249d0c0e4cc17aada7436d8fa31b0443fce6
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:57:22 2012 +0900

    opi1
$ 
$ git show
commit 0e74249d0c0e4cc17aada7436d8fa31b0443fce6
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:57:22 2012 +0900

    opi1

diff --git a/op1 b/op1
new file mode 100644
index 0000000..c7e36a6
--- /dev/null
+++ b/op1
@@ -0,0 +1 @@
+opi1
$ 
```


### opopブランチを切ってop2、op3というファイルをつくってコミット
```
$ 
$ git branch opop
$ 
$ git checkout opop
Switched to branch 'opop'
$ 
$ git branch -a
  master
* opop
$ 
$ 
$ ls
op1
$ ls -a
.	..	.git	op1
$ 
$ cat op1 
opi1
$ 
$ 
$ echo "opi2" > op2
$ 
$ 
$ cat op2 
opi2
$ 
$ 
$ git add op2 
$ 
$ 
$ git commit -m "op2"
[opop d34324c] op2
 1 file changed, 1 insertion(+)
 create mode 100644 op2
$ 
$ 
$ git log
commit d34324c8c6937cb907b13d446ac0d343a353e9bc
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:58:35 2012 +0900

    op2

commit 0e74249d0c0e4cc17aada7436d8fa31b0443fce6
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:57:22 2012 +0900

    opi1
$ 
$ 
$ echo "opi3" > op3
$ 
$ 
$ cat op3 
opi3
$ 
$ 
$ git add op3 
$ 
$ git commit -m "op3"
[opop b3dcf89] op3
 1 file changed, 1 insertion(+)
 create mode 100644 op3
$ 
$ 
$ 
$ git log
commit b3dcf89147dfafa980159755e62879d9e154e6a1
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:59:11 2012 +0900

    op3

commit d34324c8c6937cb907b13d446ac0d343a353e9bc
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:58:35 2012 +0900

    op2

commit 0e74249d0c0e4cc17aada7436d8fa31b0443fce6
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:57:22 2012 +0900

    opi1
$ 
$ 
$ git show d34324c8c6937cb907b13d446ac0d343a353e9bc
commit d34324c8c6937cb907b13d446ac0d343a353e9bc
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:58:35 2012 +0900

    op2

diff --git a/op2 b/op2
new file mode 100644
index 0000000..a7efa24
--- /dev/null
+++ b/op2
@@ -0,0 +1 @@
+opi2
$ 
```

### masterブランチに戻ってopi2のコミットだけを反映するcherry-pick

```
$ 
$ 
$ 
$ git branch -a
  master
* opop
$ 
$ 
$ git checkout master
Switched to branch 'master'
$ 
$ 
$ git branch -a
* master
  opop
$ 
$ 
$ git log
commit 0e74249d0c0e4cc17aada7436d8fa31b0443fce6
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:57:22 2012 +0900

    opi1
$ 
$ 
$ 
$ git checrry-pick d34324c8c6937cb907b13d446ac0d343a353e9bc
git: 'checrry-pick' is not a git command. See 'git --help'.

Did you mean this?
	cherry-pick
$ 
$ git cherry-pick d34324c8c6937cb907b13d446ac0d343a353e9bc
[master f9a2f15] op2
 1 file changed, 1 insertion(+)
 create mode 100644 op2
$ 
$ git log
commit f9a2f15b304fb1f20bb02fd7eb33a822999b493a
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:58:35 2012 +0900

    op2

commit 0e74249d0c0e4cc17aada7436d8fa31b0443fce6
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:57:22 2012 +0900

    opi1
$ 
$ 
$ 
$ 
$ ls -a
.	..	.git	op1	op2
$ 
$ cat op2 
opi2
$ 
```


### masterでopi2のファイルを書き換えてopopブランチでその変更をcherry-pick

```
$ 
$ 
$ echo "op2op2" > op2 
$ 
$ 
$ 
$ git add op2
$ 
$ 
$ git commit -m "modify op2"
[master 2d42034] modify op2
 1 file changed, 1 insertion(+), 1 deletion(-)
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ git log
commit 2d4203421f027efbc158bc65ce4a9f9529cf731f
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 20:00:49 2012 +0900

    modify op2

commit f9a2f15b304fb1f20bb02fd7eb33a822999b493a
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:58:35 2012 +0900

    op2

commit 0e74249d0c0e4cc17aada7436d8fa31b0443fce6
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:57:22 2012 +0900

    opi1
$ 
$ 
$ 
$ 
$ 
$ 
$ git branch -a
* master
  opop
$ 
$ git checkout opop
Switched to branch 'opop'
$ 
$ 
$ git branch -a
  master
* opop
$ 
$ 
$ git log
commit b3dcf89147dfafa980159755e62879d9e154e6a1
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:59:11 2012 +0900

    op3

commit d34324c8c6937cb907b13d446ac0d343a353e9bc
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:58:35 2012 +0900

    op2

commit 0e74249d0c0e4cc17aada7436d8fa31b0443fce6
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:57:22 2012 +0900

    opi1
$ 
$ 
$ cat op2 
opi2
$ 
$ 
$ git checkout master
Switched to branch 'master'
$ 
$ 
$ 
$ 
$ echo "op4" > op4
$ 
$ git add op4 
$ 
$ git commit -m "op4"
[master 89813f6] op4
 1 file changed, 1 insertion(+)
 create mode 100644 op4
$ 
$ 
$ git log
commit 89813f6bd1f80f607773b0072ff02d4c5c02a40f
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 20:01:56 2012 +0900

    op4

commit 2d4203421f027efbc158bc65ce4a9f9529cf731f
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 20:00:49 2012 +0900

    modify op2

commit f9a2f15b304fb1f20bb02fd7eb33a822999b493a
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:58:35 2012 +0900

    op2

commit 0e74249d0c0e4cc17aada7436d8fa31b0443fce6
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:57:22 2012 +0900

    opi1
$ 
$ 
$ git branch -a
* master
  opop
$ 
$ git checkout opop
Switched to branch 'opop'
$ 
$ git branch -a
  master
* opop
$ 
$ 
$ git log
commit b3dcf89147dfafa980159755e62879d9e154e6a1
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:59:11 2012 +0900

    op3

commit d34324c8c6937cb907b13d446ac0d343a353e9bc
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:58:35 2012 +0900

    op2

commit 0e74249d0c0e4cc17aada7436d8fa31b0443fce6
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 19:57:22 2012 +0900

    opi1
$ 
$ 
$ git cherry-pick 2d4203421f027efbc158bc65ce4a9f9529cf731f
[opop b1a6fb6] modify op2
 1 file changed, 1 insertion(+), 1 deletion(-)
$ 
$ 
$ git diff
$ 
$ 
$ cat op2 
op2op2
$ 
$ 
$ 
$ git show
commit b1a6fb69f4444af33427a16b24ab227480688ab8
Author: kenjiskywalker <git@kenjiskywalker.org>
Date:   Sat Nov 10 20:00:49 2012 +0900

    modify op2

diff --git a/op2 b/op2
index a7efa24..fe481c3 100644
--- a/op2
+++ b/op2
@@ -1 +1 @@
-opi2
+op2op2
$ 
$ 
```