13

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.

orlp
  • 106,415
  • 33
  • 201
  • 300

2 Answers2

9

If Git aliases aren't an option, it can be done in 2 commands:

git ls-files $(git rev-parse --show-toplevel)
Community
  • 1
  • 1
Bluu
  • 4,726
  • 4
  • 28
  • 33
6

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?.

Community
  • 1
  • 1
tom
  • 19,901
  • 6
  • 40
  • 36
  • On Windows it needs double quotes - do double quotes also work for Linux? – orlp May 12 '15 at 12:36
  • No (in some shells, e.g. `bash`, `!` performs history expansion inside double quotes but not single quotes). I'll have to think about it -- double quotes won't work on Linux, single quotes and backslashes won't work on Windows... – tom May 12 '15 at 12:43
  • PowerShell on Windows should work with single quotes, if that's any help. – tom May 12 '15 at 13:00
  • It's been a while, but I just realised you can use `"! git ls-files"` in bash (the space after the exclamation mark prevents history expansion). That should be portable. – tom Jun 17 '15 at 02:10