3 # Copyright (c) 2005 Linus Torvalds
4 # Copyright (c) 2005 Junio C Hamano
11 USAGE
='[--edit | --no-edit] [-n] <commit-ish>' ;;
15 USAGE
='[--edit] [-n] [-r] [-x] <commit-ish>' ;;
17 die
"What are you talking about?" ;;
22 while case "$#" in 0) break ;; esac
25 -n|
--n|
--no|
--no-|
--no-c|
--no-co|
--no-com|
--no-comm|\
26 --no-commi|
--no-commit)
29 -e|
--e|
--ed|
--edi|
--edit)
32 --n|
--no|
--no-|
--no-e|
--no-ed|
--no-edi|
--no-edit)
37 -x|
--i-really-want-to-expose-my-private-commit-object-name)
50 test "$me,$replay" = "revert,t" && usage
54 # We do not intend to commit immediately. We just want to
55 # merge the differences in.
56 head=$
(git-write-tree
) ||
57 die
"Your index file is unmerged."
60 head=$
(git-rev-parse
--verify HEAD
) ||
61 die
"You do not have a valid HEAD"
62 files
=$
(git-diff-index
--cached --name-only $head) ||
exit
64 die
"Dirty index: cannot $me (dirty: $files)"
69 rev=$
(git-rev-parse
--verify "$@") &&
70 commit
=$
(git-rev-parse
--verify "$rev^0") ||
71 die
"Not a single commit $@"
72 prev
=$
(git-rev-parse
--verify "$commit^1" 2>/dev
/null
) ||
73 die
"Cannot run $me a root commit"
74 git-rev-parse
--verify "$commit^2" >/dev
/null
2>&1 &&
75 die
"Cannot run $me a multi-parent commit."
77 # "commit" is an existing commit. We would want to apply
78 # the difference it introduces since its first parent "prev"
79 # on top of the current HEAD if we are cherry-pick. Or the
80 # reverse of it if we are revert.
84 git-rev-list
--pretty=oneline
--max-count=1 $commit |
89 echo "This reverts commit $commit."
90 test "$rev" = "$commit" ||
91 echo "(original 'git revert' arguments: $@)"
92 base
=$commit next
=$prev
100 s/^author \([^<]*\) <[^>]*> .*$/\1/
102 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
105 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
107 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
110 s/^author [^<]* <[^>]*> \(.*\)$/\1/
112 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
116 set_author_env=`git-cat-file commit "$commit" |
117 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
118 eval "$set_author_env"
119 export GIT_AUTHOR_NAME
120 export GIT_AUTHOR_EMAIL
121 export GIT_AUTHOR_DATE
123 git-cat-file commit $commit | sed -e '1,/^$
/d
'
126 echo "(cherry picked from commit $commit)"
127 test "$rev" = "$commit" ||
128 echo "(original 'git cherry-pick
' arguments: $@)"
131 base=$prev next=$commit
136 # This three way merge is an interesting one. We are at
137 # $head, and would want to apply the change between $commit
138 # and $prev on top of us (when reverting), or the change between
139 # $prev and $commit on top of us (when cherry-picking or replaying).
141 echo >&2 "First trying simple merge strategy to $me."
142 git-read-tree -m -u --aggressive $base $head $next &&
143 result=$(git-write-tree 2>/dev/null) || {
144 echo >&2 "Simple $me fails; trying Automatic $me."
145 git-merge-index -o git-merge-one-file -a || {
146 echo >&2 "Automatic $me failed. After resolving the conflicts,"
147 echo >&2 "mark the corrected paths with 'git-update-index
<paths
>'"
148 echo >&2 "and commit with 'git commit
-F .msg
'"
151 echo >&2 "You may choose to use the following when making"
152 echo >&2 "the commit:"
153 echo >&2 "$set_author_env"
157 result=$(git-write-tree) || exit
159 echo >&2 "Finished one $me."
161 # If we are cherry-pick, and if the merge did not result in
162 # hand-editing, we will hit this commit and inherit the original
163 # author date and name.
164 # If we are revert, or if our cherry-pick results in a hand merge,
165 # we had better say that the current user is responsible for that.
169 git-commit -n -F .msg $edit