2012-08-06 89 views
14

有沒有一種方法可以確定現有git存儲庫中的行結束符?有沒有一種方法來確定現有的git回購行結束?

如果我克隆現有的存儲庫,我該如何確定創建者使用了什麼core.autocrlf?

我還不確定什麼對於core.autocrlf例如,在Windows中 的最佳設置(因爲有多個觀點:Distributing git configuration with the codehttps://help.github.com/articles/dealing-with-line-endings

獎金的問題:你能確定在Windows(標準工具)如果回購有混合行結束(通過錯誤的core.autocrlf設置)通過所有提交?

+0

回答第一個問題[here](http://stackoverflow.com/q/25697254/1436671)。 – 2016-04-28 14:49:33

回答

2

我仍然會保持該設置(core.autocrlf)到false,正如我在「 Distributing git configuration with the code」你提到解釋,並使用eol gitattributes directive進行更細粒度的控制。

話雖這麼說,檢測混行結尾:

  • 設置core.autocrlftrue
  • git clone您的回購
  • git diff:如果diff文件只是你的克隆......一些自動停產後可見轉換隻是在工作樹上發生。

更新2016(4年後):a more modern way to detect eol changes

git -c color.diff.whitespace="red reverse" diff -R -- afile 
10

要檢查哪些行結束在倉庫中(不管你core.autocrlf設置的)實際上犯,請嘗試以下操作:

git grep -I --files-with-matches --perl-regexp '\r' HEAD 

-I表示不應該查看二進制文件。)

+0

我的msysgit沒有使用USE_LIBPCRE進行編譯,這樣做是否也會工作'git grep -I --files-with-matches --basic-regexp'\ r'HEAD'(現在也沒有結果'\ r \ n ') – 2012-08-06 09:45:25

+2

試試這個:'git grep -I --files -with-matches $'\ r'HEAD' – robinst 2012-08-06 10:33:05

+0

這個命令返回HEAD結尾的所有文件,或者? 'git grep -I --files-with-matches $'\ r \ n'HEAD'會傳遞DOS行結束符? – 2012-08-06 10:58:00

1

最好的行尾的做法是在這裏:https://stackoverflow.com/a/10855862

要確定在現有的Git倉庫行的結尾:

  1. 設置core.autocrlffalse,所以在傳輸文件,也不會改變文件結尾。
  2. git clone您的回購爲前。在一個新的目錄中。
  3. 使用顯示行結尾的文本編輯器打開文件(例如,PHPStorm)。您應該打開多個文件,因爲文件之間的結尾可能會有所不同。

您不能確定創建者使用的core.autocrlf是什麼,因爲它是本地配置,除了repo具有.gitattributes文件。

在Windows上,如果您沒有使用.gitattributes,只需使用core.autocrlf true,因爲它默認設置。

相關問題