Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git ls-files: howto identify new files (added, not committed)?

Tags:

git

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

... new file:    <file> 

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

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

There seems no commandline switch to exist for new files. The file is reported as cached, which is ok, but how do I find out that it is not committed at this time?

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

like image 582
tanascius Avatar asked Feb 19 '10 16:02

tanascius


People also ask

How do you see which files were changed in a commit?

Find what file changed in a commit To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.

How do you check changes before commit?

If you just want to see the diff without committing, use git diff to see unstaged changes, git diff --cached to see changes staged for commit, or git diff HEAD to see both staged and unstaged changes in your working tree.


2 Answers

You want to use git diff --cached. With --name-only it'll list all the files you've changed in the index relative to HEAD. With --name-status you can get the status symbol too, with --diff-filter you can specify which set of files you want to show ('A' for newly added files, for instance). Use -M to turn on move detection and -C for copy detection if you want them.

For the strictest reading of what you wrote, git diff --cached --name-only --diff-filter=A will list all the files you've added since HEAD which don't exist in HEAD.

like image 140
Andrew Aylett Avatar answered Oct 06 '22 02:10

Andrew Aylett


Clarification: This is a way to show the files that I intend to add. This is not what the OP was looking for, but I'll leave this post in case it's useful to others.

This seems to show only the files that I have added [to my working copy, not the index] but aren't matched by my standard ignore patterns:

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

Without --exclude-standard, it also shows files that are ignored when I run git status.

like image 39
Mike Seplowitz Avatar answered Oct 06 '22 02:10

Mike Seplowitz