threads / discuss / 17943

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

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

## tl;dr

3 messages between Feb 21, 2009 and Feb 22, 2009.

replies: 2people: 2as markdown or json

Brent Goodrick· Feb 21, 2009, 23:20 UTC · lore
Hi,

git-ls-files does not seem to show files pending to be committed. The -m option does seem to work for files that I might have edited outside of git via an editor, but not all of the other ones pending for merge. The -t option "seems" to imply that the info would be shown, but only lists all files in the repo. Only git-status seems to show these files but in a fashion that makes filtering a bit clunky. 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? E.g., the first section of "modified" files and "new file" type files, but not the junk/ directory:

# On branch work # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: .Xmodmap # new file: .some_file # modified: .gitignore # modified: .zone.profile # modified: Vncviewer # new file: bin/gitw-merge-common.sh # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # junk/

Thanks, Brent

Linus Torvalds· Feb 21, 2009, 23:29 UTC · re: Brent Goodrick · lore

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

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
Brent Goodrick· Feb 22, 2009, 02:09 UTC · re: Linus Torvalds · lore

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

Thanks very much! I'll have to play around with those variations a bit to get a feel for what will work in my context.

bg

On Sat, Feb 21, 2009 at 3:29 PM, Linus Torvalds <torvalds@linux-foundation.org> wrote:

Show 41 quoted lines
>
>
> On Sat, 21 Feb 2009, Brent Goodrick wrote:
>>
>> 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
>

← back to recent threads