Filip Majernik
Filip Majernik

Reputation: 7810

How to list only newly added files between two branches

How can I list newly created (added) files between two branches? I can list all files that have been changed with:

git diff --color --name-only branch1..branch2

But that also contains files, that just changed their content, not necessarily new files. Is there some Git command for this, or do I have to checkout each branch and compare the files, e.g. with bash?

Upvotes: 57

Views: 18465

Answers (4)

eftshift0
eftshift0

Reputation: 30156

You would use ... so that you do not see files that were deleted on one branch to show up as added on the other:

git diff --name-only --diff-filter=A branch1...branch2

Upvotes: 5

michas
michas

Reputation: 26495

Just replace --name-only with --name-status. This way git will show if the file is added, deleted or just modified.

If you are only interested in the new (=added) files you can simply grep for ^A:

git diff --name-status branch1..branch2 | grep ^A

Upvotes: 57

Jakub Narębski
Jakub Narębski

Reputation: 323354

You can use --diff-filter option of git diff:

git diff --color --name-only --diff-filter=A branch1 branch2

Upvotes: 75

dialogik
dialogik

Reputation: 9542

Use this command to check for new tracked/added files

git diff --color --name-status staging | grep ^A

Upvotes: 1

Related Questions