I'm using git-svn
to work against my company's central svn
repository. We've recently created a new feature branch in the central repo. How do I tell git
about it? When I run git branch -r
I can only see the branches that existed when I ran fetch
against the svn
repo to initialize my git
repo?
相关问题
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
- Upload file > 25 MB on Github
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- git: retry if http request failed
If you want to track ALL the remote svn branches, then the solution is as simple as:
This will fetch ALL the remote branches that have not been fetched yet.
Extra tip: if you checked out only the trunk at first, and later you want to track ALL branches, then edit
.git/config
to look like this and re-rungit svn fetch
:The key points are
url
should point to the repository root, and the paths defined infetch
andbranches
should be relative tourl
.If you want to fetch only specific branches instead of ALL, there is a nice example in
git svn --help
:With older versions of
git-svn
, once you specified branches like this, you might not be able to get new branches withgit svn fetch
. One workaround is adding morefetch
lines, like this:Another workaround by @AndyEstes: edit
.git/svn/.metadata
and change the value ofbranches-maxRev
ortags-maxRev
to a revision before any newly-specified branches or tags were created. Once you've done this, rungit svn fetch
to track the new svn remote branch.Maybe I messed it up somehow but I followed the instructions in vjangus' answer and it almost worked. The only problem was that newbranch didn't appear to be branched from the trunk. In gitk, it was kind of "floating" all on its own; it had no common ancestor with the trunk.
The solution to this was:
git diff-tree <sha1 from step 1> <sha1 from step 2>
-- there should be no output. If there is output, you may have selected the wrong commits.git checkout local-newbranch
thengit rebase <sha1 from step 1>
. This will rebaselocal-newbranch
onto the new tree butremotes/newbranch
will still be disconnected..git/refs/remotes/newbranch
and edit it to contain the full SHA1 of the new commit (on the rebasednewbranch
) that corresponds to the old commit it's currently pointing at. (Or maybe usegit-update-ref refs/remotes/newbranch <new-SHA>
. Thank you inger.)git svn dcommit
tonewbranch
, you'll get a bunch of messages about it updating some log. This is normal I think.I recommend keeping
gitk --all
open the whole time and refreshing it often to keep track of what you're doing. I'm still sort of new to git and git svn so please suggest improvements to this method.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:
After that, you can switch to a remote branch:
Then you will automatically be switched to your branch.
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.
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:
After that you should see following configuration:
when ever you want to fetch new branch from MyRepo you can just add new fetch entries to configuration by:
Or you may edit the same configuration in .git/config
To fetch the new branches after adding them to config just run:
[Edit] Sometimes it seems to be necessary to run fetch with --all parameter to fetch newly added branches:
It appears I just needed to
git svn fetch
; somehow I had convinced myself that would fetch the entire repo instead of just the changes.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:eg.
Credit to http://evan-tech.livejournal.com/255341.html
(I'd add this as a comment, but I've not enough reputation.)