我的.gitignore文件似乎无法预测地工作。下面是一个示例:
我用一个文件bar.txt创建了一个新的存储库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)到底怎么回事?
发布于 2011-12-08 04:35:06
.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$ 发布于 2016-12-08 21:47:35
这一点在git 2.0中发生了变化。从release notes
.gitignore文件中的
尾随空格将被警告并忽略,除非在
fnmatch(3)中对它们进行了引号,例如"path\ "。严格地说,这是一个向后不兼容的变化,但不太可能影响任何理智的用户,调整应该是显而易见和容易的。
https://stackoverflow.com/questions/8422045
复制相似问题