Windows 의 기본 줄바꿈 문자는 CRLF
Mac / Linux의 기본 줄바꿈 문자는 LF입니다.
운영체제에 따라 줄바꿈 문자가 다르기 때문에 git으로 프로젝트를 관리할 경우 문제가 생길 수 있습니다.
IDE나 텍스트 편집 프로그램에서는 운영체제에 따라 자동으로 줄 바꿈 문자를 인식하지만
git 에서는 다른 파일로 인식할 수 있어 예기치 못한 문제가 일어날 수 있습니다.
crlf will be replaced by lf the next time git touches it
이 오류의 경우도 git에서 자동으로 lf 형식으로 바꾸겠다는 오류 입니다.
운영체제 상관 없이 줄바꿈 문자를 설정하여 문제를 해결해봅시다.
줄 끝을 처리하도록 Git 구성 - GitHub Docs
diff에서의 문제를 방지하기 위해 줄 끝을 제대로 처리하도록 Git을 구성할 수 있습니다.
docs.github.com
문서에서는 먼저 내부 git의 core.autocrlf 설정을 수정했지만 저는.gitattributes를 사용하여 모든 사용자의 설정을 통일했습니다.
해당하는 프로젝트의 .gitattibutes에 다음의 데이터를 추가합니다. 없다면 추가해줍시다.
# Auto detect text files and perform LF normalization
* text=crlf
*.cs text diff=csharp
*.java text diff=java
*.html text diff=html
*.css text
*.js text
*.sql text
*.csproj text merge=union
*.sln text merge=union eol=crlf
*.docx diff=astextplain
*.DOCX diff=astextplain
# absolute paths are ok, as are globs
/**/postinst* text eol=lf
# paths that don't start with / are treated relative to the .gitattributes folder
relative/path/*.txt text eol=lf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binaryS
만약 lf로 된 파일이 있다면 자동으로 crlf설정으로 바꾼 후 git에 추가합니다.
프로젝트에서 사용하는 파일확장자명에 따라 .gitattributes 에 추가하면 됩니다.
저장한 후 커밋하면됩니다.
① gitattributes파일 커밋하기
$ git add . -u
$ git commit -m "Saving files before refreshing line endings"
② 변경된 모든 파일을 다시 추가하고 줄끝을 정규화하기
$ git add --renormalize .
③ 다시 작성된 정규화된파일 표시
$ git status
④ 변경내용 리포지토리에 푸시
$ git commit -m "Normalize all the line endings"
$ git push origin main
참고 자료
줄 끝을 처리하도록 Git 구성 - GitHub Docs
diff에서의 문제를 방지하기 위해 줄 끝을 제대로 처리하도록 Git을 구성할 수 있습니다.
docs.github.com
What's the strategy for handling CRLF (carriage return, line feed) with Git?
I tried committing files with CRLF-ending lines, but it failed. I spent a whole work day on my Windows computer trying different strategies and was almost drawn to stop trying to use Git and instea...
stackoverflow.com
'TIL' 카테고리의 다른 글
[Git] 커밋 메시지 수정하기 (0) | 2023.06.17 |
---|---|
.gitignore 파일 자동생성하기 - gitignore.io (2) | 2023.05.25 |
JAVA 빌드 도구 정리 (4) | 2023.05.24 |
Git 기초 사용법 정리 (4) | 2023.05.24 |
JAVA 컴파일 인터프리터 정리 (0) | 2023.05.23 |