Commit | Line | Data |
---|---|---|
215a7ad1 JH |
1 | git-cherry-pick(1) |
2 | ================== | |
de2b82c6 JH |
3 | |
4 | NAME | |
5 | ---- | |
89d32d33 | 6 | git-cherry-pick - Apply the changes introduced by some existing commits |
de2b82c6 JH |
7 | |
8 | SYNOPSIS | |
9 | -------- | |
89d32d33 | 10 | 'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>... |
de2b82c6 JH |
11 | |
12 | DESCRIPTION | |
13 | ----------- | |
89d32d33 CC |
14 | |
15 | Given one or more existing commits, apply the change each one | |
16 | introduces, recording a new commit for each. This requires your | |
17 | working tree to be clean (no modifications from the HEAD commit). | |
de2b82c6 | 18 | |
d7e5c0cb JS |
19 | When it is not obvious how to apply a change, the following |
20 | happens: | |
21 | ||
22 | 1. The current branch and `HEAD` pointer stay at the last commit | |
23 | successfully made. | |
24 | 2. The `CHERRY_PICK_HEAD` ref is set to point at the commit that | |
25 | introduced the change that is difficult to apply. | |
26 | 3. Paths in which the change applied cleanly are updated both | |
27 | in the index file and in your working tree. | |
28 | 4. For conflicting paths, the index file records up to three | |
29 | versions, as described in the "TRUE MERGE" section of | |
30 | linkgit:git-merge[1]. The working tree files will include | |
31 | a description of the conflict bracketed by the usual | |
32 | conflict markers `<<<<<<<` and `>>>>>>>`. | |
33 | 5. No other modifications are made. | |
34 | ||
35 | See linkgit:git-merge[1] for some hints on resolving such | |
36 | conflicts. | |
37 | ||
de2b82c6 JH |
38 | OPTIONS |
39 | ------- | |
89d32d33 CC |
40 | <commit>...:: |
41 | Commits to cherry-pick. | |
f028cdae | 42 | For a more complete list of ways to spell commits, see |
9d83e382 | 43 | linkgit:gitrevisions[7]. |
89d32d33 CC |
44 | Sets of commits can be passed but no traversal is done by |
45 | default, as if the '--no-walk' option was specified, see | |
46 | linkgit:git-rev-list[1]. | |
de2b82c6 | 47 | |
3240240f SB |
48 | -e:: |
49 | --edit:: | |
0b444cdb | 50 | With this option, 'git cherry-pick' will let you edit the commit |
233808db | 51 | message prior to committing. |
8bf14d6e | 52 | |
abd6970a | 53 | -x:: |
dd8175f8 RW |
54 | When recording the commit, append to the original commit |
55 | message a note that indicates which commit this change | |
56 | was cherry-picked from. Append the note only for cherry | |
57 | picks without conflicts. Do not use this option if | |
58 | you are cherry-picking from your private branch because | |
59 | the information is useless to the recipient. If on the | |
abd6970a JH |
60 | other hand you are cherry-picking between two publicly |
61 | visible branches (e.g. backporting a fix to a | |
62 | maintenance branch for an older release from a | |
63 | development branch), adding this information can be | |
64 | useful. | |
65 | ||
6b04600a | 66 | -r:: |
abd6970a JH |
67 | It used to be that the command defaulted to do `-x` |
68 | described above, and `-r` was to disable it. Now the | |
69 | default is not to do `-x` so this option is a no-op. | |
de2b82c6 | 70 | |
3240240f SB |
71 | -m parent-number:: |
72 | --mainline parent-number:: | |
84989bd8 | 73 | Usually you cannot cherry-pick a merge because you do not know which |
7791ecbc JH |
74 | side of the merge should be considered the mainline. This |
75 | option specifies the parent number (starting from 1) of | |
76 | the mainline and allows cherry-pick to replay the change | |
77 | relative to the specified parent. | |
78 | ||
3240240f SB |
79 | -n:: |
80 | --no-commit:: | |
89d32d33 CC |
81 | Usually the command automatically creates a sequence of commits. |
82 | This flag applies the changes necessary to cherry-pick | |
83 | each named commit to your working tree and the index, | |
84 | without making any commit. In addition, when this | |
37a7744f BD |
85 | option is used, your index does not have to match the |
86 | HEAD commit. The cherry-pick is done against the | |
8bd867ee | 87 | beginning state of your index. |
df8baa42 JF |
88 | + |
89 | This is useful when cherry-picking more than one commits' | |
8bd867ee | 90 | effect to your index in a row. |
de2b82c6 | 91 | |
3240240f SB |
92 | -s:: |
93 | --signoff:: | |
cfd9c277 DM |
94 | Add Signed-off-by line at the end of the commit message. |
95 | ||
ab7e63e8 CC |
96 | --ff:: |
97 | If the current HEAD is the same as the parent of the | |
98 | cherry-pick'ed commit, then a fast forward to this commit will | |
99 | be performed. | |
de2b82c6 | 100 | |
89d32d33 CC |
101 | EXAMPLES |
102 | -------- | |
103 | git cherry-pick master:: | |
104 | ||
105 | Apply the change introduced by the commit at the tip of the | |
106 | master branch and create a new commit with this change. | |
107 | ||
108 | git cherry-pick ..master:: | |
109 | git cherry-pick ^HEAD master:: | |
110 | ||
111 | Apply the changes introduced by all commits that are ancestors | |
112 | of master but not of HEAD to produce new commits. | |
113 | ||
be1b0558 | 114 | git cherry-pick master{tilde}4 master{tilde}2:: |
89d32d33 CC |
115 | |
116 | Apply the changes introduced by the fifth and third last | |
117 | commits pointed to by master and create 2 new commits with | |
118 | these changes. | |
119 | ||
120 | git cherry-pick -n master~1 next:: | |
121 | ||
122 | Apply to the working tree and the index the changes introduced | |
123 | by the second last commit pointed to by master and by the last | |
124 | commit pointed to by next, but do not create any commit with | |
125 | these changes. | |
126 | ||
127 | git cherry-pick --ff ..next:: | |
128 | ||
129 | If history is linear and HEAD is an ancestor of next, update | |
130 | the working tree and advance the HEAD pointer to match next. | |
131 | Otherwise, apply the changes introduced by those commits that | |
132 | are in next but not HEAD to the current branch, creating a new | |
133 | commit for each new change. | |
134 | ||
f873a273 CC |
135 | git rev-list --reverse master \-- README | git cherry-pick -n --stdin:: |
136 | ||
137 | Apply the changes introduced by all commits on the master | |
138 | branch that touched README to the working tree and index, | |
139 | so the result can be inspected and made into a single new | |
140 | commit if suitable. | |
141 | ||
de2b82c6 JH |
142 | Author |
143 | ------ | |
59eb68aa | 144 | Written by Junio C Hamano <gitster@pobox.com> |
de2b82c6 JH |
145 | |
146 | Documentation | |
147 | -------------- | |
148 | Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>. | |
149 | ||
89d32d33 CC |
150 | SEE ALSO |
151 | -------- | |
152 | linkgit:git-revert[1] | |
153 | ||
de2b82c6 JH |
154 | GIT |
155 | --- | |
9e1f0a85 | 156 | Part of the linkgit:git[1] suite |