3 # Copyright (c) 2005 Linus Torvalds
4 # Copyright (c) 2005 Junio C Hamano
6 . git-sh-setup || die
"Not a git archive"
14 die
"What are ou talking about?" ;;
20 die
"usage git $me [-n] [-r] <commit-ish>"
23 die
"usage git $me [-n] <commit-ish>"
29 while case "$#" in 0) break ;; esac
32 -n|
--n|
--no|
--no-|
--no-c|
--no-co|
--no-com|
--no-comm|\
33 --no-commi|
--no-commit)
36 -r|
--r|
--re|
--rep|
--repl|
--repla|
--replay)
49 test "$me,$replay" = "revert,t" && usage
53 # We do not intend to commit immediately. We just want to
54 # merge the differences in.
55 head=$
(git-write-tree
) ||
56 die
"Your index file is unmerged."
59 check_clean_tree || die
"Cannot run $me from a dirty tree."
60 head=$
(git-rev-parse
--verify HEAD
) ||
61 die
"You do not have a valid HEAD"
65 rev=$
(git-rev-parse
--verify "$@") &&
66 commit
=$
(git-rev-parse
--verify "$rev^0") ||
67 die
"Not a single commit $@"
68 prev
=$
(git-rev-parse
--verify "$commit^1" 2>/dev
/null
) ||
69 die
"Cannot run $me a root commit"
70 git-rev-parse
--verify "$commit^2" >/dev
/null
2>&1 &&
71 die
"Cannot run $me a multi-parent commit."
73 # "commit" is an existing commit. We would want to apply
74 # the difference it introduces since its first parent "prev"
75 # on top of the current HEAD if we are cherry-pick. Or the
76 # reverse of it if we are revert.
80 git-rev-list
--pretty=oneline
--max-count=1 $commit |
85 echo "This reverts $commit commit."
86 test "$rev" = "$commit" ||
87 echo "(original 'git revert' arguments: $@)"
88 base
=$commit next
=$prev
95 s/^author \([^<]*\) <[^>]*> .*$/\1/
97 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
100 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
102 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
105 s/^author [^<]* <[^>]*> \(.*\)$/\1/
107 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
111 set_author_env=`git-cat-file commit "$commit" |
112 sed -ne "$pick_author_script"`
113 eval "$set_author_env"
114 export GIT_AUTHOR_NAME
115 export GIT_AUTHOR_EMAIL
116 export GIT_AUTHOR_DATE
118 git-cat-file commit $commit | sed -e '1,/^$
/d
'
121 echo "(cherry picked from $commit commit)"
122 test "$rev" = "$commit" ||
123 echo "(original 'git cherry-pick
' arguments: $@)"
126 base=$prev next=$commit
131 # This three way merge is an interesting one. We are at
132 # $head, and would want to apply the change between $commit
133 # and $prev on top of us (when reverting), or the change between
134 # $prev and $commit on top of us (when cherry-picking or replaying).
136 echo >&2 "First trying simple merge strategy to $me."
137 git-read-tree -m -u $base $head $next &&
138 result=$(git-write-tree 2>/dev/null) || {
139 echo >&2 "Simple $me fails; trying Automatic $me."
140 git-merge-index -o git-merge-one-file -a || {
141 echo >&2 "Automatic $me failed. After fixing it up,"
142 echo >&2 "you can use \"git commit -F .msg\""
145 echo >&2 "You may choose to use the following when making"
146 echo >&2 "the commit:"
147 echo >&2 "$set_author_env"
151 result=$(git-write-tree) || exit
153 echo >&2 "Finished one $me."
155 # If we are cherry-pick, and if the merge did not result in
156 # hand-editing, we will hit this commit and inherit the original
157 # author date and name.
158 # If we are revert, or if our cherry-pick results in a hand merge,
159 # we had better say that the current user is responsible for that.
163 git-commit -n -F .msg