깃헙에 열심히 커밋하면서 생기는 경고 메세지가 있다.
git add . 해도 마찬가지, 주피터 노트북으로 모든 .ipynb 파일을 생성 후 add할 때마다 발생하는 경고문이다.
$ git add .
warning: LF will be replaced by CRLF in 파일명어쩌구
The file will have its original line endings in your working directory
다행히도 구글링을 하니 수많은 분들께서 에러 해결방법을 주셨고,
정리해서 남겨놓으려고 한다.
나는 window 환경에서 TIL용으로 혼자 repository에 commit을 하고 있지만
혹시 깃 레포지토리를 같이 쓰고 팀원과 윈도우&맥 처럼 서로 다른 환경에서 협업하는 중이라면 저 경고를 완전 무시하기엔 다소 기억해둬야 할 부분인 것 같다.
\n커서는 그 자리에 그대로 둔 상황에서 종이만 한 줄 올려 줄을 바꾸는 동작.
유닉스 시스템에서는 한 줄의 끝이 LF(Line Feed)로 이루어진다.
\r현재 커서를 줄 올림 없이 가장 앞으로 옮기는 동작.
줄바꿈이다.
윈도우에서는 줄 하나가 CR(Carriage Return)와 LF(Line Feed), 즉 CRLF로 이루어진다.
나는 윈도우라서, LF will be replaced by CRLF in~ 이라는 warning이 뜬다.
(유닉스 OS을 쓰고 있다면 CRLF will be replaced by LF in… 에러 메시지가 뜬다고 한다.)
실제 코드는 변경된 게 없는데 소스의 CR/LF 때문에 변경으로 착각하여 commit 을 하게 될 수 있으며 변경 로그를 보거나 merge 마다 문제가 될 소지가 있다. 물론 혼자 한다면 무시해도 되겠지만, 다른 환경에서 개발한다면 merge할 때 지구가 무너지는 느낌을.. 큰일난다.
윈도우 사용자가 올린(커밋한) 코드를 -> 맥 사용자가 받아서 쓰고 싶을 때,
맥 사용자가 올린(커밋한) 코드를 -> 윈도우 사용자가 받아서 쓰고 싶을 때
왔다갔다 알아서 전환할 수 있도록 git bash 창에 명령어를 입력한다.
git config --global core.autocrlf true
git config --global core.autocrlf input
혹은 이러한 변환 기능을 원하지 않고, 그냥 에러 메시지 끄고 알아서 작업하고 싶은 경우에는 아래 명령어로 경고 메시지 기능인 core.safecrlf를 꺼주면 된다.
git config --global core.safecrlf false
라고 하길래, 에러 뜨게 해주세요 하고 싶어서 true로 변환하여 진행했더니 못보던 오류가 뜬다.
status로 확인해도 파일만 수정되었다 하고 add가 안된다.
그래서 그냥 false로 진행하고 add하니 원활하게 add, commit된다.
중간 중간 config --list로 core.autocrlf 확인해도 계속 true다.
나중에 더 찾아보고 직접 충돌나봐야 알 것 같다..
$ git config --global core.safecrlf true
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: itertools.ipynb
Untracked files:
(use "git add <file>..." to include in what will be committed)
.ipynb_checkpoints/itertools-checkpoint.ipynb
no changes added to commit (use "git add" and/or "git commit -a")
$ git add .
fatal: LF would be replaced by CRLF in itertools.ipynb
$ git config --global core.autocrlf true
$ git add . # 안돼...
fatal: LF would be replaced by CRLF in itertools.ipynb
$ git config --list # 둘 다 true다
core.autocrlf=true
core.safecrlf=true
$ git config --global core.safecrlf false
$ git config --list
core.autocrlf=true
core.safecrlf=false # false로 바꿨다
$ git add .
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: .ipynb_checkpoints/itertools-checkpoint.ipynb
modified: itertools.ipynb
$ git config --global core.autocrlf true # 이걸 쳐도 status 결과는 같다..
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: .ipynb_checkpoints/itertools-checkpoint.ipynb
modified: itertools.ipynb
참고:
https://blog.jaeyoon.io/2018/01/git-crlf.html
https://www.lesstif.com/gitbook/git-crlf-20776404.html
https://cocoon1787.tistory.com/728
https://velog.io/@wjdgkrud/window-%EC%97%90%EC%84%9C-git-%EC%97%90%EB%9F%AC-LF
https://bgpark.tistory.com/110