2012-10-26 4 views
1

나는 repo Arepo B이 있습니다. repo A에있는 프로젝트는 프로젝트에 따라 repo B에 달려 있습니다. 일부 사용자가 repo A에서 소스를 가져 오려고 시도 할 때 repo A에서 가져 오면 repo B의 소스도 일부 폴더에 있어야합니다. 나는 SVN이 다른 SVN 저장소에 어떤 SVN 저장소를 연결할 수있는 것을 보았다. git repos를 어떻게 연결할 수 있습니까?힘내 - 다른 저장소를 내 저장소에 연결하십시오.

감사합니다.

답변

3

힘내는 이것을 위해 submodules입니다.

예 :

$ git init repo_a 
Initialized empty Git repository in /Users/messa/temp/submodule-example/repo_a/.git/ 
$ git init repo_b 
Initialized empty Git repository in /Users/messa/temp/submodule-example/repo_b/.git/ 

$ cd repo_b 
$ echo 'This is Project B.' >> README.txt 
$ git add README.txt 
$ git commit -am 'Initial commit in B' 
[master (root-commit) 5158772] Initial commit in B 
1 file changed, 1 insertion(+) 
create mode 100644 README.txt 

$ cd ../repo_a 
$ echo 'This is Project A, that depends on Project B.' >> README.txt 
$ git add README.txt 
$ git commit -am 'Initial commit in A' 
[master (root-commit) 7e8275b] Initial commit in A 
1 file changed, 1 insertion(+) 
create mode 100644 README.txt 

$ git submodule add ../repo_b project_b 
Cloning into 'project_b'... 
done. 
$ git status 
# On branch master 
# Changes to be committed: 
# (use "git reset HEAD <file>..." to unstage) 
# 
# new file: .gitmodules 
# new file: project_b 
# 
$ git commit -am 'Added submodule project_b' 
[master c8fc469] Added submodule project_b 
2 files changed, 4 insertions(+) 
create mode 100644 .gitmodules 
create mode 160000 project_b 

$ tree 
. 
├── README.txt 
└── project_b 
    └── README.txt 

1 directory, 2 files 

당신은 정확히 repo_b에서 커밋 제어 할 수는 repo_a에서 연결됩니다.

자세한 내용은 git help submodule 또는 위 링크를 참조하십시오.

하지만 한 가지 문제가 있습니다. 누군가가 repo_a를 복제하면 project_b가 있지만 빈 것입니다. git clone 이후에 git submodule initgit submodule update이 필요합니다.

서브 모듈에 대한 실제 경험이 없지만 비판을 보았습니다 (예 : this article). 대부분의 문제를 피하기 위해 올바른 워크 플로를 선택하는 것이 중요하다고 생각합니다.

관련 문제