git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Can I checkout a single file without altering index?

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Oct 15, 2010, 19:32 UTC
Message-ID
<20101015193252.GA23082@burratino>
In-Reply-To
<20101015185539.GA30380@sigill.intra.peff.net>
Jeff King wrote:
> On Fri, Oct 15, 2010 at 01:43:02PM -0500, Jonathan Nieder wrote:
>> Neal Kreitzinger wrote:
Show 9 quoted lines
>>> However, there is an option in git-commit to copy files directly from the 
>>> working-tree to the object-store by totally bypassing the index
>>
>> What option is this?  I thought "git commit --include" added content
>> to the index.
>
> git commit -o|--only, which is the same as "git commit <paths>". Of
> course it still uses an index, to create the tree, but it uses a
> temporary one based on HEAD instead of the current index contents.
Ah, it's stranger than that.
	 * A partial commit.
	 *
	 * (0) find the set of affected paths;
	 * (1) get lock on the real index file;
	 * (2) update the_index with the given paths;
	 * (3) write the_index out to the real index (still locked);
	 * (4) get lock on the false index file;
	 * (5) reset the_index from HEAD;
	 * (6) update the_index the same way as (2);
	 * (7) write the_index out to the false index file;
	 * (8) return the name of the false index file (still locked);
The net effect being that the index will match the work tree for the
listed paths when the operation is over, while other files are
untouched.
-- 8< --
Subject: Documentation: clarify "commit --only" description
>From the current description, one might imagine that "git commit

<pathspec>" bypasses the index completely. Clarify what it does do to the index:

 - paths matching <pathspec> are updated to match the work tree
 - paths not matching <pathspec> are left alone

so readers can have a better idea of what the index represents before and after such an operation.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 I'm not so happy with the wording.  Hopefully this gives the idea...
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 42fb1f5..6bb3eff 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -191,9 +191,10 @@ FROM UPSTREAM REBASE" section in linkgit:git-rebase[1].)
 --only::
 	Make a commit only from the paths specified on the
 	command line, disregarding any contents that have been
-	staged so far. This is the default mode of operation of
-	'git commit' if any paths are given on the command line,
-	in which case this option can be omitted.
+	staged so far.  The state of other files in the index is
+	preserved and will not affect the commit.  This is the
+	default mode of operation of 'git commit' if any paths are given
+	on the command line, in which case this option can be omitted.
 	If this option is specified together with '--amend', then
 	no paths need to be specified, which can be used to amend
 	the last commit without committing changes that have
Previous: Jeff KingNext: Jeff King
Message 11 of 16 in “Can I checkout a single file without altering index?”
  1. Christian HalstrickOct 12, 2010
  2. Michael J GruberOct 12, 2010
  3. Stefan NaeweOct 12, 2010
  4. Jared HanceOct 13, 2010
  5. Alex RiesenOct 12, 2010
  6. Tomas CarneckyOct 12, 2010
  7. Christian HalstrickOct 14, 2010
  8. Neal KreitzingerOct 15, 2010
  9. Jonathan NiederOct 15, 2010
  10. Jeff KingOct 15, 2010
  11. Jonathan NiederOct 15, 2010
  12. Jeff KingOct 15, 2010
  13. Neal KreitzingerOct 15, 2010
  14. Andreas SchwabOct 15, 2010
  15. Junio C HamanoOct 15, 2010
  16. Jonathan NiederOct 15, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.