Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a list of all unversioned files in a Git-controlled folder

Tags:

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] 
like image 671
Ryan Lester Avatar asked Nov 07 '12 05:11

Ryan Lester


People also ask

How do I get a list of files in a directory in git?

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.

How do I see all untracked files in git?

-unormal which shows untracked files and directories. This is the default behaviour of git status. -uall Which shows individual files in untracked directories.

Which command provides the list of tracked files?

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.


2 Answers

Or...

git clean -dnx | cut -c 14- 

If you don't want to see ignored files,

git clean -dn | cut -c 14- 
like image 59
Dietrich Epp Avatar answered Sep 21 '22 18:09

Dietrich Epp


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.

like image 43
platforms Avatar answered Sep 20 '22 18:09

platforms