1. 程式人生 > >git grep和grep搜尋結果不一樣

git grep和grep搜尋結果不一樣

1、程式碼庫檔案test.txt檔案如下

testgitgrep=1
testlinuxgrep=0

把testgitgrep=1改成testgitgrep=0後

testgitgrep=0
testlinuxgrep=0

2、

用git grep搜尋,結果如下

[email protected]:~$git grep 'test' test.txt
test.txt:testgitgrep=1 ()
test.txt:testlinuxgrep=0

用grep搜尋,結果如下

[email protected]
:~$grep 'test' test.txt testgitgrep=0 testlinuxgrep=0

而且用git diff也沒有輸出

[email protected]:~$git diff test.txt

3、為什麼git grep搜尋結果錯誤,原來是設定了git update-index --assume-unchanged,把他設定回去git update-index --no-assume-unchanged,如下

git update-index --no-assume-unchanged test.txt

現在git diff就有輸出了,而且git grep搜出來的結果也和grep一致。

git diff test.txt
diff --git a/test.txt b/test.txt
index 27e64ff..3e4920f 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,2 @@
-testgitgrep=1
+testgitgrep=0
 testlinuxgrep=0
[email protected]:~$git grep 'test' test.txt
test.txt:testgitgrep=0
test.txt:testlinuxgrep=0