문제

In my specific case, I am using git-p4 and I want to know if git-p4 committed the files with CRLF in the actual committed objects themselves. In general, though, I wan to know how to directly find out. In other words, when I checkout normally, things like core.autocrlf and .gitattributes could modify what gets written to disk; I want to bypass that for a second.

도움이 되었습니까?

해결책

git show HEAD:file.txt > /tmp/here.txt && file /tmp/here.txt

Or using pipe-fu to avoid the tempfile:

git show HEAD:file.txt | file -

EDIT: the below methods are extremely inneffective, but they were my original answer so I'll leave them here.

Something else that will work is git cat-file -p abcd2134 > temp_file.txt where abcd1234 is the object hash for the file. Whatever that outputs should be the verbatim text that's committed. I can open temp_file.txt and see what it's line endings are (I used vim to do that).

If you're in bash, you can type the following:

git cat-file -p `git ls-tree HEAD file.txt  | sed 's/.* .* \(.\{40\}\).*$/\1/'` | tr "\r" '!!!!' | grep '!!!!' | wc -l

If the result is 0, then the file was committed with only CR. If the result is greater than zero, then there are occurrences of "\r" which means it was committed with dos format (CRLF).

See How to get SHA of file for specific Git commit? for an explanation of the part inside the backticks.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top