NAME
git-svn - Bidirectional operation between a Subversion repository and Git
SYNOPSIS
- git svn <command> [<options>] [<arguments>]
DESCRIPTION
git svn is a simple conduit for changesets between Subversion and Git.It provides a bidirectional flow of changes between a Subversion and a Gitrepository.
git svn can track a standard Subversion repository,following the common "trunk/branches/tags" layout, with the —stdlayout option.It can also follow branches and tags in any layout with the -T/-t/-b options(see options to init below, and also the clone command).
Once tracking a Subversion repository (with any of the above methods), the Gitrepository can be updated from Subversion by the fetch command andSubversion updated from Git by the dcommit command.
COMMANDS
- init
- Initializes an empty Git repository with additionalmetadata directories for git svn. The Subversion URLmay be specified as a command-line argument, or as fullURL arguments to -T/-t/-b. Optionally, the targetdirectory to operate on can be specified as a secondargument. Normally this command initializes the currentdirectory.
- -T
- —trunk=
- -t
- —tags=
- -b
- —branches=
- -s
- —stdlayout
These are optional command-line options for init. Each ofthese flags can point to a relative repository path(—tags=project/tags) or a full url(—tags=https://foo.org/project/tags).You can specify more than one —tags and/or —branches options, in caseyour Subversion repository places tags or branches under multiple paths.The option —stdlayout isa shorthand way of setting trunk,tags,branches as the relative paths,which is the Subversion default. If any of the other options are givenas well, they take precedence.
Set the noMetadata option in the [svn-remote] config.This option is not recommended, please read the _svn.noMetadata_section of this manpage before using this option.
Set the useSvmProps option in the [svn-remote] config.
Set the useSvnsyncProps option in the [svn-remote] config.
Set the rewriteRoot option in the [svn-remote] config.
Set the rewriteUUID option in the [svn-remote] config.
For transports that SVN handles authentication for (http,https, and plain svn), specify the username. For othertransports (e.g.
svn+ssh://
), you must include the username inthe URL, e.g.svn+ssh://foo@svn.bar.com/project
- This allows one to specify a prefix which is prependedto the names of remotes if trunk/branches/tags arespecified. The prefix does not automatically include atrailing slash, so be sure you include one in theargument if that is what you want. If —branches/-b isspecified, the prefix must include a trailing slash.Setting a prefix (with a trailing slash) is stronglyencouraged in any case, as your SVN-tracking refs willthen be located at "refs/remotes/$prefix/", which iscompatible with Git’s own remote-tracking ref layout(refs/remotes/$remote/). Setting a prefix is also usefulif you wish to track multiple projects that share a commonrepository.By default, the prefix is set to origin/.
NoteBefore Git v2.0, the default prefix was "" (no prefix). Thismeant that SVN-tracking refs were put at "refs/remotes/*", which isincompatible with how Git’s own remote-tracking refs are organized.If you still want the old default, you can get it by passing—prefix ""
on the command line (—prefix=""
may not work ifyour Perl’s Getopt::Long is < v2.37).
- —ignore-refs=
When passed to init or clone this regular expression willbe preserved as a config key. See fetch for a descriptionof
—ignore-refs
.When passed to init or clone this regular expression willbe preserved as a config key. See fetch for a descriptionof
—ignore-paths
.When passed to init or clone this regular expression willbe preserved as a config key. See fetch for a descriptionof
—include-paths
.- When tracking multiple directories (using —stdlayout,—branches, or —tags options), git svn will attempt to connectto the root (or highest allowed level) of the Subversionrepository. This default allows better tracking of history ifentire projects are moved within a repository, but may causeissues on repositories where read access restrictions are inplace. Passing
—no-minimize-url
will allow git svn toaccept URLs as-is without attempting to connect to a higherlevel directory. This option is off by default when onlyone URL/branch is tracked (it would do little good).
- fetch
- Fetch unfetched revisions from the Subversion remote we aretracking. The name of the [svn-remote "…"] section in the$GIT_DIR/config file may be specified as an optionalcommand-line argument.
This automatically updates the revmap if needed (see$GITDIR/svn/*/.rev_map. in the FILES section below for details).
- —localtime
- Store Git commit times in the local time zone instead of UTC. Thismakes git log (even without —date=local) show the same timesthat
svn log
would in the local time zone.
This doesn’t interfere with interoperating with the Subversionrepository you cloned from, but if you wish for your local Gitrepository to be able to interoperate with someone else’s local Gitrepository, either don’t use this option or you should both use it inthe same local time zone.
- —parent
Fetch only from the SVN parent of the current HEAD.
- Ignore refs for branches or tags matching the Perl regularexpression. A "negative look-ahead assertion" like
^refs/remotes/origin/(?!tags/wanted-tag|wanted-branch).*$
can be used to allow only certain refs.
- config key: svn-remote.<name>.ignore-refs
If the ignore-refs configuration key is set, and the command-lineoption is also given, both regular expressions will be used.
- —ignore-paths=
- This allows one to specify a Perl regular expression that willcause skipping of all matching paths from checkout from SVN.The
—ignore-paths
option should match for every fetch(including automatic fetches due to clone, dcommit,rebase, etc) on a given repository.
- config key: svn-remote.<name>.ignore-paths
If the ignore-paths configuration key is set, and the command-lineoption is also given, both regular expressions will be used.
Examples:
- [](https://git-scm.com/docs/#Documentation/git-svn.txt-Skipdocdirectoryforeveryfetch)Skip "doc*" directory for every fetch
-
- --ignore-paths="^doc"
- [](https://git-scm.com/docs/#Documentation/git-svn.txt-Skipbranchesandtagsoffirstleveldirectories)Skip "branches" and "tags" of first level directories
-
- --ignore-paths="^[^/]+/(?:branches|tags)"
- —include-paths=
- This allows one to specify a Perl regular expression that willcause the inclusion of only matching paths from checkout from SVN.The
—include-paths
option should match for every fetch(including automatic fetches due to clone, dcommit,rebase, etc) on a given repository.—ignore-paths
takesprecedence over—include-paths
.
- config key: svn-remote.<name>.include-paths
- —log-window-size=
- Fetch
log entries per request when scanning Subversion history.The default is 100. For very large Subversion repositories, largervalues may be needed for clone/fetch to complete in reasonabletime. But overly large values may lead to higher memory usage andrequest timeouts.
- clone
- Runs init and fetch. It will automatically create adirectory based on the basename of the URL passed to it;or if a second argument is passed; it will create a directoryand work within that. It accepts all arguments that theinit and fetch commands accept; with the exception of
—fetch-all
and—parent
. After a repository is cloned,the fetch command will be able to update revisions withoutaffecting the working tree; and the rebase command will beable to update the working tree with the latest changes.
- —preserve-empty-dirs
Create a placeholder file in the local Git repository for eachempty directory fetched from Subversion. This includes directoriesthat become empty by removing all entries in the Subversionrepository (but not the directory itself). The placeholder filesare also tracked and removed when no longer necessary.
- Set the name of placeholder files created by —preserve-empty-dirs.Default: ".gitignore"
- rebase
- This fetches revisions from the SVN parent of the current HEADand rebases the current (uncommitted to SVN) work against it.
This works similarly to svn update
or git pull except thatit preserves linear history with git rebase instead ofgit merge for ease of dcommitting with git svn.
This accepts all options that git svn fetch and _git rebase_accept. However, —fetch-all
only fetches from the current[svn-remote], and not all [svn-remote] definitions.
Like git rebase; this requires that the working tree be cleanand have no uncommitted changes.
This automatically updates the revmap if needed (see$GITDIR/svn/*/.rev_map. in the FILES section below for details).
- -l
- —local
- Do not fetch remotely; only run git rebase against thelast fetched commit from the upstream SVN.
- dcommit
- Commit each diff from the current branch directly to the SVNrepository, and then rebase or reset (depending on whether ornot there is a diff between SVN and head). This will createa revision in SVN for each commit in Git.
When an optional Git branch name (or a Git commit object name)is specified as an argument, the subcommand works on the specifiedbranch, not on the current branch.
Use of dcommit is preferred to set-tree (below).
- —no-rebase
After committing, do not rebase or reset.
- Commit to this SVN URL (the full path). This is intended toallow existing git svn repositories created with one transportmethod (e.g.
svn://
orhttp://
for anonymous read) to bereused if a user is later given access to an alternate transportmethod (e.g.svn+ssh://
orhttps://
) for commit.
- config key: svn-remote.<name>.commiturl
- config key: svn.commiturl (overwrites all svn-remote.<name>.commiturl options)
Note that the SVN URL of the commiturl config key includes the SVN branch.If you rather want to set the commit URL for an entire SVN repository usesvn-remote.
Using this option for any other purpose (don’t ask) is very stronglydiscouraged.
- —mergeinfo=
- Add the given merge information during the dcommit(e.g.
—mergeinfo="/branches/foo:1-10"
). All svn server versions canstore this information (as a property), and svn clients starting fromversion 1.5 can make use of it. To specify merge information from multiplebranches, use a single space character between the branches(—mergeinfo="/branches/foo:1-10 /branches/bar:3,5-6,8"
)
- config key: svn.pushmergeinfo
This option will cause git-svn to attempt to automatically populate thesvn:mergeinfo property in the SVN repository when possible. Currently, this canonly be done when dcommitting non-fast-forward merges where all parents but thefirst have already been pushed into SVN.
- —interactive
- Ask the user to confirm that a patch set should actually be sent to SVN.For each patch, one may answer "yes" (accept this patch), "no" (discard thispatch), "all" (accept all patches), or "quit".
git svn dcommit returns immediately if answer is "no" or "quit", withoutcommitting anything to SVN.
- -m
- —message
Allows to specify the commit message.
- —tag
Create a tag by using the tags_subdir instead of the branches_subdirspecified during git svn init.
- —destination=
- If more than one —branches (or —tags) option was given to the init_or _clone command, you must provide the location of the branch (ortag) you wish to create in the SVN repository.
specifies whichpath to use to create the branch or tag and should match the patternon the left-hand side of one of the configured branches or tagsrefspecs. You can see these refspecs with the commands
- git config --get-all svn-remote.<name>.branches
- git config --get-all svn-remote.<name>.tags
where
- —username
Specify the SVN username to perform the commit as. This option overridesthe username configuration property.
- Use the specified URL to connect to the destination Subversionrepository. This is useful in cases where the source SVNrepository is read-only. This option overrides configurationproperty commiturl.
- git config --get-all svn-remote.<name>.commiturl
- —parents
- Create parent folders. This parameter is equivalent to the parameter—parents on svn cp commands and is useful for non-standard repositorylayouts.
- tag
Create a tag in the SVN repository. This is a shorthand forbranch -t.
- This should make it easy to look up svn log messages when svnusers refer to -r/—revision numbers.
The following features from ‘svn log’ are supported:
- -r
[: ] - —revision=
[: ] is supported, non-numeric args are not:HEAD, NEXT, BASE, PREV, etc …
- —verbose
it’s not completely compatible with the —verboseoutput in svn log, but reasonably close.
is NOT the same as —max-count, doesn’t countmerged/excluded commits
- supported
New features:
NoteSVN itself only stores times in UTC and nothing else. The regular svnclient converts the UTC time to the local time (or based on the TZ=environment). This command has the same behaviour.
Any other arguments are passed directly to git log
- blame
- Show what revision and author last modified each line of a file. Theoutput of this mode is format-compatible with the output of‘svn blame’ by default. Like the SVN blame command,local uncommitted changes in the working tree are ignored;the version of the file in the HEAD revision is annotated. Unknownarguments are passed directly to git blame.
- —git-format
- Produce output in the same format as git blame, but withSVN revision numbers instead of Git commit hashes. In this mode,changes that haven’t been committed to SVN (including localworking-copy edits) are shown as revision 0.
- find-rev
- When given an SVN revision number of the form rN, returns thecorresponding Git commit hash (this can optionally be followed by atree-ish to specify which branch should be searched). When given atree-ish, returns the corresponding SVN revision number.
- -B
- —before
Don’t require an exact match if given an SVN revision, instead findthe commit corresponding to the state of the SVN repository (on thecurrent branch) at the specified revision.
- —after
- Don’t require an exact match if given an SVN revision; if there isnot an exact match return the closest match searching forward in thehistory.
- set-tree
You should consider using dcommit instead of this command.Commit specified commit or tree objects to SVN. This relies onyour imported fetch data being up to date. This makesabsolutely no attempts to do patching when committing to SVN, itsimply overwrites files with those specified in the tree orcommit. All merging is assumed to have taken placeindependently of git svn functions.
Recursively finds the svn:ignore property on directories andcreates matching .gitignore files. The resulting files are staged tobe committed, but are not committed. Use -r/—revision to refer to aspecific revision.
Recursively finds and lists the svn:ignore property ondirectories. The output is suitable for appending tothe $GIT_DIR/info/exclude file.
Attempts to recreate empty directories that core Git cannot trackbased on information in $GIT_DIR/svn/
/unhandled.log files.Empty directories are automatically recreated when using"git svn clone" and "git svn rebase", so "mkdirs" is intendedfor use after commands like "git checkout" or "git reset".(See the svn-remote. .automkdirs config file option formore information.) - Commits the diff of two tree-ish arguments from thecommand-line. This command does not rely on being inside a
git svninit
-ed repository. This command takes three arguments, (a) theoriginal tree to diff against, (b) the new tree result, (c) theURL of the target Subversion repository. The final argument(URL) may be omitted if you are working from a git svn-awarerepository (that has beeninit
-ed with git svn).The -roption is required for this.
The commit message is supplied either directly with the -m
or -F
option, or indirectly from the tag or commit when the second tree-ishdenotes such an object, or it is requested by invoking an editor (see—edit
option below).
- -m
- —message=
Use the given
msg
as the commit message. This optiondisables the—edit
option.- —file=
- Take the commit message from the given file. This optiondisables the
—edit
option.
- info
Shows information about a file or directory similar to what‘svn info’ provides. Does not currently support a -r/—revisionargument. Use the —url option to output only the value of theURL: field.
Lists the properties stored in the Subversion repository about agiven file or directory. Use -r/—revision to refer to a specificSubversion revision.
Gets the Subversion property given as the first argument, for afile. A specific revision can be specified with -r/—revision.
- Sets the Subversion property given as the first argument, to thevalue given as the second argument for the file given as thethird argument.
Example:
- git svn propset svn:keywords "FreeBSD=%H" devel/py-tipper/Makefile
This will set the property svn:keywords to FreeBSD=%H for the filedevel/py-tipper/Makefile.
- show-externals
Shows the Subversion externals. Use -r/—revision to specify aspecific revision.
Compress $GIT_DIR/svn/
/unhandled.log files and remove$GIT_DIR/svn/ /index files. - Undoes the effects of fetch back to the specified revision.This allows you to re-fetch an SVN revision. Normally thecontents of an SVN revision should never change and reset_should not be necessary. However, if SVN permissions change,or if you alter your —ignore-paths option, a _fetch may failwith "not found in commit" (file not previously visible) or"checksum mismatch" (missed a modification). If the problemfile cannot be ignored forever (with —ignore-paths) the onlyway to repair the repo is to use reset.
Only the revmap and refs/remotes/git-svn are changed (see$GITDIR/svn/*/.rev_map. in the FILES section below for details).Follow reset with a fetch and then git reset or git rebase tomove local branches onto the new tree.
- -r
- —revision=
Specify the most recent revision to keep. All later revisionsare discarded.
- —parent
Discard the specified revision as well, keeping the nearestparent instead.
- Assume you have local changes in "master", but you need to refetch "r2".
- r1---r2---r3 remotes/git-svn
- \
- A---B master
Fix the ignore-paths or SVN permissions problem that caused "r2" tobe incomplete in the first place. Then:
- git svn reset -r2 -p
- git svn fetch
- r1---r2'--r3' remotes/git-svn
- \
- r2---r3---A---B master
Then fixup "master" with git rebase.Do NOT use git merge or your history will not be compatible with afuture dcommit!
- git rebase --onto remotes/git-svn A^ master
- r1---r2'--r3' remotes/git-svn
- \
- A'--B' master
OPTIONS
- —shared[=(false|true|umask|group|all|world|everybody)]
- —template=
Only used with the init command.These are passed directly to git init.
- —revision
- Used with the fetch command.
This allows revision ranges for partial/cauterized historyto be supported. $NUMBER, $NUMBER1:$NUMBER2 (numeric ranges),$NUMBER:HEAD, and BASE:$NUMBER are all supported.
This can allow you to make partial mirrors when running fetch;but is generally not recommended because history will be skippedand lost.
Read a list of commits from stdin and commit them in reverseorder. Only the leading sha1 is read from each line, sogit rev-list —pretty=oneline output can be used.
Remove directories from the SVN tree if there are no files leftbehind. SVN can version empty directories, and they are notremoved by default if there are no files left in them. Gitcannot version empty directories. Enabling this flag will makethe commit to SVN act like Git.
- config key: svn.rmdir
Edit the commit message before committing to SVN. This is off bydefault for objects that are commits, and forced on when committingtree objects.
- config key: svn.edit
They are both passed directly to git diff-tree; seegit-diff-tree[1] for more information.
- config key: svn.l
- config key: svn.findcopiesharder
- -A
- —authors-file=
- Syntax is compatible with the file used by git cvsimport butan empty email address can be supplied with <>:
- loginname = Joe User <user@example.com>
If this option is specified and git svn encounters an SVNcommitter name that does not exist in the authors-file, git svn_will abort operation. The user will then have to add theappropriate entry. Re-running the previous _git svn commandafter the authors-file is modified should continue operation.
- config key: svn.authorsfile
- —authors-prog=
- If this option is specified, for each SVN committer name thatdoes not exist in the authors file, the given file is executedwith the committer name as the first argument. The program isexpected to return a single line of the form "Name
" or"Name <>", which will be treated as if included in the authorsfile.
Due to historical reasons a relative filename is first searchedrelative to the current directory for init and clone and relativeto the root of the working tree for fetch. If filename isnot found, it is searched like any other command in $PATH.
- config key: svn.authorsProg
- -q
- —quiet
Make git svn less verbose. Specify a second time to make iteven less verbose.
- —merge
- -s
- —strategy=
- -p
- —preserve-merges
- These are only used with the dcommit and rebase commands.
Passed directly to git rebase when using dcommit if agit reset cannot be used (see dcommit).
For dcommit, print out the series of Git arguments that would showwhich diffs would be committed to SVN.
For rebase, display the local branch associated with the upstream svnrepository associated with the current branch and the URL of svnrepository that will be fetched from.
For branch and tag, display the urls that will be used for copying whencreating the branch or tag.
- —use-log-author
- When retrieving svn commits into Git (as part of fetch, rebase, ordcommit operations), look for the first
From:
orSigned-off-by:
linein the log message and use that as the author string.
- config key: svn.useLogAuthor
- —add-author-from
- When committing to svn from Git (as part of set-tree or _dcommit_operations), if the existing log message doesn’t already have a
From:
orSigned-off-by:
line, append aFrom:
line based on theGit commit’s author string. If you use this, then—use-log-author
will retrieve a valid author string for all commits.
- config key: svn.addAuthorFrom
ADVANCED OPTIONS
- -i
- —id
This sets GITSVN_ID (instead of using the environment). Thisallows the user to override the default refname to fetch fromwhen tracking a single URL. The _log and dcommit commandsno longer require this switch as an argument.
- —svn-remote
Specify the [svn-remote "
"] section to use,this allows SVN multiple repositories to be tracked.Default: "svn" - This option is only relevant if we are tracking branches (usingone of the repository layout options —trunk, —tags,—branches, —stdlayout). For each tracked branch, try to findout where its revision was copied from, and seta suitable parent in the first Git commit for the branch.This is especially helpful when we’re tracking a directorythat has been moved around within the repository. If thisfeature is disabled, the branches created by git svn will allbe linear and not share any history, meaning that there will beno information on where branches were branched off or merged.However, following long/convoluted histories can take a longtime, so disabling this feature may speed up the cloningprocess. This feature is enabled by default, use—no-follow-parent to disable it.
- config key: svn.followparent
CONFIG FILE-ONLY OPTIONS
- svn.noMetadata
- svn-remote.
.noMetadata - This gets rid of the git-svn-id: lines at the end of every commit.
This option can only be used for one-shot imports as git svn_will not be able to fetch again without metadata. Additionally,if you lose your $GITDIR/svn/*/.rev_map. files, git svn will notbe able to rebuild them.
The git svn log command will not work on repositories usingthis, either. Using this conflicts with the _useSvmProps_option for (hopefully) obvious reasons.
This option is NOT recommended as it makes it difficult to track downold references to SVN revision numbers in existing documentation, bugreports and archives. If you plan to eventually migrate from SVN to Gitand are certain about dropping SVN history, considergit-filter-branch[1] instead. filter-branch also allowsreformatting of metadata for ease-of-reading and rewriting authorshipinfo for non-"svn.authorsFile" users.
- svn.useSvmProps
- svn-remote.
.useSvmProps - This allows git svn to re-map repository URLs and UUIDs frommirrors created using SVN::Mirror (or svk) for metadata.
If an SVN revision has a property, "svm:headrev", it is likelythat the revision was created by SVN::Mirror (also used by SVK).The property contains a repository UUID and a revision. We wantto make it look like we are mirroring the original URL, sointroduce a helper function that returns the original identityURL and UUID, and use it when generating metadata in commitmessages.
- svn.useSvnsyncProps
- svn-remote.
.useSvnsyncprops Similar to the useSvmProps option; this is for usersof the svnsync(1) command distributed with SVN 1.4.x andlater.
This allows users to create repositories from alternateURLs. For example, an administrator could run git svn on theserver locally (accessing via file://) but wish to distributethe repository with a public http:// or svn:// URL in themetadata so users of it will see the public URL.
Similar to the useSvmProps option; this is for users who needto remap the UUID manually. This may be useful in situationswhere the original UUID is not available via either useSvmPropsor useSvnsyncProps.
Similar to Git’s
remote.<name>.pushurl
, this key is designedto be used in cases where url points to an SVN repositoryvia a read-only transport, to provide an alternate read/writetransport. It is assumed that both keys point to the samerepository. Unlike commiturl, pushurl is a base path. Ifeither commiturl or pushurl could be used, _commiturl_takes precedence.This disables potentially expensive checks to workaroundbroken symlinks checked into SVN by broken clients. Set thisoption to "false" if you track a SVN repository with manyempty blobs that are not symlinks. This option may be changedwhile git svn is running and take effect on the nextrevision fetched. If unset, git svn assumes this option tobe "true".
This instructs git svn to recode pathnames to a given encoding.It can be used by windows users and by those who work in non-utf8locales to avoid corrupted file names with non-ASCII characters.Valid encodings are the ones supported by Perl’s Encode module.
- Normally, the "git svn clone" and "git svn rebase" commandsattempt to recreate empty directories that are in theSubversion repository. If this option is set to "false", thenempty directories will only be created if the "git svn mkdirs"command is run explicitly. If unset, git svn assumes thisoption to be "true".
Since the noMetadata, rewriteRoot, rewriteUUID, useSvnsyncProps and useSvmPropsoptions all affect the metadata generated and used by git svn; theymust be set in the configuration file before any history is importedand these settings should never be changed once they are set.
Additionally, only one of these options can be used per svn-remotesection because they affect the git-svn-id: metadata line, exceptfor rewriteRoot and rewriteUUID which can be used together.
BASIC EXAMPLES
Tracking and contributing to the trunk of a Subversion-managed project(ignoring tags and branches):
- # Clone a repo (like git clone):
- git svn clone http://svn.example.com/project/trunk
- # Enter the newly cloned directory:
- cd trunk
- # You should be on master branch, double-check with 'git branch'
- git branch
- # Do some work and commit locally to Git:
- git commit ...
- # Something is committed to SVN, rebase your local changes against the
- # latest changes in SVN:
- git svn rebase
- # Now commit your changes (that were committed previously using Git) to SVN,
- # as well as automatically updating your working HEAD:
- git svn dcommit
- # Append svn:ignore settings to the default Git exclude file:
- git svn show-ignore >> .git/info/exclude
Tracking and contributing to an entire Subversion-managed project(complete with a trunk, tags and branches):
- # Clone a repo with standard SVN directory layout (like git clone):
- git svn clone http://svn.example.com/project --stdlayout --prefix svn/
- # Or, if the repo uses a non-standard directory layout:
- git svn clone http://svn.example.com/project -T tr -b branch -t tag --prefix svn/
- # View all branches and tags you have cloned:
- git branch -r
- # Create a new branch in SVN
- git svn branch waldo
- # Reset your master to trunk (or any other branch, replacing 'trunk'
- # with the appropriate name):
- git reset --hard svn/trunk
- # You may only dcommit to one branch/tag/trunk at a time. The usage
- # of dcommit/rebase/show-ignore should be the same as above.
The initial git svn clone can be quite time-consuming(especially for large Subversion repositories). If multiplepeople (or one person with multiple machines) want to usegit svn to interact with the same Subversion repository, you cando the initial git svn clone to a repository on a server andhave each person clone that repository with git clone:
- # Do the initial import on a server
- ssh server "cd /pub && git svn clone http://svn.example.com/project [options...]"
- # Clone locally - make sure the refs/remotes/ space matches the server
- mkdir project
- cd project
- git init
- git remote add origin server:/pub/project
- git config --replace-all remote.origin.fetch '+refs/remotes/*:refs/remotes/*'
- git fetch
- # Prevent fetch/pull from remote Git server in the future,
- # we only want to use git svn for future updates
- git config --remove-section remote.origin
- # Create a local branch from one of the branches just fetched
- git checkout -b master FETCH_HEAD
- # Initialize 'git svn' locally (be sure to use the same URL and
- # --stdlayout/-T/-b/-t/--prefix options as were used on server)
- git svn init http://svn.example.com/project [options...]
- # Pull the latest changes from Subversion
- git svn rebase
REBASE VS. PULL/MERGE
Prefer to use git svn rebase or git rebase, rather thangit pull or git merge to synchronize unintegrated commits with a git svn_branch. Doing so will keep the history of unintegrated commits linear withrespect to the upstream SVN repository and allow the use of the preferred_git svn dcommit subcommand to push unintegrated commits back into SVN.
Originally, git svn recommended that developers pulled or merged fromthe git svn branch. This was because the author favoredgit svn set-tree B
to commit a single head rather than thegit svn set-tree A..B
notation to commit multiple commits. Use ofgit pull or git merge with git svn set-tree A..B
will cause non-linearhistory to be flattened when committing into SVN and this can lead to mergecommits unexpectedly reversing previous commits in SVN.
MERGE TRACKING
While git svn can trackcopy history (including branches and tags) for repositories adopting astandard layout, it cannot yet represent merge history that happenedinside git back upstream to SVN users. Therefore it is advised thatusers keep history as linear as possible inside Git to easecompatibility with SVN (see the CAVEATS section below).
HANDLING OF SVN BRANCHES
If git svn is configured to fetch branches (and —follow-branchesis in effect), it sometimes creates multiple Git branches for oneSVN branch, where the additional branches have names of the formbranchname@nnn (with nnn an SVN revision number). These additionalbranches are created if git svn cannot find a parent commit for thefirst commit in an SVN branch, to connect the branch to the history ofthe other branches.
Normally, the first commit in an SVN branch consistsof a copy operation. git svn will read this commit to get the SVNrevision the branch was created from. It will then try to find theGit commit that corresponds to this SVN revision, and use that as theparent of the branch. However, it is possible that there is no suitableGit commit to serve as parent. This will happen, among other reasons,if the SVN branch is a copy of a revision that was not fetched by gitsvn (e.g. because it is an old revision that was skipped with—revision
), or if in SVN a directory was copied that is not trackedby git svn (such as a branch that is not tracked at all, or asubdirectory of a tracked branch). In these cases, git svn will stillcreate a Git branch, but instead of using an existing Git commit as theparent of the branch, it will read the SVN history of the directory thebranch was copied from and create appropriate Git commits. This isindicated by the message "Initializing parent: <branchname>".
Additionally, it will create a special branch named<branchname>@<SVN-Revision>, where <SVN-Revision> is the SVN revisionnumber the branch was copied from. This branch will point to the newlycreated parent commit of the branch. If in SVN the branch was deletedand later recreated from a different version, there will be multiplesuch branches with an @.
Note that this may mean that multiple Git commits are created for asingle SVN revision.
An example: in an SVN repository with a standardtrunk/tags/branches layout, a directory trunk/sub is created in r.100.In r.200, trunk/sub is branched by copying it to branches/. git svnclone -s will then create a branch sub. It will also create new Gitcommits for r.100 through r.199 and use these as the history of branchsub. Thus there will be two Git commits for each revision from r.100to r.199 (one containing trunk/, one containing trunk/sub/). Finally,it will create a branch sub@200 pointing to the new parent commit ofbranch sub (i.e. the commit for r.200 and trunk/sub/).
CAVEATS
For the sake of simplicity and interoperating with Subversion,it is recommended that all git svn users clone, fetch and dcommitdirectly from the SVN server, and avoid all git clone/pull/merge/push_operations between Git repositories and branches. The recommendedmethod of exchanging code between Git branches and users is_git format-patch and git am, or just 'dcommit’ing to the SVN repository.
Running git merge or git pull is NOT recommended on a branch youplan to dcommit from because Subversion users cannot see anymerges you’ve made. Furthermore, if you merge or pull from a Git branchthat is a mirror of an SVN branch, dcommit may commit to the wrongbranch.
If you do merge, note the following rule: git svn dcommit willattempt to commit on top of the SVN commit named in
- git log --grep=^git-svn-id: --first-parent -1
You must therefore ensure that the most recent commit of the branchyou want to dcommit to is the first parent of the merge. Chaos willensue otherwise, especially if the first parent is an older commit onthe same SVN branch.
git clone does not clone branches under the refs/remotes/ hierarchy orany git svn metadata, or config. So repositories created and managed withusing git svn should use rsync for cloning, if cloning is to be doneat all.
Since dcommit uses rebase internally, any Git branches you git push tobefore dcommit on will require forcing an overwrite of the existing refon the remote repository. This is generally considered bad practice,see the git-push[1] documentation for details.
Do not use the —amend option of git-commit[1] on a change you’vealready dcommitted. It is considered bad practice to —amend commitsyou’ve already pushed to a remote repository for other users, anddcommit with SVN is analogous to that.
When cloning an SVN repository, if none of the options for describingthe repository layout is used (—trunk, —tags, —branches,—stdlayout), git svn clone will create a Git repository withcompletely linear history, where branches and tags appear as separatedirectories in the working copy. While this is the easiest way to get acopy of a complete repository, for projects with many branches it willlead to a working copy many times larger than just the trunk. Thus forprojects using the standard directory structure (trunk/branches/tags),it is recommended to clone with option —stdlayout
. If the projectuses a non-standard structure, and/or if branches and tags are notrequired, it is easiest to only clone one directory (typically trunk),without giving any repository layout options. If the full history withbranches and tags is required, the options —trunk
/ —branches
/—tags
must be used.
When using multiple —branches or —tags, git svn does not automaticallyhandle name collisions (for example, if two branches from different paths havethe same name, or if a branch and a tag have the same name). In these cases,use init to set up your Git repository then, before your first fetch, editthe $GIT_DIR/config file so that the branches and tags are associatedwith different name spaces. For example:
- branches = stable/*:refs/remotes/svn/stable/*
- branches = debug/*:refs/remotes/svn/debug/*
BUGS
We ignore all SVN properties except svn:executable. Any unhandledproperties are logged to $GIT_DIR/svn/<refname>/unhandled.log
Renamed and copied directories are not detected by Git and hence nottracked when committing to SVN. I do not plan on adding support forthis as it’s quite difficult and time-consuming to get working for allthe possible corner cases (Git doesn’t do it, either). Committingrenamed and copied files is fully supported if they’re similar enoughfor Git to detect them.
In SVN, it is possible (though discouraged) to commit changes to a tag(because a tag is just a directory copy, thus technically the same as abranch). When cloning an SVN repository, git svn cannot know if such acommit to a tag will happen in the future. Thus it acts conservativelyand imports all SVN tags as branches, prefixing the tag name with tags/.
CONFIGURATION
git svn stores [svn-remote] configuration information in therepository $GITDIR/config file. It is similar the core Git[remote] sections except _fetch keys do not accept globarguments; but they are instead handled by the branches_and _tags keys. Since some SVN repositories are oddlyconfigured with multiple projects glob expansions such thoselisted below are allowed:
- [svn-remote "project-a"]
- url = http://server.org/svn
- fetch = trunk/project-a:refs/remotes/project-a/trunk
- branches = branches/*/project-a:refs/remotes/project-a/branches/*
- branches = branches/release_*:refs/remotes/project-a/branches/release_*
- branches = branches/re*se:refs/remotes/project-a/branches/*
- tags = tags/*/project-a:refs/remotes/project-a/tags/*
Keep in mind that the (asterisk) wildcard of the local ref(right of the
:
) *must be the farthest right path component;however the remote wildcard may be anywhere as long as it’s anindependent path component (surrounded by /
or EOL). Thistype of configuration is not automatically created by init andshould be manually entered with a text-editor or using git config.
Also note that only one asterisk is allowed per word. For example:
- branches = branches/re*se:refs/remotes/project-a/branches/*
will match branches release, rese, re123se, however
- branches = branches/re*s*e:refs/remotes/project-a/branches/*
will produce an error.
It is also possible to fetch a subset of branches or tags by using acomma-separated list of names within braces. For example:
- [svn-remote "huge-project"]
- url = http://server.org/svn
- fetch = trunk/src:refs/remotes/trunk
- branches = branches/{red,green}/src:refs/remotes/project-a/branches/*
- tags = tags/{1.0,2.0}/src:refs/remotes/project-a/tags/*
Multiple fetch, branches, and tags keys are supported:
- [svn-remote "messy-repo"]
- url = http://server.org/svn
- fetch = trunk/project-a:refs/remotes/project-a/trunk
- fetch = branches/demos/june-project-a-demo:refs/remotes/project-a/demos/june-demo
- branches = branches/server/*:refs/remotes/project-a/branches/*
- branches = branches/demos/2011/*:refs/remotes/project-a/2011-demos/*
- tags = tags/server/*:refs/remotes/project-a/tags/*
Creating a branch in such a configuration requires disambiguating whichlocation to use using the -d or —destination flag:
- $ git svn branch -d branches/server release-2-3-0
Note that git-svn keeps track of the highest revision in which a branchor tag has appeared. If the subset of branches or tags is changed afterfetching, then $GIT_DIR/svn/.metadata must be manually edited to remove(or reset) branches-maxRev and/or tags-maxRev as appropriate.
FILES
- $GIT_DIR/svn/*/.rev_map.
- Mapping between Subversion revision numbers and Git commitnames. In a repository where the noMetadata option is not set,this can be rebuilt from the git-svn-id: lines that are at theend of every commit (see the svn.noMetadata section above fordetails).
git svn fetch and git svn rebase automatically update the revmapif it is missing or not up to date. _git svn reset automaticallyrewinds it.
SEE ALSO
GIT
Part of the git[1] suite