Add git branch after initial fetch in the same svn

2019-03-15 01:01发布

I'm using git-svn to work with a svn repo. I don't want the whole repo, sine it contains a lot of legacy, with binaries in it. I'm only tracking some directories.

Here is my current .git/config, which is working fine.

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[svn-remote "svn"]
    url = https://svn.example.com/repository
    fetch = trunk/Python:refs/remotes/trunk
    branches = branches/{stage,prod,stage_with_proxy}/ucapi/:refs/remotes/*
    branches = branches/{active}/Python/:refs/remotes/*

Now I want to add a new branch:

    branches = branches/{fuze_node}/:refs/remotes/*

but when doing git svn fetch the new branch is not visible to git. It acts as if the line is not in the config.


I know this could be done with a new svn-remote, but I would prefer not to take that road.

标签: git svn git-svn
1条回答
Viruses.
2楼-- · 2019-03-15 01:34

For every svn-remote git-svn stores the latest fetched revision in .git/svn/.metadata file. It never fetches revisions less than that value. That's why it doesn't fetch the branch you've added to config; git-svn thinks fuze_node branch is already converted.

However you can fetch this branch without re-cloning the whole repository once again:

  1. Add another svn-remote with all the branches you need to fetch;
  2. Remove the older svn-remote;
  3. Run git svn fetch -R newer-svn-remote to fetch revisions from the added branch.

Your config should look like this:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
# [svn-remote "svn"]
#    url = https://svn.example.com/repository
#    fetch = trunk/Python:refs/remotes/trunk
#    branches = branches/{stage,prod,stage_with_proxy}/ucapi/:refs/remotes/*
#    branches = branches/{active}/Python/:refs/remotes/*
[svn-remote "newer-svn-remote"]
    url = https://svn.example.com/repository
    fetch = trunk/Python:refs/remotes/trunk
    branches = branches/{stage,prod,stage_with_proxy}/ucapi/:refs/remotes/*
    branches = branches/{active}/Python/:refs/remotes/*
    branches = branches/{fuze_node}/:refs/remotes/*

Note that you have to specify exactly the same branches mapping as in the older svn-remote:

    branches = branches/{stage,prod,stage_with_proxy}/ucapi/:refs/remotes/*

That is, refs/remotes/* should still be on the right side of the mappings. Otherwise git-svn fails to detect already converted commits and tries to fetch them once again.


There's actually another way to achieve the same. It involves some manipulations with internal git-svn files though.

You can just add necessary branch to .git/config and update .git/svn/.metadata file, so the latest fetched revision becomes 0:

[svn-remote "svn"]
    reposRoot = https://svn.example.com/repository
    uuid = 8a6ef855-a4ab-4527-adea-27b4edd9acb6
    branches-maxRev = 0
    tags-maxRev = 0

After that git svn fetch will fetch only necessary revisions.

查看更多
登录 后发表回答