相关疑难解决方法(0)

删除包含特定字符串的文本文件中的行

我如何使用sed删除包含特定字符串的文本文件中的所有行?

shell sed in-place text-parsing

1670
推荐指数
13
解决办法
168万
查看次数

为什么'git status'会忽略.gitattributes清理过滤器?

我有一个.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索引中.为什么是这样?

git gitattributes

10
推荐指数
1
解决办法
1234
查看次数

标签 统计

git ×1

gitattributes ×1

in-place ×1

sed ×1

shell ×1

text-parsing ×1