简体   繁体   中英

How do I track a remote public Subversion repository with a local Git repository?

I've been trying to figure this one out by reading the git-svn man-page but am having trouble understanding how to achieve it.

What I want to do is:

  1. Checkout a public subversion trunk
  2. Create a local git repo to track this
  3. Create a 'vendor' branch which I will not commit to and will only use for pulling changes from the subversion repo
  4. Create git branches for patches I wish to work on
  5. Pull updates to the 'vendor' branch and merge into my branches.
  6. Submit patches with git-format-patch

How do I achieve this?

Suggested workflow for git-svn:

  1. Pull using git-svn mentioned above.
  2. By default, you will be in master . DO NOT WORK DIRECTLY ON THIS BRANCH.
  3. Do all your development in a feature branch (use git checkout -b <feature> from master).
  4. Commit changes to your feature branch.
  5. Do git rebase master in your feature branch. 5a. If you want to pull in svn updates at this time, then switch to master and do git svn rebase . Then switch back to feature branch, do git rebase master .
  6. Switch to master branch and do git merge <feature> .
  7. Check that merge goes smoothly, then do git svn dcommit to push changes to svn.

Remember, once you do git svn dcommit all your changes will become visible to others. So be absolutely sure you have done things properly before doing git svn dcommit .

You want to use git-svn. I'm not sure what the state of available tutorials is, but here's some stuff to get you started.

Creating your local git repo.

How to git-svn clone the last n revisions from a Subversion repository?

To fetch new revisions from svn use git svn fetch . This will fetch new revisions and put them on a remote branch. You can make whatever changes you want on your own branch, then commit using git svn dcommit .

But, I would be careful with the git merge command. When using git-svn I always recommend using rebase, and making your history strictly linear. svn can't track git branches very well. If you have a branched history in git and try to push that to svn, svn will only be able to represent one half of that history. You won't lose any code, but you will lose granularity of your commits.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM