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

Re: How to list files that are pending for commit from a merge, including hand modified files

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Feb 21, 2009, 23:29 UTC
Message-ID
<alpine.LFD.2.00.0902211523280.3111@localhost.localdomain>
In-Reply-To
<e38bce640902211520j3f3c2787y28640b0ebcba5e27@mail.gmail.com>
On Sat, 21 Feb 2009, Brent Goodrick wrote:
Show 5 quoted lines
> 
> Is there some way in which to get a listing of the files that git-status 
> shows in its "changes to be committed" section, but not the "Untracked 
> files" section, short of postprocessing the git-status output with 
> sed/awk gymnastics?
Just do variations on
	git diff --name-only HEAD

and the reason I say "variations on" is that depending on exactly what you want you may want to use slightly different diffs.

For example, the command line above will list all files that are changed in the working tree wrt HEAD. But if you want to see only the files that you have actually updated in the index (ie the ones that would be committed without using "-a"), you should add "--cached" to the command line, so that it does the diff from HEAD to index, not HEAD to working tree.

And if you want to see what files are different in the working tree from the index, then drop the "HEAD" part, since that's the default behavior for "git diff".

Finally, use "--name-status" if you want to see if they are new, modified, or deleted - rather than just the name.

And if you care about renames, and want to see them as such, use -C or -M, of course.

So "git ls-files" is not at all what you want. That will give you information about the current index, but doesn't talk at all about how it differs from the previous commit or from the working tree. It can be useful for another thing, though: if you're in the middle of a merge, then you can ask for which files are marked as being unmerged in the index.

		Linus
Previous: Brent GoodrickNext: Brent Goodrick
Message 2 of 3 in “How to list files that are pending for commit from a merge, including hand modified files”
  1. Brent GoodrickFeb 21, 2009
  2. Linus TorvaldsFeb 21, 2009
  3. Brent GoodrickFeb 22, 2009

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.