GIT-SVN(1) | Git Manual | GIT-SVN(1) |
git-svn - Bidirectional operation between a Subversion repository and Git
git svn <command> [<options>] [<arguments>]
git svn is a simple conduit for changesets between Subversion and Git. It provides a bidirectional flow of changes between a Subversion and a Git repository.
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 Git repository can be updated from Subversion by the fetch command and Subversion updated from Git by the dcommit command.
init
-T<trunk_subdir>, --trunk=<trunk_subdir>, -t<tags_subdir>, --tags=<tags_subdir>, -b<branches_subdir>, --branches=<branches_subdir>, -s, --stdlayout
--no-metadata
--use-svm-props
--use-svnsync-props
--rewrite-root=<URL>
--rewrite-uuid=<UUID>
--username=<user>
--prefix=<prefix>
--ignore-refs=<regex>
--ignore-paths=<regex>
--include-paths=<regex>
--no-minimize-url
fetch
This automatically updates the rev_map if needed (see $GIT_DIR/svn/**/.rev_map.* in the FILES section below for details).
--localtime
This doesn’t interfere with interoperating with the Subversion repository you cloned from, but if you wish for your local Git repository to be able to interoperate with someone else’s local Git repository, either don’t use this option or you should both use it in the same local time zone.
--parent
--ignore-refs=<regex>
config key: svn-remote.<name>.ignore-refs
If the ignore-refs configuration key is set, and the command-line option is also given, both regular expressions will be used.
--ignore-paths=<regex>
config key: svn-remote.<name>.ignore-paths
If the ignore-paths configuration key is set, and the command-line option is also given, both regular expressions will be used.
Examples:
Skip "doc*" directory for every fetch
--ignore-paths="^doc"
Skip "branches" and "tags" of first level directories
--ignore-paths="^[^/]+/(?:branches|tags)"
--include-paths=<regex>
config key: svn-remote.<name>.include-paths
--log-window-size=<n>
clone
--preserve-empty-dirs
--placeholder-filename=<filename>
rebase
This works similarly to svn update or git pull except that it preserves linear history with git rebase instead of git 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 clean and have no uncommitted changes.
This automatically updates the rev_map if needed (see $GIT_DIR/svn/**/.rev_map.* in the FILES section below for details).
-l, --local
dcommit
When an optional Git branch name (or a Git commit object name) is specified as an argument, the subcommand works on the specified branch, not on the current branch.
Use of dcommit is preferred to set-tree (below).
--no-rebase
--commit-url <URL>
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 use svn-remote.<name>.pushurl instead.
Using this option for any other purpose (don’t ask) is very strongly discouraged.
--mergeinfo=<mergeinfo>
config key: svn.pushmergeinfo
This option will cause git-svn to attempt to automatically populate the svn:mergeinfo property in the SVN repository when possible. Currently, this can only be done when dcommitting non-fast-forward merges where all parents but the first have already been pushed into SVN.
--interactive
git svn dcommit returns immediately if answer is "no" or "quit", without committing anything to SVN.
branch
-m, --message
-t, --tag
-d<path>, --destination=<path>
git config --get-all svn-remote.<name>.branches git config --get-all svn-remote.<name>.tags
where <name> is the name of the SVN repository as specified by the -R option to init (or "svn" by default).
--username
--commit-url
git config --get-all svn-remote.<name>.commiturl
--parents
tag
log
The following features from ‘svn log’ are supported:
-r <n>[:<n>], --revision=<n>[:<n>]
-v, --verbose
--limit=<n>
--incremental
New features:
--show-commit
--oneline
blame
--git-format
find-rev
-B, --before
-A, --after
set-tree
create-ignore
show-ignore
mkdirs
commit-diff
The commit message is supplied either directly with the -m or -F option, or indirectly from the tag or commit when the second tree-ish denotes such an object, or it is requested by invoking an editor (see --edit option below).
-m <msg>, --message=<msg>
-F <filename>, --file=<filename>
info
proplist
propget
propset
Example:
git svn propset svn:keywords "FreeBSD=%H" devel/py-tipper/Makefile
This will set the property svn:keywords to FreeBSD=%H for the file devel/py-tipper/Makefile.
show-externals
gc
reset
Only the rev_map and refs/remotes/git-svn are changed (see $GIT_DIR/svn/**/.rev_map.* in the FILES section below for details). Follow reset with a fetch and then git reset or git rebase to move local branches onto the new tree.
-r <n>, --revision=<n>
-p, --parent
Example:
r1---r2---r3 remotes/git-svn
\
A---B master
Fix the ignore-paths or SVN permissions problem that caused "r2" to be 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 a future dcommit!
git rebase --onto remotes/git-svn A^ master
r1---r2'--r3' remotes/git-svn
\
A'--B' master
--shared[=(false|true|umask|group|all|world|everybody)], --template=<template-directory>
-r <arg>, --revision <arg>
This allows revision ranges for partial/cauterized history to 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 skipped and lost.
-, --stdin
Read a list of commits from stdin and commit them in reverse order. Only the leading sha1 is read from each line, so git rev-list --pretty=oneline output can be used.
--rmdir
Remove directories from the SVN tree if there are no files left behind. SVN can version empty directories, and they are not removed by default if there are no files left in them. Git cannot version empty directories. Enabling this flag will make the commit to SVN act like Git.
config key: svn.rmdir
-e, --edit
Edit the commit message before committing to SVN. This is off by default for objects that are commits, and forced on when committing tree objects.
config key: svn.edit
-l<num>, --find-copies-harder
They are both passed directly to git diff-tree; see git-diff-tree(1) for more information.
config key: svn.l config key: svn.findcopiesharder
-A<filename>, --authors-file=<filename>
loginname = Joe User <user@example.com>
If this option is specified and git svn encounters an SVN committer name that does not exist in the authors-file, git svn will abort operation. The user will then have to add the appropriate entry. Re-running the previous git svn command after the authors-file is modified should continue operation.
config key: svn.authorsfile
--authors-prog=<filename>
Due to historical reasons a relative filename is first searched relative to the current directory for init and clone and relative to the root of the working tree for fetch. If filename is not found, it is searched like any other command in $PATH.
config key: svn.authorsProg
-q, --quiet
-m, --merge, -s<strategy>, --strategy=<strategy>, -p, --rebase-merges
Passed directly to git rebase when using dcommit if a git reset cannot be used (see dcommit).
-n, --dry-run
For dcommit, print out the series of Git arguments that would show which diffs would be committed to SVN.
For rebase, display the local branch associated with the upstream svn repository associated with the current branch and the URL of svn repository that will be fetched from.
For branch and tag, display the urls that will be used for copying when creating the branch or tag.
--use-log-author
config key: svn.useLogAuthor
--add-author-from
config key: svn.addAuthorFrom
-i<GIT_SVN_ID>, --id <GIT_SVN_ID>
-R<remote name>, --svn-remote <remote name>
--follow-parent
config key: svn.followparent
svn.noMetadata, svn-remote.<name>.noMetadata
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 $GIT_DIR/svn/**/.rev_map.* files, git svn will not be able to rebuild them.
The git svn log command will not work on repositories using this, either. Using this conflicts with the useSvmProps option for (hopefully) obvious reasons.
This option is NOT recommended as it makes it difficult to track down old references to SVN revision numbers in existing documentation, bug reports, and archives. If you plan to eventually migrate from SVN to Git and are certain about dropping SVN history, consider git-filter-repo[1] instead. filter-repo also allows reformatting of metadata for ease-of-reading and rewriting authorship info for non-"svn.authorsFile" users.
svn.useSvmProps, svn-remote.<name>.useSvmProps
If an SVN revision has a property, "svm:headrev", it is likely that the revision was created by SVN::Mirror (also used by SVK). The property contains a repository UUID and a revision. We want to make it look like we are mirroring the original URL, so introduce a helper function that returns the original identity URL and UUID, and use it when generating metadata in commit messages.
svn.useSvnsyncProps, svn-remote.<name>.useSvnsyncprops
svn-remote.<name>.rewriteRoot
svn-remote.<name>.rewriteUUID
svn-remote.<name>.pushurl
svn.brokenSymlinkWorkaround
svn.pathnameencoding
svn-remote.<name>.automkdirs
Since the noMetadata, rewriteRoot, rewriteUUID, useSvnsyncProps and useSvmProps options all affect the metadata generated and used by git svn; they must be set in the configuration file before any history is imported and these settings should never be changed once they are set.
Additionally, only one of these options can be used per svn-remote section because they affect the git-svn-id: metadata line, except for rewriteRoot and rewriteUUID which can be used together.
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 multiple people (or one person with multiple machines) want to use git svn to interact with the same Subversion repository, you can do the initial git svn clone to a repository on a server and have 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
Prefer to use git svn rebase or git rebase, rather than git pull or git merge to synchronize unintegrated commits with a git svn branch. Doing so will keep the history of unintegrated commits linear with respect 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 from the git svn branch. This was because the author favored git svn set-tree B to commit a single head rather than the git svn set-tree A..B notation to commit multiple commits. Use of git pull or git merge with git svn set-tree A..B will cause non-linear history to be flattened when committing into SVN and this can lead to merge commits unexpectedly reversing previous commits in SVN.
While git svn can track copy history (including branches and tags) for repositories adopting a standard layout, it cannot yet represent merge history that happened inside git back upstream to SVN users. Therefore it is advised that users keep history as linear as possible inside Git to ease compatibility with SVN (see the CAVEATS section below).
If git svn is configured to fetch branches (and --follow-branches is in effect), it sometimes creates multiple Git branches for one SVN branch, where the additional branches have names of the form branchname@nnn (with nnn an SVN revision number). These additional branches are created if git svn cannot find a parent commit for the first commit in an SVN branch, to connect the branch to the history of the other branches.
Normally, the first commit in an SVN branch consists of a copy operation. git svn will read this commit to get the SVN revision the branch was created from. It will then try to find the Git commit that corresponds to this SVN revision, and use that as the parent of the branch. However, it is possible that there is no suitable Git 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 git svn (e.g. because it is an old revision that was skipped with --revision), or if in SVN a directory was copied that is not tracked by git svn (such as a branch that is not tracked at all, or a subdirectory of a tracked branch). In these cases, git svn will still create a Git branch, but instead of using an existing Git commit as the parent of the branch, it will read the SVN history of the directory the branch was copied from and create appropriate Git commits. This is indicated by the message "Initializing parent: <branchname>".
Additionally, it will create a special branch named <branchname>@<SVN-Revision>, where <SVN-Revision> is the SVN revision number the branch was copied from. This branch will point to the newly created parent commit of the branch. If in SVN the branch was deleted and later recreated from a different version, there will be multiple such branches with an @.
Note that this may mean that multiple Git commits are created for a single SVN revision.
An example: in an SVN repository with a standard trunk/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 svn clone -s will then create a branch sub. It will also create new Git commits for r.100 through r.199 and use these as the history of branch sub. Thus there will be two Git commits for each revision from r.100 to r.199 (one containing trunk/, one containing trunk/sub/). Finally, it will create a branch sub@200 pointing to the new parent commit of branch sub (i.e. the commit for r.200 and trunk/sub/).
For the sake of simplicity and interoperating with Subversion, it is recommended that all git svn users clone, fetch and dcommit directly from the SVN server, and avoid all git clone/pull/merge/push operations between Git repositories and branches. The recommended method 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 you plan to dcommit from because Subversion users cannot see any merges you’ve made. Furthermore, if you merge or pull from a Git branch that is a mirror of an SVN branch, dcommit may commit to the wrong branch.
If you do merge, note the following rule: git svn dcommit will attempt 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 branch you want to dcommit to is the first parent of the merge. Chaos will ensue otherwise, especially if the first parent is an older commit on the same SVN branch.
git clone does not clone branches under the refs/remotes/ hierarchy or any git svn metadata, or config. So repositories created and managed with using git svn should use rsync for cloning, if cloning is to be done at all.
Since dcommit uses rebase internally, any Git branches you git push to before dcommit on will require forcing an overwrite of the existing ref on 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’ve already dcommitted. It is considered bad practice to --amend commits you’ve already pushed to a remote repository for other users, and dcommit with SVN is analogous to that.
When cloning an SVN repository, if none of the options for describing the repository layout is used (--trunk, --tags, --branches, --stdlayout), git svn clone will create a Git repository with completely linear history, where branches and tags appear as separate directories in the working copy. While this is the easiest way to get a copy of a complete repository, for projects with many branches it will lead to a working copy many times larger than just the trunk. Thus for projects using the standard directory structure (trunk/branches/tags), it is recommended to clone with option --stdlayout. If the project uses a non-standard structure, and/or if branches and tags are not required, it is easiest to only clone one directory (typically trunk), without giving any repository layout options. If the full history with branches and tags is required, the options --trunk / --branches / --tags must be used.
When using multiple --branches or --tags, git svn does not automatically handle name collisions (for example, if two branches from different paths have the 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, edit the $GIT_DIR/config file so that the branches and tags are associated with different name spaces. For example:
branches = stable/*:refs/remotes/svn/stable/* branches = debug/*:refs/remotes/svn/debug/*
git svn stores [svn-remote] configuration information in the repository $GIT_DIR/config file. It is similar the core Git [remote] sections except fetch keys do not accept glob arguments; but they are instead handled by the branches and tags keys. Since some SVN repositories are oddly configured with multiple projects glob expansions such those listed 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 an independent path component (surrounded by / or EOL). This type of configuration is not automatically created by init and should 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 a comma-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 which location 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 branch or tag has appeared. If the subset of branches or tags is changed after fetching, then $GIT_DIR/svn/.metadata must be manually edited to remove (or reset) branches-maxRev and/or tags-maxRev as appropriate.
$GIT_DIR/svn/**/.rev_map.*
git svn fetch and git svn rebase automatically update the rev_map if it is missing or not up to date. git svn reset automatically rewinds it.
We ignore all SVN properties except svn:executable. Any unhandled properties are logged to $GIT_DIR/svn/<refname>/unhandled.log
Renamed and copied directories are not detected by Git and hence not tracked when committing to SVN. I do not plan on adding support for this as it’s quite difficult and time-consuming to get working for all the possible corner cases (Git doesn’t do it, either). Committing renamed and copied files is fully supported if they’re similar enough for 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 a branch). When cloning an SVN repository, git svn cannot know if such a commit to a tag will happen in the future. Thus it acts conservatively and imports all SVN tags as branches, prefixing the tag name with tags/.
git-rebase(1)
Part of the git(1) suite
06/06/2021 | Git 2.32.0 |