2012-06-13 48 views

回答

14

如果你有你想要什麼,當你見過的第一個未跟蹤文件,退出權則。

如果你在GNU /什麼

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

將設置RC1,如果有任何

否則,

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

會做同樣的工作

+0

爲了使結果更符合'git status',添加'--no-empty-directory'。 – pjvandehaar

+0

我不認爲這有效。如果你對這個命令進行基準測試,它與sed和sed的速度完全相同。我懷疑git並沒有刷新輸出,直到它全部可用。 – user3467349

+0

@ user3467349我不認爲填充緩衝區所需的幾十個文件名會給很多人帶來足夠的時間,他說「很多」,但是如果你有一些奇怪的佈局,將很少的未跟蹤文件分散到多個目錄或總是有'stdbuf'命令強制對ls-files stdout進行線緩衝。 – jthill

1

git status會通知您任何未跟蹤的文件。

輸出示例:

[email protected] ~/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) 
+1

我想' git ls-files'仍然快於'git status' – k107

+1

是的,事實上你是對的!我將這兩個命令定時在一個100000個新文件的測試集上。 'git status'取'real:0m0.927s',而'ls-files'只取'real:0m0.468s'。 (沒有太多的答案,但也許很好理解) –

相關問題