Getting a list of unversioned files in a Git-controlled folder is way more annoying than it needs to be. Unless I really suck at reading man pages, it doesn't look like Git provides a facility to perform this operation on its own.
There may be a more elegant way of performing this, but here's a one-liner I threw together for this task, in case anyone else ever needs to use it.
Edit: turns out there's a standard way to do this that already works well.
git ls-files --other [--exclude-standard]
Use the terminal to display the . git directory with the command ls -a . The ls command lists the current directory contents and by default will not show hidden files.
-unormal which shows untracked files and directories. This is the default behaviour of git status. -uall Which shows individual files in untracked directories.
This command will list the files that are being tracked currently. If you want a list of files that ever existed use: git log --pretty=format: --name-only --diff-filter=A | sort - | sed '/^$/d'This command will list all the files including deleted files.
Or...
git clean -dnx | cut -c 14-
If you don't want to see ignored files,
git clean -dn | cut -c 14-
Actually, if you use git clean
with the -n
or --dry-run
option, it will print out a list untracked files that it would have removed had you run it with the -f
or --force
option. Adding the -d
flag includes directories that are either empty or contain only untracked files.
So you can run this command from within a git repository:
$ git clean -dn
And get output like this:
Would remove dir/untracked_file_1.txt Would remove untracked_file_2.txt
Here's a bonus: It respects your .gitignore file as well, though if you add the -X
flag, it will list only ignored files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With