我有一个.gitattributes清理过滤器,用于在提交之前删除文件中的所有注释.
$ cat .git/config
[filter "cleancomments"]
clean = "grep -v '^#'"
$ cat .gitattributes
* filter=cleancomments
Run Code Online (Sandbox Code Playgroud)
我有一个文件'test',其中包含以下内容(在存储库中提交):
This is a file with random content
Run Code Online (Sandbox Code Playgroud)
现在我对'test'进行修改并添加注释:
This is a file with random content
# and some comments
# like this
Run Code Online (Sandbox Code Playgroud)
git status 现在告诉我:
modified: test
Run Code Online (Sandbox Code Playgroud)
但是git diff是空的(应该如此).
我不完全清楚为什么git status不使用过滤器来决定文件是否被修改,但我认为这是它的实现方式.
对我来说真正神秘的是:
如果我这样做:
git add test
Run Code Online (Sandbox Code Playgroud)
然后突然文件'test'不再标记为已修改,并且它不会出现在git索引中.为什么是这样?