Git ls-files: how to identify new files (added, failed)?

After I called git add <file> , the git status command will show me something like:

 ... new file: <file> 

Somehow I can’t manage it to get the same information using ls-files , it ( ls-files -tc in this case) will show me:

 H <commited file> H <other commited file> H <file> 

There seems to be no command line switch for new files. The file is reported as cached, which is normal, but how do I know if it is not committed at this time?

Is this possible with ls-files or some similar command (where I do not need to parse a lot of output, as in the case of git status )?

+47
git
Feb 19 '10 at 16:50
source share
2 answers

You want to use git diff --cached . Using --name-only it will list all the files that you changed in the index relative to HEAD. Using --name-status you can also get a status symbol, and --diff-filter you can specify which set of files you want to display (for example, "A" for recently added files). Use -M to enable motion detection and -C to detect copy if you want them.

For a rigorous read of what you wrote, git diff --cached --name-only --diff-filter=A display all the files that you added with HEAD that are not in HEAD.

+57
Feb 19 '10 at 21:20
source share

Explanation:. This is a way to show the files that I intend to add. This is not what the OP was looking for, but I will leave this post if it will be useful to others.

This seems to only show the files that I added [to my working copy, not the index], but do not match my standard ignore patterns:

  $ git ls-files --others --exclude-standard 

Without --exclude-standard it also shows files that are ignored when git status starts.

+28
Feb 19 '10 at 20:49
source share



All Articles