3 # Copyright (c) 2005 Linus Torvalds
4 # Copyright (c) 2005 Junio C Hamano
12 USAGE
='[--edit | --no-edit] [-n] <commit-ish>' ;;
17 USAGE
='[--edit] [-n] [-r] [-x] <commit-ish>' ;;
19 echo >&2 "What are you talking about?"
23 SUBDIRECTORY_OK
=Yes
;# we will cd up
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 -e|
--e|
--ed|
--edi|
--edit)
39 --n|
--no|
--no-|
--no-e|
--no-ed|
--no-edi|
--no-edit)
44 -x|
--i-really-want-to-expose-my-private-commit-object-name)
57 test "$me,$replay" = "revert,t" && usage
61 # We do not intend to commit immediately. We just want to
62 # merge the differences in.
63 head=$
(git-write-tree
) ||
64 die
"Your index file is unmerged."
67 head=$
(git-rev-parse
--verify HEAD
) ||
68 die
"You do not have a valid HEAD"
69 files
=$
(git-diff-index
--cached --name-only $head) ||
exit
71 die
"Dirty index: cannot $me (dirty: $files)"
76 rev=$
(git-rev-parse
--verify "$@") &&
77 commit
=$
(git-rev-parse
--verify "$rev^0") ||
78 die
"Not a single commit $@"
79 prev
=$
(git-rev-parse
--verify "$commit^1" 2>/dev
/null
) ||
80 die
"Cannot run $me a root commit"
81 git-rev-parse
--verify "$commit^2" >/dev
/null
2>&1 &&
82 die
"Cannot run $me a multi-parent commit."
84 encoding
=$
(git repo-config i18n.commitencoding ||
echo UTF-8
)
86 # "commit" is an existing commit. We would want to apply
87 # the difference it introduces since its first parent "prev"
88 # on top of the current HEAD if we are cherry-pick. Or the
89 # reverse of it if we are revert.
93 git show
-s --pretty=oneline
--encoding="$encoding" $commit |
99 echo "This reverts commit $commit."
100 test "$rev" = "$commit" ||
101 echo "(original 'git revert' arguments: $@)"
102 base
=$commit next
=$prev
108 s/'\''/'\''\\'\'\''/g
110 s/^author \([^<]*\) <[^>]*> .*$/\1/
112 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
115 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
117 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
120 s/^author [^<]* <[^>]*> \(.*\)$/\1/
122 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
127 logmsg=`git show -s --pretty=raw --encoding="$encoding" "$commit"`
128 set_author_env=`echo "$logmsg" |
129 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
130 eval "$set_author_env"
131 export GIT_AUTHOR_NAME
132 export GIT_AUTHOR_EMAIL
133 export GIT_AUTHOR_DATE
136 sed -e '1,/^$
/d
' -e 's
/^
//'
139 echo "(cherry picked from commit $commit)"
140 test "$rev" = "$commit" ||
141 echo "(original 'git cherry-pick
' arguments: $@)"
144 base=$prev next=$commit
149 # This three way merge is an interesting one. We are at
150 # $head, and would want to apply the change between $commit
151 # and $prev on top of us (when reverting), or the change between
152 # $prev and $commit on top of us (when cherry-picking or replaying).
154 echo >&2 "First trying simple merge strategy to $me."
155 git-read-tree -m -u --aggressive $base $head $next &&
156 result=$(git-write-tree 2>/dev/null) || {
157 echo >&2 "Simple $me fails; trying Automatic $me."
158 git-merge-index -o git-merge-one-file -a || {
159 mv -f .msg "$GIT_DIR/MERGE_MSG"
164 git ls-files --unmerged |
165 sed -e 's
/^
[^
]* / /' |
167 } >>"$GIT_DIR/MERGE_MSG"
168 echo >&2 "Automatic $me failed. After resolving the conflicts,"
169 echo >&2 "mark the corrected paths with 'git-add
<paths
>'"
170 echo >&2 "and commit the result."
173 echo >&2 "You may choose to use the following when making"
174 echo >&2 "the commit:"
175 echo >&2 "$set_author_env"
179 result=$(git-write-tree) || exit
181 echo >&2 "Finished one $me."
183 # If we are cherry-pick, and if the merge did not result in
184 # hand-editing, we will hit this commit and inherit the original
185 # author date and name.
186 # If we are revert, or if our cherry-pick results in a hand merge,
187 # we had better say that the current user is responsible for that.
191 git-commit -n -F .msg $edit