리포지토리를 가져온 후 생성 된 원격 브랜치에 대해 git-svn에 알리려면 어떻게해야합니까?
git-svn
회사의 중앙 svn
저장소 에 대해 작업 하는 데 사용 하고 있습니다 . 우리는 최근에 중앙 저장소에 새로운 기능 분기를 만들었습니다. git
그것에 대해 어떻게 알 수 있습니까? 실행할 git branch -r
때 리포지토리를 실행 fetch
하여 svn
리포지토리를 초기화 할 때 존재했던 분기 만 볼 수 git
있습니까?
원격 지점을 수동으로 추가 할 수 있습니다.
git config --add svn-remote.newbranch.url https://svn/path_to_newbranch/
git config --add svn-remote.newbranch.fetch :refs/remotes/newbranch
git svn fetch newbranch [-r<rev>]
git checkout -b local-newbranch -t newbranch
git svn rebase newbranch
모든 원격 svn 분기를 추적하려는 경우 솔루션은 다음과 같이 간단합니다.
git svn fetch
아직 가져 오지 않은 모든 원격 브랜치를 가져옵니다.
추가 팁 : 처음에 트렁크 만 체크 아웃 한 다음 나중에 모든 분기를 추적 .git/config
하려면 다음과 같이 편집 하고 다시 실행하십시오 git svn fetch
.
[svn-remote "svn"]
url = https://svn/path_to_repo_root/
fetch = path_to_trunk:refs/remotes/git-svn
branches = path_to_branches/*:refs/remotes/*
요점은 url
리포지토리 루트를 가리키고에 정의 된 경로 fetch
와 branches
상대 경로 여야합니다 url
.
ALL 대신 특정 분기 만 가져 오려면 다음과 같은 좋은 예가 있습니다 git svn --help
.
[svn-remote "huge-project"]
url = http://server.org/svn
fetch = trunk/src:refs/remotes/trunk
branches = branches/{red,green}/src:refs/remotes/branches/*
tags = tags/{1.0,2.0}/src:refs/remotes/tags/*
의 이전 버전에서는 이와 git-svn
같이 분기를 지정하면으로 새 분기를 얻지 못할 수 있습니다 git svn fetch
. 한 가지 해결 방법은 fetch
다음과 같이 줄을 추가하는 것입니다 .
[svn-remote "huge-project"]
url = http://server.org/svn
fetch = trunk/src:refs/remotes/trunk
fetch = branches/blue:refs/remotes/branches/blue
fetch = branches/yellow:refs/remotes/branches/yellow
branches = branches/{red,green}/src:refs/remotes/branches/*
@AndyEstes의 또 다른 해결 방법 : 새로 지정된 분기 또는 태그를 만들기 전에 .git/svn/.metadata
값을 수정 branches-maxRev
하거나 tags-maxRev
수정합니다. 이 작업을 완료 git svn fetch
하면 새로운 svn 원격 분기를 추적하도록 실행 하십시오.
방금 필요한 것 같습니다 git svn fetch
. 어떻게 든 변경 사항 대신 전체 저장소를 가져올 것이라고 스스로 확신했습니다.
어쩌면 나는 어쨌든 그것을 엉망으로 만들었지 만 vjangus의 답변에있는 지침을 따르고 거의 효과가있었습니다. 유일한 문제는 뉴 브랜치가 트렁크에서 분기되지 않은 것입니다. gitk에서, 그것은 스스로 "떠 다니는"종류였다. 트렁크와 공통 조상이 없었습니다.
이에 대한 해결책은 다음과 같습니다.
- 분기를 만들기 전에 트렁크에서 발생한 마지막 커밋의 SHA1을 찾습니다.
- 새 브랜치에서 첫 번째 커밋의 SHA1을 찾으십시오 (메시지는 아마도 "Created new branch, copy from trunk @ 12345"또는 다른 것입니다)
git diff-tree <sha1 from step 1> <sha1 from step 2>
-출력이 없어야합니다. 출력이 있으면 잘못된 커밋을 선택했을 수 있습니다.git checkout local-newbranch
그때git rebase <sha1 from step 1>
.local-newbranch
새 트리로 리베이스 되지만remotes/newbranch
여전히 연결이 끊어집니다.- 파일로 이동하여 현재 가리키는 이전 커밋에 해당하는 새로운 커밋
.git/refs/remotes/newbranch
의 전체 SHA1 (rebased에 있음 ) 을 포함하도록 편집하십시오 . (또는 어쩌면 사용하십시오 . 감사합니다.)newbranch
git-update-ref refs/remotes/newbranch <new-SHA>
- 다음 번에 당신이
git svn dcommit
할newbranch
, 당신은 몇 가지 로그를 업데이트 그것에 대해 메시지의 무리를 얻을 수 있습니다. 이것은 정상적인 것입니다.
gitk --all
하루 종일 열어 두고 자주 새로 고쳐서 수행중인 작업을 추적하는 것이 좋습니다. 나는 여전히 git 및 git svn을 처음 사용 하므로이 방법의 개선을 제안하십시오.
vjangus의 답변 단순화 :
SVN에서 표준 레이아웃을 사용하고 일반적인 svn init을 수행했다면 git-svn이 구성 작업을 수행합니다. 다만:
- SVN에서 분기 복사 수정본 찾기
- git-svn으로 그 개정판 가져 오기
- 새로운 로컬 지점 추적 원격 생성
예입니다. SVN URL은 svn+ssh://gil@svn.myplace.com/repo
입니다. 내가 찾고있는 SVN 지점은 newbranch
입니다. 로컬 자식 브랜치 (트래킹 원격 newbranch
)가됩니다 git-newbranch
.
1 단계 : 분기 복사 개정판 찾기
# svn log --stop-on-copy svn + ssh : //gil@svn.myplace.com/repo/branches/newbranch | 꼬리 -4 r7802 | 누군가 | 2014-03-21 18:54:58 +0000 (2014 년 3 월 21 일 금요일) | 1 줄 HEAD를 새 가지로 분기 -------------------------------------------------- ----------------------
SVN의 분기점은 개정 7802입니다.
2 단계 : 개정판 가져 오기
# 자식 svn 가져 오기 -r 7802 Found possible branch point: svn+ssh://gil@svn.myplace.com/repo/trunk => svn+ssh://gil@svn.myplace.com/repo/branches/newbranch, 7801 Found branch parent: (refs/remotes/trunk) 8dcf3c5793ff1a8a79dc94d268c91c2bf388894a Following parent with do_switch Successfully followed parent r7802 = 9bbd4194041675ca5c9c6f3917e05ca5654a8a1e (refs/remotes/newbranch)
git-svn did all the work and now knows about the remote:
# git show-ref | grep newbranch 2df23af4733f36f5ad3c14cc1fa582ceeb3edb5c refs/remotes/newbranch
Step 3: Create your new local branch tracking the remote one:
# git checkout -b git-newbranch -t newbranch Checking out files: 100% (413/413), done. Branch git-newbranch set up to track local ref refs/remotes/newbranch. Switched to a new branch 'git-newbranch'
I have not found any documentation about this feature, but looks like git svn configuration supports multiple fetch entries. This way you can also add branches separately without need to add another remote svn repository entry to your config nor using wildcards to get all branches of certain directory.
Assume that your SVN tree is really nasty having lots of branches without any logic how they are located, e.g. having branches and sub-directories containing more branched.
i.e.
trunk
branches
-> branch1
-> sub-dir1
-> branch2
-> branch3
-> sub-dir2
-> branch4
-> sub-dir3
-> branchX
<... hundreds more ...>
and you just want to hand pick some of the branches to be included to your git repository.
You may first init your repository with only trunk without any additional branches:
git svn clone -r 10000:HEAD https://svn.com/MyRepo myrepo --prefix=svn/ --trunk=trunk
After that you should see following configuration:
localhost: elhigu$ git config --get-regexp "svn-remote."
svn-remote.svn.url https://svn.com/MyRepo
svn-remote.svn.fetch trunk:refs/remotes/svn/trunk
when ever you want to fetch new branch from MyRepo you can just add new fetch entries to configuration by:
git config --add svn-remote.svn.fetch branches/sub-dir2/branch4:refs/remotes/svn/branches/sub-dir2/branch4
Or you may edit the same configuration in .git/config
To fetch the new branches after adding them to config just run:
git svn fetch -r 10000:HEAD
[Edit] Sometimes it seems to be necessary to run fetch with --all parameter to fetch newly added branches:
git svn fetch --all -r 10000:HEAD
Instead of dealing with the git-svn quirks you may try SubGit.
One has to install SubGit into Subversion repository. After that one can use standard git workflow instead of using special git-svn commands:
Pushing new commits:
git-svn:
$ git commit $ git svn rebase $ git svn dcommit
SubGit:
$ git commit $ git push
Fetching incoming changes
git-svn:
$ git svn rebase
SubGit:
$ git pull [--rebase]
Creating a new branch:
git-svn:
$ git svn branch foo $ git checkout -b foo -t remotes/foo $ git commit $ git svn dcommit
SubGit:
$ git checkout -b foo $ git commit $ git push
See SubGit documentation for more details.
To add to vjangus' answer, which helped me, I also found it useful to add use git grafts to tie the branches to the trunk at the appropriate point - allowing git to see the history and perform merges correctly.
This is simply a case of adding a line to .git/info/grafts
with the hashes:
<initial branch commit> <parent commit in trunk>
eg.
378b0ae0902f5c2d2ba230c429a47698810532e5 6c7144991381ce347d4e563e9912465700be0638
Credit to http://evan-tech.livejournal.com/255341.html
(I'd add this as a comment, but I've not enough reputation.)
If you don't check out with a valid layout, you won't be able to checkout a remote branch.
This is what I do:
git svn init -s <svn path with no trunk> local_repo
cd local_repo
git svn fetch
## wait
After that, you can switch to a remote branch:
git checkout --track -b branch_name branch_name
Then you will automatically be switched to your branch.
'IT' 카테고리의 다른 글
Node.js의 HTML 파서 (0) | 2020.05.13 |
---|---|
Sublime Text 2에서 새 탭에서 새 파일을 어떻게 열 수 있습니까? (0) | 2020.05.13 |
포크와 exec의 차이점 (0) | 2020.05.13 |
Ruby에서 해시를 어떻게 복사합니까? (0) | 2020.05.13 |
UINavigationController에 오른쪽 버튼을 추가하는 방법? (0) | 2020.05.13 |