programing

LFol igit repo 및 작업 복사본 강제 적용

jooyons 2023. 7. 4. 21:53
반응형

LFol igit repo 및 작업 복사본 강제 적용

깃허브에 깃 저장소를 호스팅하고 있습니다.많은 파일들이 처음에 Windows에서 개발되었고, 저는 줄 끝 부분에 대해 너무 조심하지 않았습니다.초기 커밋을 수행했을 때 올바른 줄 끝을 적용하기 위한 GIT 구성도 없었습니다.그 결과 Github 저장소에 CRLF 줄 끝이 있는 파일이 여러 개 있습니다.

저는 현재 리눅스에서 부분적으로 개발 중이며, 라인 엔딩을 정리하고 싶습니다.LF on github로 파일이 올바르게 저장되고 작업 복사본에 LF가 있는지 확인하려면 어떻게 해야 합니까?

제가 설정했습니다..gitattributes가 된 파일text eol=LF그게 맞습니까?밀어붙인 에서, 는 그냥 헌적이고것강으로인냥가, ▁i▁just▁with.rm원하는 효과를 얻기 위해 내 로컬 레포와 github의 재클론?

저장소에 있는 파일(순수 소스 코드, 이미지, 실행 파일 등)에 대한 약간의 정보가 없으면 질문에 답하기가 조금 어렵습니다. :)

또한 Windows 또는 Linux에서 작업할 때 .git 저장소에 텍스트 파일의 LF 줄 끝이 있는지 확인하기 위해 작업 디렉터리의 줄 끝이 LF로 기본 설정됩니다.정말로 미안하기보다는 안전한 것이 낫습니다.

그러나 더 나은 대안이 있습니다. Linux workdir의 LF 줄말기, Windows workdir의 CRLF 줄말기 및 저장소의 LF 줄말기의 이점을 누릴 수 있습니다.

및 Windows 부로중이로므작업서으에적을 하십시오.core.eol으로 설정됨native그리고.core.autocrlf으로 설정됨true.

다음, 그다음내바다꿉니의 ..gitattributes과 같이 합니다.

* text=auto

이렇게 하면 Git가 커밋 및 체크아웃 시 자동 매직 라인 종료 변환을 처리할 수 있습니다.이진 파일은 변경되지 않으며 텍스트 파일로 탐지된 파일은 즉시 변환된 줄 끝을 볼 수 있습니다.

그러나 저장소의 내용을 알고 있으므로 Git에게 도움을 주고 이진 파일에서 텍스트 파일을 탐지하는 데 도움을 줄 수 있습니다.

이미지 프로젝트를 을 변경합니다..gitattributes과 같이 합니다.

* text=auto
*.txt text
*.c text
*.h text
*.jpg binary

이렇게 하면 확장명이 c, h 또는 txt인 파일이 레포에 LF 줄 끝과 함께 저장되고 작업 디렉터리에 기본 줄 끝이 있게 됩니다.JPEG 파일은 터치되지 않습니다.다른 모든 제품은 위에서 본 것과 같은 자동 필터링의 이점을 누릴 수 있습니다.

이 모든 것의 내면적인 세부 사항을 더 깊이 이해하기 위해, 저는 여러분이 Githubber인 Tim Clem의 매우 좋은 게시물인 "당신의 라인의 끝에 주의하세요"에 뛰어들 것을 제안합니다.

실제 예로, 당신은 또한 그것들이 어디로 변경되는지 커밋을 엿볼 수 있습니다..gitattributes파일이 시연됩니다.

다음 의견을 고려하여 답변에 업데이트합니다.

Linux 환경은 실제로 Windows 디렉토리를 공유하는 VirtualBox이기 때문에 실제로는 CRLF를 Windows 디렉토리에 넣지 않습니다.

일리가 있습니다.설명해 주셔서 감사합니다.이 특정한 맥락에서,.gitattributes파일 자체로는 충분하지 않을 것입니다.

리포지토리에 대해 다음 명령을 실행

$ git config core.eol lf
$ git config core.autocrlf input

Linux 및 Windows 환경 간에 저장소가 공유되면 두 환경의 로컬 구성 파일이 모두 업데이트됩니다. core.eol텍스트 파일에 체크아웃 시 LF 줄 끝이 있는지 확인합니다. core.autocrlf그러면 (예를 들어 복사/붙여넣기 작업으로 인해) 텍스트 파일의 잠재적인 CRLF가 리포지토리의 LF로 변환됩니다.

선택적으로, 당신은 Git가 텍스트 파일이 무엇인지 구별하는 것을 도울 수 있습니다..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파일, 커밋.

마지막으로 확인합니다.git status커밋할 내용 없음(작업 디렉토리 정리)을 언급한 다음 다음 작업을 수행합니다.

$ git checkout-index --force --all

이렇게 하면 구성 변경 사항과 다음을 고려하여 작업 디렉토리에 파일이 재생성됩니다..gitattributes파일을 저장하고 텍스트 파일에서 잠재적으로 간과되는 CRLF를 대체합니다.

이 작업이 완료되면 작업 디렉토리의 모든 텍스트 파일에 LF 줄 끝과git status여전히 작업장이 깨끗하다고 생각해야 합니다.

Git 2.10(2016-09-03 출시)부터는 각 텍스트 파일을 별도로 열거할 필요가 없습니다.Git 2.10은 .Source함께 동작을 수정했습니다.

.gitattributesGit 저장소의 루트에 있는 파일:

* text=auto eol=lf

추가하고 커밋합니다.

이후 다음 두 단계를 수행하여 모든 파일을 표준화할 수 있습니다.

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.

출처: 케노브의 답변.

모든 텍스트 파일의 LF 줄 끝을 강제로 지정하려면 다음 줄로 저장소의 최상위 수준에 파일을 만들 수 있습니다(원하는 대로 변경).

# Ensure all C and PHP files use LF.
*.c         eol=lf
*.php       eol=lf

로 간주하는모든 합니다.LF줄 끝 (normally리포아의끝부줄분리(지)core.eol구성을 통해 기본적으로 사용 중인 항목을 제어할 수 있습니다.

새 속성 설정에 따라 CRLF를 포함하는 텍스트 파일은 Git에 의해 정규화되어야 합니다.이 작업이 자동으로 수행되지 않으면 줄 끝을 변경한 후 리포지토리를 수동으로 새로 고칠 수 있으므로 다음 단계(기본 작업 디렉터리 지정)에 따라 작업 디렉터리를 다시 검색하고 커밋할 수 있습니다.

$ 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"

또는 GitHub 문서에 따라:

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.

참고 항목: @Charles Bailey 게시물.

또한 텍스트로 처리되지 않는 파일을 제외하려면 예를 들어 해당 텍스트 속성의 설정을 취소합니다.

manual.pdf      -text

또는 이진수로 명시적으로 표시합니다.

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary

고급 git 정규화 파일을 보려면 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

참고 항목:

나는 크롬을 복제하고 있었습니다.depot_tools모든 작업 복사본 파일이 CRLF로 종료되었습니다.저는 제 문제를 해결한 이 스크립트를 발견했습니다.

cd <your repo>
# config the local repo to use LF
git config core.eol lf
git config core.autocrlf input

# Copy files from the index to the working tree
git checkout-index --force --all

# If above line doesn't work, delete all cached files and reset.
git rm --cached -r .
git reset --hard

언급URL : https://stackoverflow.com/questions/9976986/force-lf-eol-in-git-repo-and-working-copy

반응형