2012-09-25 2 views
4

내 다른 프로젝트 (B)와 일정량의 코드를 공유하는 큰 자식 저장소 (A)가 있습니다. 유지 보수를 쉽게하기 위해 공통 코드 (C)가있는 세 번째 저장소를 가지고 다음 git subtree을 통해 사용하기로 결정했습니다.자식 하위 트리 내보내기 및 다시 가져 오기

나는 A의 모든 (폴더 "하위"의 공통 코드를 넣어)를 준비하고 내가 몇 커밋과 C를 가지고, 내가 넣어 싶어 이제

C를 만들 Detach (move) subdirectory into separate Git repository에 설명 된 절차를 사용 다시 A, 폴더 하위로. 하위 폴더에 대한 모든 커밋이 중복 된 경우에만 작업 한 http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html에 설명 된 방법을 사용했습니다. 나는 이것에 대해별로 신경 쓰지 않았다. 그러나이 서브 디렉토리로 작업을 계속하는 방법을 모르겠다.

나는 git subtree push changes back to subtree project에 설명 된대로 난 그냥 하위 트리에 지점을 만들
git subtree split --prefix sub -b split-branch 

를 사용 내가 C로 밀어 원하는 A/하위에 추가 변경을했다. 이것은 약간의 시간이 걸리지 만 성공적으로 완료됩니다.

git checkout split-branch 
git push remote-c master 

을하는 것은 나에게

failed to push some refs to "remote-c" 
hint: Updates were rejected because a pushed branch tip is behind its remote 
hint: counterpart. Check out this branch and merge the remote changes 
hint: (e.g. 'git pull') before pushing again. 

을 제공하지만 git pull remote-c master가 이미 래요 - - 날짜.

이 상황을 어떻게 해결합니까?

EDIT1 : 작은 테스트 스크립트로 문제를 재현하려고했습니다. 이 스크립트를 실행 :

(cd testC; git init --bare) 
(cd testA; git init) 

cd testA 
git remote add C ../testC 

mkdir sub 
echo subFile1 > sub/subFile1 
echo subFile2 > sub/subFile2 
git add sub 
git commit -m "adding files" 

echo FileA > fileA 
echo FileB > fileB 
git add fileA fileB 
git commit -m "add root level files" 

# extract subtree and push to C 
git subtree split -P sub -b split-branch 
git push C split-branch:master 

# try to make an update in C 
git checkout -b cmaster C/master 
echo subFile2new > subFile2 
git commit subFile2 -m "updated #2 in C" 
git push 

이 결과

To ../testC 
! [rejected]  master -> master (non-fast-forward) 
error: failed to push some refs to '../testC' 
hint: Updates were rejected because a pushed branch tip is behind its remote 
hint: counterpart. If you did not intend to push that branch, you may want to 
hint: specify branches to push or set the 'push.default' configuration 
hint: variable to 'current' or 'upstream' to push only the current branch. 
+0

내가하려는 일을 이해한다면,'git' 서브 모듈이 상수 서브 트리 병합/추출보다 나은 해결책이라고 생각합니다. – twalberg

+0

나는 chit submodule을 사용하는 것보다는 CVS로 돌아가고 싶다 ;-) 나는 이것을 한번 시도했지만 여전히 악몽을 꾼다. – Frankie

+0

FYI, http://codingkilledthecat.wordpress.com/2012/04/28/why-your-company-shouldnt-use-git-submodules/에서는 서브 모듈 관련 문제를 설명합니다. – Frankie

답변

1

에 나는 일 것으로 보인다 git push -f을 시도했다. 아직도 정확히 무슨 일이 일어 났는지, 왜 그런지 알고 싶습니다.

+1

조심해서 로컬 저장소의'master' 브랜치를'C/master'에 넣었을 수도 있습니다. – LopSae

0

git push의 기본 동작은 동일한 브랜치가 로컬 및 원격으로있는 경우 모든 브랜치를 현재 브랜치 원격으로 푸시하려고하는 것입니다.

특수 refspec : (또는 + : 비 빨리 감기 업데이트를 허용하는) 는 "일치"지점을 밀어 자식을 지시 : 로컬 측에 존재하는 모든 지점에 대해, 상기 git push 매뉴얼에서 원격 측에 동일한 이름 인 브랜치가 이미 존재하면 원격 측은 갱신됩니다. 명시 적 refspec가 발견되지 않으면 기본 동작 모드입니다 ( 은 명령 줄이나 해당 원격 파일의 푸시 라인이 아닙니다. 아래 참조). 푸시 .default 구성 변수가 설정되어 있지 않습니다. 이 경우

, 현재 리모컨 C이며 모두 로컬 master 원격 C/master이 추진됩니다 있고, 나무가 전혀 일치하지 때문에 푸시는 master -> master (non-fast-forward) 메시지와 함께 실패 할 것이기 때문이다.

브랜치에 git pull이있는 경우 최신 브랜치를 가져 오기 때문에 up-to-date라고 표시됩니다.

git push의 동작을 수정하려면 자식 설정에서 push.default 값을 설정해야합니다. http://www.kernel.org/pub/software/scm/git/docs/git-config.html

0

내 해결책 : upgrade git에서 "push.default"를 찾습니다. :-)

testAtestC 디렉토리가 이미 존재한다고 가정하면 테스트 스크립트가 성공합니다. 나는 git (v1.8.2.1)의 최신 버전을 사용하고 있으므로 게시 한 이후로 뭔가 수정했을 것입니다.

$ mkdir testA testC 
$ ./test.sh 
Initialized empty Git repository in /tmp/git/testC/ 
Initialized empty Git repository in /tmp/git/testA/.git/ 
[master (root-commit) 3d5644d] adding files 
2 files changed, 2 insertions(+) 
create mode 100644 sub/subFile1 
create mode 100644 sub/subFile2 
[master 398c203] add root level files 
2 files changed, 2 insertions(+) 
create mode 100644 fileA 
create mode 100644 fileB 
Created branch 'split-branch' 
57fe3e8fc226d854b623f11444d82dc77fd45682 
Counting objects: 4, done. 
Delta compression using up to 16 threads. 
Compressing objects: 100% (2/2), done. 
Writing objects: 100% (4/4), 269 bytes, done. 
Total 4 (delta 0), reused 0 (delta 0) 
To ../testC 
* [new branch]  split-branch -> master 
Branch cmaster set up to track remote branch master from C. 
Switched to a new branch 'cmaster' 
[cmaster 07c7c89] updated #2 in C 
1 file changed, 1 insertion(+), 1 deletion(-) 
Counting objects: 5, done. 
Delta compression using up to 16 threads. 
Compressing objects: 100% (2/2), done. 
Writing objects: 100% (3/3), 285 bytes, done. 
Total 3 (delta 0), reused 0 (delta 0) 
To ../testC 
    57fe3e8..07c7c89 cmaster -> master