git은 공백과 탭을 자동으로 전환 할 수 있습니까?
파이썬 프로그램에서 들여 쓰기에 탭을 사용하지만 대신 공백을 사용하는 사람들과 협력하고 싶습니다 (git 사용).
푸시 / 페치시 git이 공백과 탭 (예 : 4 공백 = 1 탭) 사이를 자동으로 변환하는 방법이 있습니까? (CR / LF 변환과 유사)
완벽한 솔루션은 다음과 같습니다.
저장소에서 .git/info/attributes
다음을 포함 하는 파일 을 추가하십시오 .
*.py filter=tabspace
리눅스 / 유닉스
이제 다음 명령을 실행하십시오 :
git config --global filter.tabspace.smudge 'unexpand --tabs=4 --first-only'
git config --global filter.tabspace.clean 'expand --tabs=4 --initial'
OS X
먼저 brew와 함께 coreutils를 설치하십시오.
brew install coreutils
이제 다음 명령을 실행하십시오 :
git config --global filter.tabspace.smudge 'gunexpand --tabs=4 --first-only'
git config --global filter.tabspace.clean 'gexpand --tabs=4 --initial'
모든 시스템
이제 프로젝트의 모든 파일을 확인할 수 있습니다. 당신은 그것을 할 수 있습니다 :
git checkout HEAD -- **
모든 파이썬 파일에는 공백 대신 탭이 있습니다.
편집 : 강제 체크 아웃 명령이 변경되었습니다. 물론 일을 먼저해야합니다.
예, 잠재적 해결책 중 하나는 git 속성 필터 드라이버 ( GitPro book 참조 )를 사용하여 얼룩 / 청소 메커니즘을 정의하는 것입니다.
그런 식으로:
- repo의 일부 파일을 체크 아웃 할 때마다 공백이 탭에서 변환 될 수 있습니다.
- 그러나 체크인 (및 푸시 및 게시) 할 때 동일한 파일은 공백 만 사용하여 다시 저장됩니다.
Git 저장소 내의 모든 파일에 적용되는 필터에 대해이 필터 드라이버 (여기 이름은 ' tabspace
')를 .git/info/attributes
다음 내용으로 선언 할 수 있습니다 .
*.py filter=tabspace
이제 다음 명령을 실행하십시오 :
# local config for the current repo
git config filter.tabspace.smudge 'script_to_make_tabs'
git config filter.tabspace.clean 'script_to_make_spaces'
이러한 얼룩 / 깨끗한 지침 세트의 구체적인 작업 예는 Olivier 의 답변 을 참조하십시오 .
GitHub (또는 기타 유사한 서비스)를 사용하는 모든 사람에게 매우 유용한 정보
~/.gitconfig
[filter "tabspace"]
smudge = unexpand --tabs=4 --first-only
clean = expand --tabs=4 --initial
[filter "tabspace2"]
smudge = unexpand --tabs=2 --first-only
clean = expand --tabs=2 --initial
그런 다음 두 개의 파일이 있습니다. attributes
*.js filter=tabspace
*.html filter=tabspace
*.css filter=tabspace
*.json filter=tabspace
과 attributes2
*.js filter=tabspace2
*.html filter=tabspace2
*.css filter=tabspace2
*.json filter=tabspace2
개인 프로젝트 작업
mkdir project
cd project
git init
cp ~/path/to/attributes .git/info/
That way, when you finally push your work on github, it won't look silly in the code view with 8 space tabs
which is default behavior in all browsers.
Contributing to other projects
mkdir project
cd project
git init
cp ~/path/to/attributes2 .git/info/attributes
git remote add origin git@github.com:some/repo.git
git pull origin branch
That way you can work with normal tabs on 2 space indented
projects.
Of course you can write similar solution for converting from 4 space to 2 space
which is the case if you want to contribute to projects published by me and you tend to use 2 spaces while developing.
If you are on windows then you have a few extra steps to get @Olivier Verdier's solution to work.
- Download CoreUtils for windows
- After installing put the install location in your PATH (How to add a path variable)
- Windows 확장 유틸리티가 이미 있으므로 expand.exe의 이름을 gexpand.exe로 변경했습니다.
참고 URL : https://stackoverflow.com/questions/2316677/can-git-automatically-switch-between-spaces-and-tabs
'Programming' 카테고리의 다른 글
F- 문자열로 소수점 이하의 고정 숫자 (0) | 2020.05.12 |
---|---|
SELECT 문에서 NOLOCK 힌트의 영향 (0) | 2020.05.12 |
MySQL 인덱스-모범 사례는 무엇입니까? (0) | 2020.05.12 |
C ++ 11 범위 기반 루프 : 값으로 항목 가져 오기 또는 const 참조 (0) | 2020.05.12 |
CheckBox의 색상을 변경하는 방법은 무엇입니까? (0) | 2020.05.11 |