Git 저장소 컨텐츠를 다른 저장소 보존 히스토리로 이동 만 다른 기존 저장소 (

다음 명령을 사용하여 한 저장소 ( repo1) 의 내용 만 다른 기존 저장소 ( repo2) 로 이동하려고 합니다.

git clone repo1
git clone repo2
cd repo1
git remote rm origin
git remote add repo1
git push

그러나 작동하지 않습니다. 비슷한 게시물을 검토했지만 내용이 아닌 폴더를 이동하는 것을 발견했습니다.



답변

찾고있는 명령은 다음과 같습니다.

cd repo2
git checkout master
git remote add r1remote **url-of-repo1**
git fetch r1remote
git merge r1remote/master --allow-unrelated-histories
git remote rm r1remote

그 후 와의 repo2/master모든 내용이 포함되며 둘 다의 역사도 갖게됩니다.repo2/masterrepo1/master


답변

https://www.smashingmagazine.com/2014/05/moving-git-repository-new-server/에 완벽하게 설명되어 있습니다.

먼저 기존 리포지토리에서 로컬 인덱스로 모든 원격 브랜치 및 태그를 가져와야합니다.

git fetch origin

로컬 복사본을 만들어야하는 누락 된 분기를 확인할 수 있습니다.

git branch -a

새 저장소의 SSH 복제 URL을 사용하여 기존 로컬 저장소에 새 원격을 작성하십시오.

git remote add new-origin git@github.com:manakor/manascope.git

이제 모든 로컬 브랜치 및 태그를 new-origin이라는 새 원격으로 푸시 할 준비가되었습니다.

git push --all new-origin
git push --tags new-origin

new-origin을 기본 리모컨으로 만들어 봅시다 :

git remote rm origin

new-origin의 이름을 origin으로 변경하여 기본 리모트가되도록하십시오.

git remote rename new-origin origin

답변

기존 지점을 보존하고 역사를 커밋하려는 경우 여기에 도움이되는 한 가지 방법이 있습니다.

git clone --mirror https://github.com/account/repo.git cloned-repo
cd cloned-repo
git push --mirror {URL of new (empty) repo}

# at this point only remote cloned-repo is correct, local has auto-generated repo structure with folders such as "branches" or "refs"
cd ..
rm -rf cloned-repo
git clone {URL of new (empty) repo}
# only now will you see the expected user-generated contents in local cloned-repo folder

# note: all non-master branches are avaialable, but git branch will not show them until you git checkout each of them
# to automatically checkout all remote branches use this loop:
for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done

이제 소스 및 대상 리포지토리를 일정 시간 동안 동기화 상태로 유지하려고한다고 가정합니다. 예를 들어, 현재 원격 저장소 내에서 여전히 새 / 대체 저장소로 가져 오려는 활동이 있습니다.

git clone -o old https://github.com/account/repo.git my-repo
cd my-repo
git remote add new {URL of new repo}

최신 업데이트를 풀다운하려면 (로컬 변경 사항이 없다고 가정) :

git checkout {branch(es) of interest}
git pull old
git push --all new

NB : 아직 서브 모듈을 사용하지 않았기 때문에 하위 모듈이있을 경우 어떤 추가 단계가 필요한지 모르겠습니다.


답변

코드가 이미 Git에 의해 추적 된 경우 가장 간단한 방법은 새 저장소를 “원본”으로 설정합니다.

cd existing-project
git remote set-url origin https://clone-url.git
git push -u origin --all
git push origin --tags

답변

이것은 내 로컬 리포지토리 (히스토리 포함)를 원격 github.com 리포지토리로 옮기는 데 효과적이었습니다. GitHub.com에서 새로운 빈 저장소를 생성 한 후 아래 3 단계에서 URL을 사용하면 효과적입니다.

git clone --mirror <url_of_old_repo>
cd <name_of_old_repo>
git remote add new-origin <url_of_new_repo>
git push new-origin --mirror

나는 이것을 https://gist.github.com/niksumeiko/8972566 에서 찾았다.


답변

아래의 방법을 사용하여 모든 지점과 커밋 기록을 유지하여 GIT Stash를 GitLab으로 마이그레이션했습니다.

이전 저장소를 로컬로 복제하십시오.

git clone --bare <STASH-URL>

GitLab에 빈 저장소를 만듭니다.

git push --mirror <GitLab-URL>

답변

당신이 가까이있는 것 같습니다. 제출시 오타가 아니라고 가정하면 3 단계 cd repo2는 repo1 대신에 있어야합니다. 그리고 6 단계는 git pull밀지 않아야합니다 . 재 작업 목록 :

1. git clone repo1
2. git clone repo2
3. cd repo2
4. git remote rm origin
5. git remote add repo1
6. git pull
7. git remote rm repo1
8. git remote add newremote