我的.gitignore文件似乎无法预测。这是一个例子:
我使用文件bar.txt创建了一个新的repo foo,我想忽略它:
pon2@kann4:~$ mkdir foo
pon2@kann4:~$ cd foo/
pon2@kann4:~/foo$ touch bar.txt
pon2@kann4:~/foo$ git init
Initialized empty Git repository in /home/pon2/foo/.git/
pon2@kann4:~/foo$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# bar.txt
nothing added to commit but untracked files present (use "git add" to track)
正如预期的那样,bar.txt显示为未跟踪。所以我告诉git忽略.txts,但我不小心添加了一些尾随空格:
pon2@kann4:~/foo$ echo "*.txt " > .gitignore
现在当我检查回购状态时,git不会忽略bar.txt:
pon2@kann4:~/foo$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# bar.txt
nothing added to commit but untracked files present (use "git add" to track)
发生了什么事?
答案 0 :(得分:2)
.gitignore是空白敏感的。如果你包含尾随空格,git不会识别你的文件。
在这一行中有一个尾随空格:
pon2@kann4:~/foo$ echo "*.txt " > .gitignore
一旦我们解决了这个问题:
pon2@kann4:~/foo$ echo "*.txt" > .gitignore
问题解决了:
pon2@kann4:~/foo$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
nothing added to commit but untracked files present (use "git add" to track)
pon2@kann4:~/foo$
答案 1 :(得分:2)
这在git 2.0中有所改变。来自release notes:
在.gitignore文件中尾随空格,除非它们被引用 对于
fnmatch(3)
,例如"path\ "
被警告并被忽视。严格 说来,这是一个向后不兼容的变化,但不太可能 咬任何理智的用户,调整应该是显而易见的。