Reputation: 117661
I'm looking for a command similar to the following, but that always lists from the repository root, rather than the current working directory:
git ls-files --cached --others --exclude-standard
If possible I'd rather not use bash/batch, since I'm looking for a cross-platform solution.
Upvotes: 18
Views: 2967
Reputation: 5619
Commands that expect pathspecs as an arg generally allow for leading :/
to mean the root of the working tree. So you can use:
git ls-files --full-name :/
This is better than combining with git rev-parse --show-toplevel
output, because the latter won't allow you to find specific file in the repo. I.e. this: git ls-files -- $(git rev-parse --show-toplevel)"*filename.c"
won't work, but this git ls-files ":/*filename.c"
does. And it's shorter too.
Upvotes: 2
Reputation: 5535
If Git aliases aren't an option, it can be done in 2 commands:
git ls-files $(git rev-parse --show-toplevel)
Upvotes: 14
Reputation: 22939
If you can create an alias,
git config --global alias.ls-files-root "! git ls-files"
Then you should be able to do
git ls-files-root --cached --others --exclude-standard
Explanation: Aliases starting with '!' are executed as shell commands from the top-level directory. Related: Is there a way to get the git root directory in one command?.
Upvotes: 8