3 # Copyright (c) 2005 Linus Torvalds
4 # Copyright (c) 2006 Junio C Hamano
6 USAGE
='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-u] [--amend] [-e] [--author <author>] [[-i | -o] <path>...]'
10 git-rev-parse
--verify HEAD
>/dev
/null
2>&1 || initial_commit
=t
11 branch
=$
(GIT_DIR
="$GIT_DIR" git-symbolic-ref HEAD
)
16 unmerged_ok_if_status
=--unmerged ;;
19 unmerged_ok_if_status
= ;;
24 echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?"
28 THIS_INDEX
="$GIT_DIR/index"
29 NEXT_INDEX
="$GIT_DIR/next-index$$"
32 cp -p "$THIS_INDEX" "$NEXT_INDEX"
42 while read status name newname
49 M
) echo "# modified: $name";;
50 D
*) echo "# deleted: $name";;
51 T
) echo "# typechange: $name";;
52 C
*) echo "# copied: $name -> $newname";;
53 R
*) echo "# renamed: $name -> $newname";;
54 A
*) echo "# new file: $name";;
55 U
) echo "# unmerged: $name";;
58 printf '%s' "$trailer"
64 # We always show status for the whole tree.
67 IS_INITIAL
="$initial_commit"
71 # If we are amending the initial commit, there
73 if git-rev-parse
--verify "HEAD^1" >/dev
/null
2>&1
83 # If TMP_INDEX is defined, that means we are doing
84 # "--only" partial commit, and that index file is used
85 # to build the tree for the commit. Otherwise, if
86 # NEXT_INDEX exists, that is the index file used to
87 # make the commit. Otherwise we are using as-is commit
88 # so the regular index file is what we use to compare.
89 if test '' != "$TMP_INDEX"
91 GIT_INDEX_FILE
="$TMP_INDEX"
93 elif test -f "$NEXT_INDEX"
95 GIT_INDEX_FILE
="$NEXT_INDEX"
100 refs
/heads
/master
) ;;
101 *) echo "# On branch $branch" ;;
104 if test -z "$IS_INITIAL"
106 git-diff-index
-M --cached --name-status \
107 --diff-filter=MDTCRA
$REFERENCE |
112 report
"Updated but not checked in" "will commit"
124 report
"Updated but not checked in" "will commit"
129 git-diff-files
--name-status |
134 report
"Changed but not updated" \
135 "use git-update-index to mark for commit"
138 if test -z "$untracked_files"; then
139 option
="--directory --no-empty-directory"
141 if test -f "$GIT_DIR/info/exclude"
143 git-ls-files
-z --others $option \
144 --exclude-from="$GIT_DIR/info/exclude" \
145 --exclude-per-directory=.gitignore
147 git-ls-files
-z --others $option \
148 --exclude-per-directory=.gitignore
150 @@PERL@@
-e '$/ = "\0";
159 print "#\n# Untracked files:\n";
160 print "# (use \"git add\" to add to commit)\n";
168 if test -n "$verbose" -a -z "$IS_INITIAL"
170 git-diff-index
--cached -M -p --diff-filter=MDTCRA
$REFERENCE
172 case "$committable" in
176 echo "# No changes" ;;
178 echo "nothing to commit" ;;
187 test -z "$TMP_INDEX" || {
188 test -f "$TMP_INDEX" && rm -f "$TMP_INDEX"
193 ################################################################
194 # Command line argument parsing and sanity checking
210 only_include_assumed
=
212 while case "$#" in 0) break;; esac
215 -F|
--F|
-f|
--f|
--fi|
--fil|
--file)
216 case "$#" in 1) usage
;; esac
219 log_given
=t
$log_given
225 log_given
=t
$log_given
226 logfile
=`expr "z$1" : 'z-[Ff]\(.*\)'`
229 --F=*|
--f=*|
--fi=*|
--fil=*|
--file=*)
231 log_given
=t
$log_given
232 logfile
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
239 --au=*|
--aut=*|
--auth=*|
--autho=*|
--author=*)
240 force_author
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
243 --au|
--aut|
--auth|
--autho|
--author)
244 case "$#" in 1) usage
;; esac
249 -e|
--e|
--ed|
--edi|
--edit)
253 -i|
--i|
--in|
--inc|
--incl|
--inclu|
--includ|
--include)
257 -o|
--o|
--on|
--onl|
--only)
261 -m|
--m|
--me|
--mes|
--mess|
--messa|
--messag|
--message)
262 case "$#" in 1) usage
;; esac
264 log_given
=m
$log_given
265 if test "$log_message" = ''
269 log_message
="$log_message
277 log_given
=m
$log_given
278 if test "$log_message" = ''
280 log_message
=`expr "z$1" : 'z-m\(.*\)'`
282 log_message
="$log_message
284 `expr "z
$1" : 'z-m\(.*\)'`"
289 --m=*|
--me=*|
--mes=*|
--mess=*|
--messa=*|
--messag=*|
--message=*)
290 log_given
=m
$log_given
291 if test "$log_message" = ''
293 log_message
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
295 log_message
="$log_message
297 `expr "z
$1" : 'zq-[^=]*=\(.*\)'`"
302 -n|
--n|
--no|
--no-|
--no-v|
--no-ve|
--no-ver|
--no-veri|
--no-verif|
--no-verify)
306 --a|
--am|
--ame|
--amen|
--amend)
308 log_given
=t
$log_given
313 case "$#" in 1) usage
;; esac
315 log_given
=t
$log_given
320 --ree=*|
--reed=*|
--reedi=*|
--reedit=*|
--reedit-=*|
--reedit-m=*|\
321 --reedit-me=*|
--reedit-mes=*|
--reedit-mess=*|
--reedit-messa=*|\
322 --reedit-messag=*|
--reedit-message=*)
323 log_given
=t
$log_given
324 use_commit
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
328 --ree|
--reed|
--reedi|
--reedit|
--reedit-|
--reedit-m|
--reedit-me|\
329 --reedit-mes|
--reedit-mess|
--reedit-messa|
--reedit-messag|
--reedit-message)
330 case "$#" in 1) usage
;; esac
332 log_given
=t
$log_given
338 case "$#" in 1) usage
;; esac
340 log_given
=t
$log_given
345 --reu=*|
--reus=*|
--reuse=*|
--reuse-=*|
--reuse-m=*|
--reuse-me=*|\
346 --reuse-mes=*|
--reuse-mess=*|
--reuse-messa=*|
--reuse-messag=*|\
348 log_given
=t
$log_given
349 use_commit
=`expr "z$1" : 'z-[^=]*=\(.*\)'`
353 --reu|
--reus|
--reuse|
--reuse-|
--reuse-m|
--reuse-me|
--reuse-mes|\
354 --reuse-mess|
--reuse-messa|
--reuse-messag|
--reuse-message)
355 case "$#" in 1) usage
;; esac
357 log_given
=t
$log_given
362 -s|
--s|
--si|
--sig|
--sign|
--signo|
--signof|
--signoff)
366 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
370 -u|
--u|
--un|
--unt|
--untr|
--untra|
--untrac|
--untrack|
--untracke|
--untracked|\
371 --untracked-|
--untracked-f|
--untracked-fi|
--untracked-fil|
--untracked-file|\
388 case "$edit_flag" in t
) no_edit
= ;; esac
390 ################################################################
391 # Sanity check options
393 case "$amend,$initial_commit" in
395 die
"You do not have anything to amend." ;;
397 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
398 die
"You are in the middle of a merge -- cannot amend."
404 die
"Only one of -c/-C/-F can be used." ;;
406 die
"Option -m cannot be combined with -c/-C/-F." ;;
409 case "$#,$also,$only,$amend" in
411 die
"Only one of --include/--only can be used." ;;
413 die
"No paths with --include/--only does not make sense." ;;
415 only_include_assumed
="# Clever... amending the last one with dirty index." ;;
419 only_include_assumed
="# Explicit paths specified without -i nor -o; assuming --only paths..."
424 case "$all,$also,$#" in
426 die
"Cannot use -a and -i at the same time." ;;
428 die
"Paths with -a does not make sense." ;;
430 die
"No paths with -i does not make sense." ;;
433 ################################################################
434 # Prepare index to have a tree to be committed
436 TOP
=`git-rev-parse --show-cdup`
447 GIT_INDEX_FILE
="$NEXT_INDEX"
448 export GIT_INDEX_FILE
449 git-diff-files
--name-only -z |
450 git-update-index
--remove -z --stdin
455 git-ls-files
--error-unmatch -- "$@" >/dev
/null ||
exit
457 git-diff-files
--name-only -z -- "$@" |
460 GIT_INDEX_FILE
="$NEXT_INDEX"
461 export GIT_INDEX_FILE
462 git-update-index
--remove -z --stdin
470 if test -f "$GIT_DIR/MERGE_HEAD"
472 refuse_partial
"Cannot do a partial commit during a merge."
474 TMP_INDEX
="$GIT_DIR/tmp-index$$"
475 if test -z "$initial_commit"
477 # make sure index is clean at the specified paths, or
478 # they are additions.
479 dirty_in_index
=`git-diff-index --cached --name-status \
480 --diff-filter=DMTU HEAD -- "$@"`
481 test -z "$dirty_in_index" ||
482 refuse_partial
"Different in index and the last commit:
485 commit_only
=`git-ls-files --error-unmatch -- "$@"` ||
exit
487 # Build the temporary index and update the real index
489 if test -z "$initial_commit"
491 cp "$THIS_INDEX" "$TMP_INDEX"
492 GIT_INDEX_FILE
="$TMP_INDEX" git-read-tree
-m HEAD
497 echo "$commit_only" |
498 GIT_INDEX_FILE
="$TMP_INDEX" \
499 git-update-index
--add --remove --stdin &&
502 echo "$commit_only" |
504 GIT_INDEX_FILE
="$NEXT_INDEX"
505 export GIT_INDEX_FILE
506 git-update-index
--remove --stdin
513 ################################################################
514 # If we do as-is commit, the index file will be THIS_INDEX,
515 # otherwise NEXT_INDEX after we make this commit. We leave
516 # the index as is if we abort.
518 if test -f "$NEXT_INDEX"
520 USE_INDEX
="$NEXT_INDEX"
522 USE_INDEX
="$THIS_INDEX"
525 GIT_INDEX_FILE
="$USE_INDEX" \
526 git-update-index
-q $unmerged_ok_if_status --refresh ||
exit
528 ################################################################
529 # If the request is status, just show it and exit.
537 ################################################################
538 # Grab commit message, write out tree and make commit.
540 if test t
= "$verify" && test -x "$GIT_DIR"/hooks
/pre-commit
544 GIT_INDEX_FILE
="$TMP_INDEX" "$GIT_DIR"/hooks
/pre-commit
546 GIT_INDEX_FILE
="$USE_INDEX" "$GIT_DIR"/hooks
/pre-commit
550 if test "$log_message" != ''
553 elif test "$logfile" != ""
555 if test "$logfile" = -
558 echo >&2 "(reading log message from standard input)"
563 elif test "$use_commit" != ""
565 git-cat-file commit
"$use_commit" |
sed -e '1,/^$/d'
566 elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG"
568 cat "$GIT_DIR/MERGE_MSG"
569 elif test -f "$GIT_DIR/SQUASH_MSG"
571 cat "$GIT_DIR/SQUASH_MSG"
572 fi | git-stripspace
>"$GIT_DIR"/COMMIT_EDITMSG
578 git-var GIT_COMMITTER_IDENT |
sed -e '
582 } >>"$GIT_DIR"/COMMIT_EDITMSG
586 if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then
588 echo "# It looks like you may be committing a MERGE."
589 echo "# If this is not correct, please remove the file"
590 echo "# $GIT_DIR/MERGE_HEAD"
591 echo "# and try again"
593 fi >>"$GIT_DIR"/COMMIT_EDITMSG
596 if test '' != "$force_author"
598 GIT_AUTHOR_NAME
=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` &&
599 GIT_AUTHOR_EMAIL
=`expr "z$force_author" : '.*\(<.*\)'` &&
600 test '' != "$GIT_AUTHOR_NAME" &&
601 test '' != "$GIT_AUTHOR_EMAIL" ||
602 die
"malformed --author parameter"
603 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
604 elif test '' != "$use_commit"
608 s/'\''/'\''\\'\'\''/g
610 s/^author \([^<]*\) <[^>]*> .*$/\1/
612 s
/.
*/GIT_AUTHOR_NAME
='\''&'\''/p
615 s
/^author
[^
<]* <\
([^
>]*\
)> .
*$
/\
1/
617 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
620 s/^author [^<]* <[^>]*> \(.*\)$/\1/
622 s
/.
*/GIT_AUTHOR_DATE
='\''&'\''/p
627 set_author_env=`git-cat-file commit "$use_commit" |
628 LANG=C LC_ALL=C sed -ne "$pick_author_script"`
629 eval "$set_author_env"
630 export GIT_AUTHOR_NAME
631 export GIT_AUTHOR_EMAIL
632 export GIT_AUTHOR_DATE
636 if test -z "$initial_commit"
639 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
640 rloga='commit
(merge
)'
641 PARENTS="-p HEAD "`sed -e 's
/^
/-p /' "$GIT_DIR/MERGE_HEAD"`
642 elif test -n "$amend"; then
643 rloga='commit
(amend
)'
644 PARENTS=$(git-cat-file commit HEAD |
645 sed -n -e '/^$
/q
' -e 's
/^parent
/-p /p
')
647 current=$(git-rev-parse --verify HEAD)
649 if [ -z "$(git-ls-files)" ]; then
650 echo >&2 Nothing to commit
655 rloga='commit
(initial
)'
658 if test -z "$no_edit"
662 echo "# Please enter the commit message for your changes."
663 echo "# (Comment lines starting with '#' will not be included)"
664 test -z "$only_include_assumed" ||
echo "$only_include_assumed"
666 } >>"$GIT_DIR"/COMMIT_EDITMSG
668 # we need to check if there is anything to commit
669 run_status
>/dev
/null
671 if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ]
673 rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
680 case "${VISUAL:-$EDITOR},$TERM" in
682 echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined."
683 echo >&2 "Please supply the commit log message using either"
684 echo >&2 "-m or -F option. A boilerplate log message has"
685 echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG"
689 git-var GIT_AUTHOR_IDENT
> /dev
/null || die
690 git-var GIT_COMMITTER_IDENT
> /dev
/null || die
691 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG"
697 if test -x "$GIT_DIR"/hooks
/commit-msg
699 "$GIT_DIR"/hooks
/commit-msg
"$GIT_DIR"/COMMIT_EDITMSG ||
exit
703 if test -z "$no_edit"
711 ' "$GIT_DIR"/COMMIT_EDITMSG
713 cat "$GIT_DIR"/COMMIT_EDITMSG
715 git-stripspace
>"$GIT_DIR"/COMMIT_MSG
717 if cnt
=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG |
722 if test -z "$TMP_INDEX"
724 tree
=$
(GIT_INDEX_FILE
="$USE_INDEX" git-write-tree
)
726 tree
=$
(GIT_INDEX_FILE
="$TMP_INDEX" git-write-tree
) &&
729 commit
=$
(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree
$tree $PARENTS) &&
730 rlogm
=$
(sed -e 1q
"$GIT_DIR"/COMMIT_MSG
) &&
731 git-update-ref
-m "$rloga: $rlogm" HEAD
$commit $current &&
732 rm -f -- "$GIT_DIR/MERGE_HEAD" &&
733 if test -f "$NEXT_INDEX"
735 mv "$NEXT_INDEX" "$THIS_INDEX"
740 echo >&2 "* no commit message? aborting commit."
744 rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
745 if test -d "$GIT_DIR/rr-cache"
750 if test -x "$GIT_DIR"/hooks
/post-commit
&& test "$ret" = 0
752 "$GIT_DIR"/hooks
/post-commit