Reputation: 31
I am writing a script that finds all files that are added to the stage. I have only come up with solutions that work when there is already a initial commit (ie using git diff-index --name-status HEAD). But no solution that works when there is no HEAD.
ie:
% git init
Initialized empty Git repository in /Users/jocke/dev/agical/test/.git/
% cat >> test
content
^C
% git add --all
% git st
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: test
#
% git diff-index --name-status HEAD
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
git status seems to be able to figure out what needs to be added. There is probably some plumbing that I could use but I can't seem to find it. Any ideas?
Upvotes: 3
Views: 446
Reputation: 301117
All you want is:
git diff --cached --name-status
And works even if there is no initial commit.
Or you want to do:
git status --porcelain
Upvotes: 1