Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git detect if there are untracked files quickly

Tags:

git

Is there a way to quickly detect if there are any untracked files?

I can list all of the untracked files with

git ls-files --other --directory --exclude-standard

But this is slow if there are many untracked files. Is there something like git diff -q where the exit status determines whether or not any untracked files exist?

like image 618
k107 Avatar asked Jun 13 '12 18:06

k107


2 Answers

If you have what you want when you've seen the first untracked file, quit right then.

If you're on GNU/anything

git ls-files --other --directory --exclude-standard | sed q1

will set rc1 if there are any

Otherwise,

anyuntracked() {
    return `git ls-files -o --directory --exclude-standard | sed q | wc -l`
}
anyuntracked

will do the same job

like image 177
jthill Avatar answered Sep 19 '22 14:09

jthill


git status will notify you of any untracked files.

Example output:

remco@Prosperpine ~/code/Sick-Beard (master) $ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   init.osx
nothing added to commit but untracked files present (use "git add" to track)
like image 33
Rem.co Avatar answered Sep 21 '22 14:09

Rem.co