2012-03-28 3 views
31

core.autocrlf, core.eol + gitattributes (Tim's post is excellent)를 통해 힘내 자체가 라인 결말을 처리하는 방법에 대해 매우 만족합니다.git-svn은 어떻게 라인 엔딩을 처리합니까?

저는 autocrlftrue으로 설정된 Windows Git repo가 ​​있습니다. 따라서 모든 텍스트 파일은 저장소에 LF으로 저장되고 작업 디렉토리에 CRLF으로 저장됩니다. 이 레포는 SVN repo에서 복제되었습니다. SVN Repo는 SVN Repo에서 푸시/푸시하는 데 여전히 사용됩니다 (SVN Repo는 CI 등을 트리거하기위한 우리의 중심적이고 축복받은 레포입니다).

그러나 밀어 넣기/끌기 작업 중에 git-svn 줄 끝을 처리하는 방법을 모르겠습니다.

누군가이 경우에 git-svn이 무엇을 설명 할 수 있습니까?

답변

15

관심이 있으신 분도 있습니다. 당신이 자식 svn의 복제를 통해 만든 REPO를 가정하면, 당신이 세 가지 질문에 그것을 무너 뜨리는 수 있다고 생각 :

  1. 어떤 자식 줄 바꿈 정상화/변경은 SVN에서 커밋 이동에 시간을 가져 자식 SVN에서 발생합니까 빌어 먹을 레포에?
  2. git newline 정규화/변경은 git commit time [즉, 정상적인 지역 자식 동안 svn 리모컨 repo에 커밋? 병합/리베이스 시간은 어떨까요?
  3. git newline 정규화/변경은 git svn dcommit 시간에, svn에 대해 커밋하는 모든 것을 밀고/재생하면서/발생합니까?
내가 이론적으로 이러한 질문에 대한 진정한해야하는데 무엇을 듣고 싶지만, 지금 나는 경우 # 1 이상에는 줄 바꿈 정상화가 없음을 보여주는 것 같다 약간의 실험을했다

:

rem We'll make a svn repo with CRLF newlines, clone it into git with 
rem autocrlf enabled, and try to see if that results in LF-only newlines 
rem getting stored in the git repo 

cd c:\code 

rem Step 1. Prepare SVN repo with CRLF type newlines. 
rem The pre-1.4 flag is to prevent an error during git clone. 

svnadmin create --pre-1.4-compatible svnrepo 
svn checkout file:///C:/code/svnrepo svnworking 
cd svnworking 
echo "First line" > file.txt 
echo "Second line" >> file.txt 
echo "Third line" >> file.txt 
rem NOTE: At this point file.txt has CRLF newlines 
svn add file.txt 
svn commit -m "Add file.txt" 
rem NOTE: At this point file.txt still has CRLF newlines 
cd .. 

rem Step 2. Clone the svn repo into git and inspect work copy newline type 
git svn clone file:///C:/code/svnrepo gitrepo 
rem The following outputs true on my machine 
git config --get core.autocrlf 
cd gitrepo 
rem The following also outputs true on my machine 
git config --get core.autocrlf 
git svn fetch 
rem NOTE: At this point file.txt (git working dir copy) has CRLF newlines 

rem Step 3. Disable autocrlf to inspect repo's inner newline type 
rem Use the following and my editor to set core.autocrlf to false: 
git config --edit --local 
rem This now prints false: 
git config --get core.autocrlf 
git checkout . 
rem NOTE: At this point file.txt (git working dir copy) still has CRLF newlines 
del file.txt 
git checkout . 
rem NOTE: Even after explicitly deleting the old one and checking out again, 
rem file.txt still has CRLF newlines 

내 git svn pull 중에 git newline 변환이 발생했다면 대조적으로 file.txt에 LF 전용 newline이 있어야합니다. 요약

rem We'll a git repo with core.autocrlf on, then switch it off to 
rem pull out a file 

rem The following outputs true 
git config --get core.autocrlf 
git init gitcrtest 
cd gitcrtest 
rem The following still outputs true 
git config --get core.autocrlf 
echo "First line" > file.txt 
echo "Second line" >> file.txt 
echo "Third line" >> file.txt 
git add file.txt 
git commit -m "Add file.txt" 
rem NOTE: At this point file.txt (git working dir copy) has CRLF newlines 
rem Use the following to set core.autocrlf to false 
git config --edit --local 
git checkout . 
rem NOTE: Now file.txt (git working dir copy) has LF-only newlines 

: 여기

실제로 REPO는 LF 만 줄 바꿈이 있는지 여부의 유효한 테스트를 구현 위의 3 단계 전성 검사의 상기 내용을 토대로,이 자식 - svn의이 끌어 때 보인다 svn에서 svn 커밋은 autocrlf가 활성화되어 있어도 crlf 변환없이 git commit 그래프에 추가됩니다. 즉, 당신의 파일이 당신의 svn repo에있는 어떤 종류의 개행이라도, 그것들은 당신의 git clone에 가지고있을 것입니다. (그러나 여러분의 자식 작업 복사본은 개행 유형이 다를 수 있습니다.)

"git help attributes"의 줄 끝 정규화에 대한 설명과 상당히 일치합니다. 정규화는 레포에서 작업 디렉토리로 물건을 가져 오는 명령 (예 : 체크 아웃 또는 병합) 또는 작업 디렉토리의 항목을 색인/저장소 (예 : 추가 또는 커밋)로 이동시키는 명령으로 발생하는 것으로 나타납니다. "Git svn fetch"는 그 중 하나를 수행하는 것 같지 않으므로 그 시점에 end-of-line normalization이 일어나지 않을 것입니다. 나는 dcommit이하는 일에 대해 더 모호하기 때문에 그 시점에서 end-of-line normalization을 기대할 지 확신 할 수 없다.

참고 repo/machine에 SVN의 svn : eol-style 속성이 설정되어있는 경우 추가 주름이 있습니다.I 생각해 보면 SVN 기본값은 이 아니며은 끝 부분에서 줄 끝 변환을 수행하지만 100 % 확신 할 수는 없습니다.

업데이트 : 실제 줄 바꿈에 대한 svn-> git 마이그레이션 관점은 Tim Abell's description도 참조하십시오. git-svn은 CRLF 개행 문자를 LF 전용 개행 문자로 변환하지 않았고 git의 자동 EOL (end-of-line normalization)을 그대로 유지하면 이상적인 결과가 나타납니다. 해결책은 git에서 줄 끝을 표준화하거나 줄 끝 정규화를 비활성화하는 것이 었습니다.

+1

"SVN 기본값은 http://svnbook.red-bean.com/en/1.7/svn.advanced.props에 따르면 그 끝에서 줄 끝 변환을하지 않는 것이 맞습니다."맞습니다. file-portability.html "기본적으로 Subversion은 파일에 사용 된 EOL (end-of-line) 마커 유형에주의를 기울이지 않습니다." –

관련 문제