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 set_reflog_action "$me"
59 test "$me,$replay" = "revert,t" && usage
63 # We do not intend to commit immediately. We just want to
64 # merge the differences in.
65 head=$(git-write-tree) ||
66 die "Your index file is unmerged."
69 head=$(git-rev-parse --verify HEAD) ||
70 die "You do not have a valid HEAD"
71 files=$(git-diff-index --cached --name-only $head) || exit
73 die "Dirty index: cannot $me (dirty: $files)"
78 rev=$(git-rev-parse --verify "$@") &&
79 commit=$(git-rev-parse --verify "$rev^0") ||
80 die "Not a single commit $@"
81 prev=$(git-rev-parse --verify "$commit^1" 2>/dev/null) ||
82 die "Cannot run $me a root commit"
83 git-rev-parse --verify "$commit^2" >/dev/null 2>&1 &&
84 die "Cannot run $me a multi-parent commit."
86 encoding=$(git config i18n.commitencoding || echo UTF-8)
88 # "commit" is an existing commit. We would want to apply
89 # the difference it introduces since its first parent "prev"
90 # on top of the current HEAD if we are cherry-pick. Or the
91 # reverse of it if we are revert.
95 git show -s --pretty=oneline --encoding="$encoding" $commit |
101 echo "This reverts commit $commit."
102 test "$rev" = "$commit" ||
103 echo "(original 'git revert' arguments: $@)"
104 base=$commit next=$prev
110 s/'\''/'\''\\'\'\''/g
112 s/^author \([^<]*\) <[^>]*> .*$/\1/
114 s/.*/GIT_AUTHOR_NAME='\''&'\''/p
117 s/^author [^<]* <\([^>]*\)> .*$/\1/
119 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
122 s/^author [^<]* <[^>]*> \(.*\)$/\1/
124 s/.*/GIT_AUTHOR_DATE='\''&'\''/p
129 logmsg=`git show -s --pretty=raw --encoding="$encoding" "$commit"`
130 set_author_env=`echo "$logmsg" |
131 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
132 eval "$set_author_env"
133 export GIT_AUTHOR_NAME
134 export GIT_AUTHOR_EMAIL
135 export GIT_AUTHOR_DATE
138 sed -e '1,/^$/d' -e 's/^ //'
141 echo "(cherry picked from commit $commit)"
142 test "$rev" = "$commit" ||
143 echo "(original 'git cherry-pick' arguments: $@)"
146 base=$prev next=$commit
151 eval GITHEAD_$head=HEAD
152 eval GITHEAD_$next='`git show -s \
153 --pretty=oneline --encoding="$encoding" "$commit" |
154 sed -e "s/^[^ ]* //"`'
155 export GITHEAD_$head GITHEAD_$next
157 # This three way merge is an interesting one. We are at
158 # $head, and would want to apply the change between $commit
159 # and $prev on top of us (when reverting), or the change between
160 # $prev and $commit on top of us (when cherry-picking or replaying).
162 git-merge-recursive $base -- $head $next &&
163 result=$(git-write-tree 2>/dev/null) || {
164 mv -f .msg "$GIT_DIR/MERGE_MSG"
169 git ls-files --unmerged |
170 sed -e 's/^[^ ]* / /' |
172 } >>"$GIT_DIR/MERGE_MSG"
173 echo >&2 "Automatic $me failed. After resolving the conflicts,"
174 echo >&2 "mark the corrected paths with 'git-add <paths>'"
175 echo >&2 "and commit the result."
178 echo >&2 "You may choose to use the following when making"
179 echo >&2 "the commit:"
180 echo >&2 "$set_author_env"
185 # If we are cherry-pick, and if the merge did not result in
186 # hand-editing, we will hit this commit and inherit the original
187 # author date and name.
188 # If we are revert, or if our cherry-pick results in a hand merge,
189 # we had better say that the current user is responsible for that.
193 git-commit -n -F .msg $edit