Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: list new files only

Tags:

git

status

When I do a git status I get a list of files prefixed with new file: . How can I get only this list? I want to process this files in a simple loop in a little shell script.

like image 225
BetaRide Avatar asked Jan 25 '12 09:01

BetaRide


People also ask

How do I see new files in git?

You can use git diff to show the changes. --name-only shows only the filenames. --diff-filter=A lists only the added files. If you want to see new files you have already added to the index use --cached , otherwise omit it.

How do I get a list of files added to git?

To see a list of commits with even more detail (including which files changed), run this command: git log --stat.

How do I display only the names of changed files?

git show --name-only SHA1 . you can also do: git diff --name-only HEAD@{3} HEAD@{0} for the exact commits you want to compare.

How do I get a list of files 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.


1 Answers

The commands below no longer give the expected results, I may originally also have made some mistakes. Please double-check your output and the options you are using. Nevertheless: The basic tenet of using diff-filter should still hold true.

Don't use grep to parse git output. Git almost certainly has the things you are looking for built-in (except if you are going for really advanced stuff).
You can use git diff to show the changes. --name-only shows only the filenames. --diff-filter=A lists only the added files.
If you want to see new files you have already added to the index use --cached, otherwise omit it. To see both diff to HEAD.
The commands look like this:

git diff --name-only --diff-filter=A --cached # All new files in the index   git diff --name-only --diff-filter=A          # All files that are not staged   git diff --name-only --diff-filter=A HEAD     # All new files not yet committed 
like image 103
andsens Avatar answered Sep 18 '22 15:09

andsens