programing

git EOL 변환 비활성화

nasanasas 2020. 10. 17. 10:37
반응형

git EOL 변환 비활성화


나는 어떤 작업에 대해서도 줄 끝을 변경하지 않도록 자식을 얻으려고합니다. 불행히도, 그것은 중요하지 않은 것 같습니다. 이 동작을 비활성화하는 다양한 메커니즘이있는 다음 테스트 케이스로 축소했습니다.


  • 두 대의 컴퓨터로 시작 (Windows 컴퓨터 = A, Linux 컴퓨터 = B)
  • 두 컴퓨터에서 : git config --global core.autocrlf false
  • 두 컴퓨터에서 : git config --global core.eol crlf(경우에 따라)

  • A에 새 저장소를 만듭니다. 빈 폴더에서 :
    • git init --shared(그런 다음 생성 된 .git디렉토리 숨기기 해제 )
    • .gitignore저장소에 새 파일 만들기
    • .gitattributes한 줄로 저장소에 새 파일 만듭니다 .* -text
    • git add ., git commit -m "initial commit"예를 들어 this .
    • git branch master_recv
    • 리모컨 추가
  • document.txtCRLF를 포함하는 저장소에 새 파일 만듭니다.
  • 커밋 : git add -A, 다음git commit -m "<something>"
  • A document.txt에는 여전히 CRLF가 포함되어 있습니다 (삭제하고로 재설정 --hard하면 CRLF가있는 버전 반환 됨).

  • 전체 디렉터리를 컴퓨터 B로 SCP
  • new fileCRLF가 포함 된 새 파일 추가
  • 커밋 : git add -A, 다음git commit -m "<something>"
  • B document.txt와 B new file모두 여전히 CRLF를 포함합니다.

  • B의 마스터를 A로 끌어옵니다. git pull <remote> master:master_recv
  • A document.txt가 LF로 변경되었습니다. 추가 된 파일 new file에는 LF도 포함되어 있습니다.

B가 Windows 시스템이면 문제가 발생하지 않습니다.


프로젝트 안에 .gitattributes파일 이 있어야 합니다. 대부분의 경우 다음과 같이 표시됩니다 (또는이 스크린 샷 ).

# Handle line endings automatically for files detected as text 
# and leave all files detected as binary untouched.
* text=auto

# Never modify line endings of our bash scripts
*.sh -crlf

#
# The above will handle all files NOT found below
#
# These files are text and should be normalized (Convert crlf => lf)
*.css           text
*.html          text
*.java          text
*.js            text
*.json          text
*.properties    text
*.txt           text
*.xml           text

# These files are binary and should be left untouched
# (binary is macro for -text -diff)
*.class         binary
*.jar           binary
*.gif           binary
*.jpg           binary
*.png           binary

자동 처리를 비활성화 * text=auto하려면 * text=false변경 합니다 ( 스크린 샷 참조 ).

이렇게 :

enter image description here

If your project doesn't have a .gitattributes file, then the line endings are set by your git configurations. To change your git configurations, do this:

Go to the config file in this directory:

1) C:\ProgramData\Git\config

2) Open up the config file in Notepad++ (or whatever text editor you prefer)

3) Change "autocrlf=" to false.

enter image description here


One simple solution is:

  • make sure core.autocrlf is set to false for all repos:
    git config --global core.autocrlf false
  • re-clone your repo, and check no EOL conversion is done.

If there are conversions automatically done, that mean a .gitattributes core.eol directive is there within the repo.


I figured it out. It seems that the SCP program was converting the line endings. I noticed this when I tried deliberately making a file with LF endings and then observing that it appeared as CRLF when downloaded.

Since this was the solution for me, I'm accepting this answer, but people of the future should also refer to the other answers for a more general solution.


From gitattributes(5) Manual Page "Effects" topic

text

This attribute enables and controls end-of-line normalization. When a text file is normalized, its line endings are converted to LF in the repository. To control what line ending style is used in the working directory, use the eol attribute for a single file and the core.eol configuration variable for all text files.

Set

Setting the text attribute on a path enables end-of-line normalization and marks the path as a text file. End-of-line conversion takes place without guessing the content type.

Unset Unsetting the text attribute on a path tells Git not to attempt any end-of-line conversion upon checkin or checkout.

core.autocrlf in new (1.7.2+) Git not used, core.eol and correct setting|unsetting of text-attribute considered as more reliable way

참고URL : https://stackoverflow.com/questions/21822650/disable-git-eol-conversions

반응형