What is the correct way to convert SVN remote branches and tags into local Git branches/tags during SVN to Git migration

后端 未结 5 640
庸人自扰
庸人自扰 2020-12-30 15:00

What is the correct way to make the remote branches/tags that exist after a git-svn init/git-svn fetch into local Git branches/tags before pushing to my remote Git repo and

相关标签:
5条回答
  • 2020-12-30 15:14

    This is a example on how to convert one of these branch references to a tag:

    # rename the branch reference
    git branch -t rel_20101019 remotes/svn/tags/rel_20101019
    
    # checkout the branch
    git checkout rel_20101019
    
    # create the tag for it
    git tag rel_20101019
    
    # go back to master
    git checkout master
    
    # delete the branch
    git branch rel_20101019 –d
    
    # now you can push your branch and tag changes to your origin
    git push origin –all
    git push origin –tags
    
    0 讨论(0)
  • 2020-12-30 15:17

    There is no easy/straightforward way to convert SVN tag-branches to native git tags after git svn conversion. There are number of scripts out there to convert SVN tags but most of them merely tag-&-remove corresponding branches outside of "master" branch so new tags won't show up in commits history even if "master" have commits identical to the tagged ones.

    In order to solve this problem I ended up writing my own utility "git-svn-convert-tags" which finds and tags commits identical to SVN "tags" within "master" branch. The logic is simple: utility compares all commits in current branch (e.g. "master") to tag-branches' HEADs. When binary-identical commit is found new tag is assigned and SVN tag-branch is deleted. Using this approach I've managed to successfully convert tags in many git-svn imported repositories to perfect git tag layout.

    0 讨论(0)
  • 2020-12-30 15:36

    To do exactly that you want just use SubGit project. You can install it into your SVN repository. So that a linked Git repository is created (with SVN tags translated to Git tags, svn:ignores to .gitignore and so on). That Git repository is kept in sync with the SVN repository: when you push to a Git repository, this changes is translated to the SVN repository, and vice versa.

    If you need client-only solution, I would recommend you to use SmartGit. It also preserves SVN concepts in Git repository.

    And what I wouldn't recommend you to use it git-svn.

    0 讨论(0)
  • 2020-12-30 15:37

    According to an answer on Git mailing list, I don't need to convert these branches into local ones before pushing them to my remote repo. I just need to do:

    git push <remote_git_repo_name> svn/<branch-name>:refs/heads/<branch-name>
    
    0 讨论(0)
  • 2020-12-30 15:40

    For a one-shot operation like this, before leaving behind a SVN repo, I like to clone it using the ruby script svn2git

    === Examples

    Say I have this code in svn:

      trunk
        ...
      branches
        1.x
        2.x
      tags
        1.0.0
        1.0.1
        1.0.2
        1.1.0
        2.0.0
    

    git-svn will go through the commit history to build a new git repo.
    It will import all branches and tags as remote svn branches, whereas what you really want is git-native local branches and git tag objects.
    So after importing this project I'll get:

      $ git branch
      * master
      $ git branch -a
      * master
        1.x
        2.x
        tags/1.0.0
        tags/1.0.1
        tags/1.0.2
        tags/1.1.0
        tags/2.0.0
        trunk
      $ git tag -l
      [ empty ]
    

    After svn2git is done with your project, you'll get this instead:

      $ git branch
      * master
        1.x
        2.x
      $ git tag -l
        1.0.0
        1.0.1
        1.0.2
        1.1.0
        2.0.0
    
    0 讨论(0)
提交回复
热议问题