git repo 및 작업 복사본에서 LF eol 강제 실행
github에서 호스팅되는 git 저장소가 있습니다. 많은 파일이 처음에 Windows에서 개발되었으므로 줄 끝을 너무 조심하지 않았습니다. 초기 커밋을 수행 할 때 올바른 줄 끝을 적용하기 위해 git 구성이 없었습니다. 결론은 내 github 저장소에 CRLF 줄 끝이있는 많은 파일이 있다는 것입니다.
Linux에서 부분적으로 개발 중이며 줄 끝을 정리하고 싶습니다. github에서 LF를 사용하여 파일이 올바르게 저장되고 작업 복사본에 LF가 있는지 어떻게 확인할 수 있습니까?
; .gitattributes
포함 하는 파일을 설정했습니다 text eol=LF
. 그 맞습니까? 커밋되고 푸시 된 상태에서 rm
로컬 리포지토리와 github에서 다시 복제하여 원하는 효과를 얻을 수 있습니까?
저장소에있는 파일 (순수한 소스 코드, 이미지, 실행 파일 등)에 대한 정보가 없으면 질문에 대답하기가 약간 어렵습니다. :)
이 외에도 Windows 또는 Linux에서 작업 할 때 텍스트 파일이 .git 저장소에 LF 줄 끝이 있는지 확인하기 때문에 작업 디렉토리에서 줄 끝으로 LF를 기본값으로 사용하려고합니다. . 정말로 미안보다 안전합니다 ....
그러나 더 좋은 대안이 있습니다. Linux workdir의 LF 줄 끝, Windows workdir의 CRLF 줄 끝 및 저장소의 LF 줄 끝의 이점을 누리십시오.
Linux 및 Windows에서 부분적으로 작업 할 때로 core.eol
설정되어 native
있고 core.autocrlf
로 설정되어 있는지 확인하십시오 true
.
그런 다음 .gitattributes
파일 내용을 다음으로 바꿉니다.
* text=auto
이를 통해 Git은 커밋 및 체크 아웃시 자동 줄 끝 변환을 처리 할 수 있습니다. 이진 파일은 변경되지 않으며 텍스트 파일로 감지 된 파일은 줄 끝이 즉시 변환되는 것을 볼 수 있습니다.
그러나 저장소의 내용을 알고 있으므로 Git에 손을 대고 바이너리 파일에서 텍스트 파일을 감지하는 데 도움을 줄 수 있습니다.
C 기반 이미지 처리 프로젝트에서 작업 한 경우 .gitattributes
파일 내용을 다음으로 바꿉니다.
* text=auto
*.txt text
*.c text
*.h text
*.jpg binary
이렇게하면 확장자가 c, h 또는 txt 인 파일이 리포지토리에 LF 줄 끝과 함께 저장되고 작업 디렉토리에 기본 줄 끝이 나타납니다. JPEG 파일은 건드리지 않습니다. 다른 모든 것들은 위에서 본 것과 동일한 자동 필터링 기능을 활용할 수 있습니다.
이 모든 것의 내부 세부 사항에 대해 더 깊이 이해하려면 Githubber의 Tim Clem의 "마지막 끝을 염두에 두십시오"라는 좋은 글을 읽어 보시기 바랍니다.
실제 예를 들어, 파일 에 대한 변경 사항을 보여주는 이 커밋을 엿볼 수도 있습니다 .gitattributes
.
다음 의견을 고려하여 답변을 업데이트하십시오.
Linux 환경이 실제로 Windows 디렉토리를 공유하는 VirtualBox이기 때문에 실제로 Windows 디렉토리에 CRLF를 원하지 않습니다.
맞는 말이다. 설명해 주셔서 감사합니다. 이 특정 상황에서 .gitattributes
파일 자체로는 충분하지 않습니다.
저장소에 대해 다음 명령을 실행하십시오.
$ git config core.eol lf
$ git config core.autocrlf input
리포지토리가 Linux와 Windows 환경간에 공유되므로 두 환경에 대한 로컬 구성 파일이 업데이트됩니다. core.eol
체크 아웃시 텍스트 파일에 LF 줄 끝이 있는지 확인하십시오. core.autocrlf
보장합니다 잠재적 인 텍스트 파일에 CRLF 저장소에 LF로 변환됩니다 (사본의 결과를 / 예를 들어 작업을 붙여 넣습니다).
선택적으로, 힘내 무엇을 구별 할 수 있도록 할 수 있습니다 작성하여 텍스트 파일 .gitattributes
에 다음과 유사한 것을 포함 파일 :
# Autodetect text files
* text=auto
# ...Unless the name matches the following
# overriding patterns
# Definitively text files
*.txt text
*.c text
*.h text
# Ensure those won't be messed up with
*.jpg binary
*.data binary
.gitattributes
파일 을 작성하기로 결정한 경우 커밋하십시오 .
마지막으로 "No commit to commit (working directory clean)"을git status
언급 하고 다음 작업을 수행하십시오.
$ git checkout-index --force --all
This will recreate your files in your working directory, taking into account your config changes and the .gitattributes
file and replacing any potential overlooked CRLF in your text files.
Once this is done, every text file in your working directory WILL bear LF line endings and git status
should still consider the workdir as clean.
Starting with git 2.10, it is not necessary to enumerate each text file separately. Git 2.10 fixed the behavior of text=auto together with eol=lf. Source.
.gitattributes
file in the root of your git repository:
* text=auto eol=lf
Add and commit it.
Afterwards, you can do following to steps and all files are normalized now:
git rm --cached -r . # Remove every file from git's index.
git reset --hard # Rewrite git's index to pick up all the new line endings.
Source: Answer by kenorb.
To force LF line endings for all text files, you can create .gitattributes
file in top-level of your repository with the following lines (change as desired):
# Ensure all C and PHP files use LF.
*.c eol=lf
*.php eol=lf
which ensures that all files that Git considers to be text files have normalized (LF
) line endings in the repository (normally core.eol
configuration controls which one do you have by default).
Based on the new attribute settings, any text files containing CRLFs should be normalized by Git. If this won't happen automatically, you can refresh a repository manually after changing line endings, so you can re-scan and commit the working directory by the following steps (given clean working directory):
$ echo "* text=auto" >> .gitattributes
$ rm .git/index # Remove the index to force Git to
$ git reset # re-scan the working directory
$ git status # Show files that will be normalized
$ git add -u
$ git add .gitattributes
$ git commit -m "Introduce end-of-line normalization"
or as per GitHub docs:
git add . -u
git commit -m "Saving files before refreshing line endings"
git rm --cached -r . # Remove every file from Git's index.
git reset --hard # Rewrite the Git index to pick up all the new line endings.
git add . # Add all your changed files back, and prepare them for a commit.
git commit -m "Normalize all the line endings" # Commit the changes to your repository.
See also: @Charles Bailey post.
In addition, if you would like to exclude any files to not being treated as a text, unset their text attribute, e.g.
manual.pdf -text
Or mark it explicitly as binary:
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
To see some more advanced git normalization file, check .gitattributes
at Drupal core:
# Drupal git normalization
# @see https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
# @see https://www.drupal.org/node/1542048
# Normally these settings would be done with macro attributes for improved
# readability and easier maintenance. However macros can only be defined at the
# repository root directory. Drupal avoids making any assumptions about where it
# is installed.
# Define text file attributes.
# - Treat them as text.
# - Ensure no CRLF line-endings, neither on checkout nor on checkin.
# - Detect whitespace errors.
# - Exposed by default in `git diff --color` on the CLI.
# - Validate with `git diff --check`.
# - Deny applying with `git apply --whitespace=error-all`.
# - Fix automatically with `git apply --whitespace=fix`.
*.config text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.css text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.dist text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.engine text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2 diff=php
*.html text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2 diff=html
*.inc text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2 diff=php
*.install text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2 diff=php
*.js text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.json text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.lock text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.map text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.md text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.module text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2 diff=php
*.php text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2 diff=php
*.po text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.profile text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2 diff=php
*.script text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.sh text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2 diff=php
*.sql text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.svg text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.theme text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2 diff=php
*.twig text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.txt text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.xml text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
*.yml text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
# Define binary file attributes.
# - Do not treat them as text.
# - Include binary diff in patches instead of "binary files differ."
*.eot -text diff
*.exe -text diff
*.gif -text diff
*.gz -text diff
*.ico -text diff
*.jpeg -text diff
*.jpg -text diff
*.otf -text diff
*.phar -text diff
*.png -text diff
*.svgz -text diff
*.ttf -text diff
*.woff -text diff
*.woff2 -text diff
See also:
- Dealing with line endings at GitHub
- When using vagrant: Windows CRLF to Unix LF Issues
참고URL : https://stackoverflow.com/questions/9976986/force-lf-eol-in-git-repo-and-working-copy
'IT story' 카테고리의 다른 글
MySQL 열 정의를 변경하는 방법? (0) | 2020.06.12 |
---|---|
대소 문자를 구분하지 않음 (0) | 2020.06.12 |
process.env.NODE_ENV가 정의되지 않았습니다 (0) | 2020.06.12 |
github에서 gem의 특정“커밋”을 얻는 방법은 무엇입니까? (0) | 2020.06.12 |
HttpWebRequest (.NET)를 비동기 적으로 사용하는 방법은 무엇입니까? (0) | 2020.06.12 |