Skip to content

Commit

Permalink
git-commit: revamp the git-commit semantics.
Browse files Browse the repository at this point in the history
 - "git commit" without _any_ parameter keeps the traditional
   behaviour.  It commits the current index.

   We commit the whole index even when this form is run from a
   subdirectory.

 - "git commit --include paths..." (or "git commit -i paths...")
   is equivalent to:

   	git update-index --remove paths...
        git commit

 - "git commit paths..." acquires a new semantics.  This is an
   incompatible change that needs user training, which I am
   still a bit reluctant to swallow, but enough people seem to
   have complained that it is confusing to them.  It

   1. refuses to run if $GIT_DIR/MERGE_HEAD exists, and reminds
      trained git users that the traditional semantics now needs
      -i flag.

   2. refuses to run if named paths... are different in HEAD and
      the index (ditto about reminding).  Added paths are OK.

   3. reads HEAD commit into a temporary index file.

   4. updates named paths... from the working tree in this
      temporary index.

   5. does the same updates of the paths... from the working
      tree to the real index.

   6. makes a commit using the temporary index that has the
      current HEAD as the parent, and updates the HEAD with this
      new commit.

 - "git commit --all" can run from a subdirectory, but it updates
   the index with all the modified files and does a whole tree
   commit.

 - In all cases, when the command decides not to create a new
   commit, the index is left as it was before the command is
   run.  This means that the two "git diff" in the following
   sequence:

       $ git diff
       $ git commit -a
       $ git diff

   would show the same diff if you abort the commit process by
   making the commit log message empty.

This commit also introduces much requested --author option.

	$ git commit --author 'A U Thor <author@example.com>'

Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Junio C Hamano committed Feb 7, 2006
1 parent 8389b52 commit 130fcca
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 122 deletions.
6 changes: 3 additions & 3 deletions Documentation/core-tutorial.txt
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ that branch, and do some work there.
------------------------------------------------
$ git checkout mybranch
$ echo "Work, work, work" >>hello
$ git commit -m 'Some work.' hello
$ git commit -m 'Some work.' -i hello
------------------------------------------------

Here, we just added another line to `hello`, and we used a shorthand for
Expand All @@ -877,7 +877,7 @@ hasn't happened in the `master` branch at all. Then do
------------
$ echo "Play, play, play" >>hello
$ echo "Lots of fun" >>example
$ git commit -m 'Some fun.' hello example
$ git commit -m 'Some fun.' -i hello example
------------

since the master branch is obviously in a much better mood.
Expand Down Expand Up @@ -942,7 +942,7 @@ Work, work, work
and once you're happy with your manual merge, just do a

------------
$ git commit hello
$ git commit -i hello
------------

which will very loudly warn you that you're now committing a merge
Expand Down
61 changes: 57 additions & 4 deletions Documentation/git-commit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ git-commit - Record your changes
SYNOPSIS
--------
[verse]
'git-commit' [-a] [-s] [-v] [(-c | -C) <commit> | -F <file> | -m <msg>]
[-e] [--] <file>...
'git-commit' [-a] [-i] [-s] [-v] [(-c | -C) <commit> | -F <file> | -m <msg>]
[-e] [--author <author>] [--] <file>...

DESCRIPTION
-----------
Expand Down Expand Up @@ -40,6 +40,10 @@ OPTIONS
Take the commit message from the given file. Use '-' to
read the message from the standard input.

--author <author>::
Override the author name used in the commit. Use
`A U Thor <author@example.com>` format.

-m <msg>::
Use the given <msg> as the commit message.

Expand All @@ -63,17 +67,66 @@ OPTIONS
commit log message unmodified. This option lets you
further edit the message taken from these sources.

-i|--include::
Instead of committing only the files specified on the
command line, update them in the index file and then
commit the whole index. This is the traditional
behaviour.

--::
Do not interpret any more arguments as options.

<file>...::
Update specified paths in the index file before committing.

Commit only the files specified on the command line.
This format cannot be used during a merge, nor when the
index and the latest commit does not match on the
specified paths to avoid confusion.

If you make a commit and then found a mistake immediately after
that, you can recover from it with gitlink:git-reset[1].


Discussion
----------

`git commit` without _any_ parameter commits the tree structure
recorded by the current index file. This is a whole-tree commit
even the command is invoked from a subdirectory.

`git commit --include paths...` is equivalent to

git update-index --remove paths...
git commit

That is, update the specified paths to the index and then commit
the whole tree.

`git commit paths...` largely bypasses the index file and
commits only the changes made to the specified paths. It has
however several safety valves to prevent confusion.

. It refuses to run during a merge (i.e. when
`$GIT_DIR/MERGE_HEAD` exists), and reminds trained git users
that the traditional semantics now needs -i flag.

. It refuses to run if named `paths...` are different in HEAD
and the index (ditto about reminding). Added paths are OK.
This is because an earlier `git diff` (not `git diff HEAD`)
would have shown the differences since the last `git
update-index paths...` to the user, and an inexperienced user
may mistakenly think that the changes between the index and
the HEAD (i.e. earlier changes made before the last `git
update-index paths...` was done) are not being committed.

. It reads HEAD commit into a temporary index file, updates the
specified `paths...` and makes a commit. At the same time,
the real index file is also updated with the same `paths...`.

`git commit --all` updates the index file with _all_ changes to
the working tree, and makes a whole-tree commit, regardless of
which subdirectory the command is invoked in.


Author
------
Written by Linus Torvalds <torvalds@osdl.org> and
Expand Down
Loading

0 comments on commit 130fcca

Please sign in to comment.