큰 Git 저장소를 여러 개의 작은 저장소로 분할
SVN 리포지토리를 Git으로 성공적으로 변환 한 후 이제 여러 개의 작은 리포지토리로 나누고 기록을 유지하려는 매우 큰 Git 리포지토리를 갖게되었습니다.
따라서 누군가 다음과 같은 저장소를 분해하는 데 도움을 줄 수 있습니까?
MyHugeRepo/
.git/
DIR_A/
DIR_B/
DIR_1/
DIR_2/
다음과 같은 두 개의 저장소로 :
MyABRepo/
.git
DIR_A/
DIR_B/
My12Repo/
.git
DIR_1/
DIR_2/
이 이전 질문에서 지침을 따르려고 시도했지만 여러 디렉토리를 별도의 저장소에 넣으려고 할 때 실제로 적합하지 않습니다 ( Detach (move) subdirectory into separate Git repository ).
그러면 MyABRepo가 설정됩니다. 물론 My12Repo도 비슷하게 할 수 있습니다.
git clone MyHugeRepo/ MyABRepo.tmp/
cd MyABRepo.tmp
git filter-branch --prune-empty --index-filter 'git rm --cached --ignore-unmatch DIR_1/* DIR_2/*' HEAD
.git / refs / original / refs / heads / master에 대한 참조가 남아 있습니다. 다음과 같이 제거 할 수 있습니다.
cd ..
git clone MyABRepo.tmp MyABRepo
모든 것이 잘 되었다면 MyABRepo.tmp를 제거 할 수 있습니다.
어떤 이유로 .git-rewrite와 관련된 오류가 발생하면 다음을 시도 할 수 있습니다.
git clone MyHugeRepo/ MyABRepo.tmp/
cd MyABRepo.tmp
git filter-branch -d /tmp/git-rewrite.tmp --prune-empty --index-filter 'git rm --cached --ignore-unmatch DIR_1/* DIR_2/*' HEAD
cd ..
git clone MyABRepo.tmp MyABRepo
이렇게하면 /tmp/git-rewrite.tmp가 대신 임시 디렉토리로 만들어지고 사용됩니다 .git-rewrite
. 당연히 /tmp/git-rewrite.tmp
쓰기 권한이 있고 디렉토리가 아직 존재하지 않는 한 대신 원하는 경로를 대체 할 수 있습니다.
git filter-branch --index-filter
with git rm --cached
를 사용 하여 원래 저장소의 복제본 / 복사본에서 원하지 않는 디렉토리를 삭제할 수 있습니다 .
예를 들면 :
trim_repo() { : trim_repo src dst dir-to-trim-out...
: uses printf %q: needs bash, zsh, or maybe ksh
git clone "$1" "$2" &&
(
cd "$2" &&
shift 2 &&
: mirror original branches &&
git checkout HEAD~0 2>/dev/null &&
d=$(printf ' %q' "$@") &&
git for-each-ref --shell --format='
o=%(refname:short) b=${o#origin/} &&
if test -n "$b" && test "$b" != HEAD; then
git branch --force --no-track "$b" "$o"
fi
' refs/remotes/origin/ | sh -e &&
git checkout - &&
git remote rm origin &&
: do the filtering &&
git filter-branch \
--index-filter 'git rm --ignore-unmatch --cached -r -- '"$d" \
--tag-name-filter cat \
--prune-empty \
-- --all
)
}
trim_repo MyHugeRepo MyABRepo DIR_1 DIR_2
trim_repo MyHugeRepo My12Repo DIR_A DIR_B
각 저장소의 불필요한 브랜치 또는 태그를 수동으로 삭제해야합니다 (예 : feature-x-for-AB 브랜치가있는 경우 "12"저장소에서 삭제할 수 있음).
git_split 프로젝트는 찾고있는 것을 정확히 수행하는 간단한 스크립트입니다. https://github.com/vangorra/git_split
Turn git directories into their very own repositories in their own location. No subtree funny business. This script will take an existing directory in your git repository and turn that directory into an independent repository of its own. Along the way, it will copy over the entire change history for the directory you provided.
./git_split.sh <src_repo> <src_branch> <relative_dir_path> <dest_repo>
src_repo - The source repo to pull from.
src_branch - The branch of the source repo to pull from. (usually master)
relative_dir_path - Relative path of the directory in the source repo to split.
dest_repo - The repo to push to.
Here is a ruby script that will do it. https://gist.github.com/4341033
Thanks for your answers but I ended up just copying the repository twice then deleting the files I didn't want from each. I am going to use the filter-branch at a later date to strip out all the commits for the deleted files since they are already version controlled elsewhere.
cp -R MyHugeRepo MyABRepo
cp -R MyHugeRepo My12Repo
cd MyABRepo/
rm -Rf DIR_1/ DIR_2/
git add -A
git commit -a
This worked for what I needed.
EDIT: Of course, the same thing was done in the My12Repo against the A and B directory. This gave me two repos with identical history up to the point I deleted the unwanted directories.
참고URL : https://stackoverflow.com/questions/3910412/split-large-git-repository-into-many-smaller-ones
'development' 카테고리의 다른 글
C ++에서 "자유 기능"이라는 용어의 의미는 무엇입니까? (0) | 2020.09.19 |
---|---|
HTML 문서 형식 (0) | 2020.09.19 |
설명 $ CI = & get_instance (); (0) | 2020.09.19 |
중괄호가 없을 때 Ruby에서 문자열 보간이 작동하는 이유는 무엇입니까? (0) | 2020.09.19 |
Python-IndexError : py2exe를 사용할 때 튜플 인덱스가 범위를 벗어났습니다. (0) | 2020.09.19 |