Git 상태 무시 줄 끝 / 동일한 파일 / Windows 및 Linux 환경 / Dropbox / mled
어떻게 만드나요
자식 상태
줄 끝 차이를 무시 하시겠습니까?
배경 정보 :
프로젝트 작업을 위해 Windows와 Linux를 임의로 사용합니다. 프로젝트가 Dropbox에 있습니다.
git diff가 줄 끝을 무시하는 방법에 대해 많이 발견했습니다. 나는 meld git diff를 사용하기 때문에 각 파일에 대해 meld를 엽니 다. 그리고 meld는 "동일한 파일"이라고 말합니다.
그래서 이것을 어떻게 피할 수 있습니까? Git은 변경된 파일에 대해서만 meld를 열어야합니다. 그리고 git status는 파일 끝이 다른 경우 파일이 변경된 것으로보고하지 않아야합니다.
편집 : 원인 :
이것은 Windows에서이 설정 때문에 발생했습니다.
core.autocrlf true
그래서 Linux에서 작업 복사본을 확인하고 Windows에서 core.autocrlf를 false로 설정했습니다.
git status가 다른 새 줄을 무시하도록 만드는 방법을 아는 것이 여전히 좋습니다.
다음과 같이 core.autocrlf 값을 설정해보십시오.
git config --global core.autocrlf true
대신 .gitattributes를 다음 설정으로 사용하십시오.
# Ignore all differences in line endings
* -crlf
.gitattributes는 글로벌 .gitconfig와 동일한 디렉토리에 있습니다. .gitattributes가 없으면 해당 디렉토리에 추가하십시오. .gitattributes를 추가 / 변경 한 후에는 기존 파일에 변경 사항을 성공적으로 적용하기 위해 저장소를 하드 리셋해야합니다.
Windows 운영 체제의 git 명령과 관련된 문제 :
$ git add --all
경고 : LF는 ...에서 CRLF로 대체됩니다.
파일은 작업 디렉토리에 원래 줄 끝이 있습니다.
해상도 :
$ git config --global core.autocrlf false
$ git add --all
경고 메시지가 나타나지 않습니다.
이 답변은 OP가 다중 OS 솔루션에 대한 필요성을 참조하기 때문에 관련이있는 것 같습니다. 이 Github 도움말 문서에서는 OS 간 행 끝을 처리하는 데 사용할 수있는 접근 방식을 자세히 설명합니다. 크로스 OS 라인 엔딩을 관리하기위한 글로벌 및 리포지토리 별 접근 방식이 있습니다.
글로벌 접근
Linux 또는 OS X에서 Git 줄 끝 처리를 구성합니다.
git config --global core.autocrlf input
Windows에서 Git 줄 끝 처리를 구성합니다.
git config --global core.autocrlf true
리포지토리 별 접근 방식 :
저장소의 루트에서 .gitattributes파일을 만들고 프로젝트 파일에 대한 줄 끝 설정을 다음 형식으로 한 번에 한 줄씩 정의합니다. path_regex line-ending-settings여기서는 line-ending-settings다음 중 하나입니다.
- 본문
- 바이너리 (Git가 줄 끝을 수정해서는 안되는 파일)
text값이 일치하는 파일의 라인 엔딩을 처리하는 방법에 망할 놈의 지시에 더 구성 할 수 있습니다 :
text-줄 끝을 OS 기본 줄 끝으로 변경합니다.text eol=crlf-CRLF체크 아웃시 줄 끝을 변환합니다 .text eol=lf-LF체크 아웃시 줄 끝을 변환합니다 .text=auto-Git의 재량에 따라 라인 핸들을 남겨 두는 합리적인 기본값.
다음은 샘플 .gitattributes 파일의 내용입니다.
# Set the default behavior for all files.
* text=auto
# Normalized and converts to
# native line endings on checkout.
*.c text
*.h text
# Convert to CRLF line endings on checkout.
*.sln text eol=crlf
# Convert to LF line endings on checkout.
*.sh text eol=lf
# Binary files.
*.png binary
*.jpg binary
여기에서 줄 끝 설정을 변경 한 후 저장소를 새로 고치는 방법에 대해 자세히 알아 보십시오 . Tldr :
Git으로 파일을 백업하고 저장소의 모든 파일 (.git 디렉터리 제외)을 삭제 한 다음 파일을 모두 한 번에 복원합니다. 작업 내용이 손실되지 않도록 현재 파일을 Git에 저장합니다.
git add . -u
git commit -m "Saving files before refreshing line endings"색인을 제거하고 Git이 작업 디렉토리를 다시 검색하도록합니다.
rm .git/indexGit 인덱스를 다시 작성하여 모든 새 줄 끝을 선택하십시오.
git reset다시 작성되고 정규화 된 파일을 표시합니다.
어떤 경우에는 이것이 완료되어야하는 전부입니다. 다른 사용자는 다음 추가 단계를 완료해야 할 수 있습니다.
git statusAdd all your changed files back, and prepare them for a commit. This is your chance to inspect which files, if any, were unchanged.
git add -uIt is perfectly safe to see a lot of messages here that read[s] "warning: CRLF will be replaced by LF in file."
Rewrite the .gitattributes file.
git add .gitattributesCommit the changes to your repository.
git commit -m "Normalize all the line endings"
I use both windows and linux, but the solution core.autocrlf true didn't help me. I even got nothing changed after git checkout <filename>.
So I use workaround to substitute git status - gitstatus.sh
#!/bin/bash
git status | grep modified | cut -d' ' -f 4 | while read x; do
x1="$(git show HEAD:$x | md5sum | cut -d' ' -f 1 )"
x2="$(cat $x | md5sum | cut -d' ' -f 1 )"
if [ "$x1" != "$x2" ]; then
echo "$x NOT IDENTICAL"
fi
done
I just compare md5sum of a file and its brother at repository.
Example output:
$ ./gitstatus.sh
application/script.php NOT IDENTICAL
application/storage/logs/laravel.log NOT IDENTICAL
I created a script to ignore differences in line endings:
It will display the files which are not added to the commit list and were modified (after ignoring differences in line endings). You can add the argument "add" to add those files to your commit.
#!/usr/bin/perl
# Usage: ./gitdiff.pl [add]
# add : add modified files to git
use warnings;
use strict;
my ($auto_add) = @ARGV;
if(!defined $auto_add) {
$auto_add = "";
}
my @mods = `git status --porcelain 2>/dev/null | grep '^ M ' | cut -c4-`;
chomp(@mods);
for my $mod (@mods) {
my $diff = `git diff -b $mod 2>/dev/null`;
if($diff) {
print $mod."\n";
if($auto_add eq "add") {
`git add $mod 2>/dev/null`;
}
}
}
Source code: https://github.com/lepe/scripts/blob/master/gitdiff.pl
Updates:
- fix by evandro777 : When the file has space in filename or directory
'Program Club' 카테고리의 다른 글
| _를 어떻게 제거합니까? (0) | 2020.11.21 |
|---|---|
| Windows에서 cd / d % ~ dp0 명령은 무엇을 의미합니까? (0) | 2020.11.20 |
| Haskell의 <|> 연산자는 무엇을합니까? (0) | 2020.11.20 |
| 한 쪽이 다른 쪽을 가리켜도 / bin / sh가 / bin / bash와 다르게 동작하는 이유는 무엇입니까? (0) | 2020.11.20 |
| SyncRoot 패턴의 용도는 무엇입니까? (0) | 2020.11.20 |