6 git-svn - Bidirectional operation between a single Subversion branch and git
10 'git-svn' <command> [options] [arguments]
14 git-svn is a simple conduit for changesets between Subversion and git.
15 It is not to be confused with linkgit:git-svnimport[1], which is
18 git-svn was originally designed for an individual developer who wants a
19 bidirectional flow of changesets between a single branch in Subversion
20 and an arbitrary number of branches in git. Since its inception,
21 git-svn has gained the ability to track multiple branches in a manner
22 similar to git-svnimport.
24 git-svn is especially useful when it comes to tracking repositories
25 not organized in the way Subversion developers recommend (trunk,
26 branches, tags directories).
33 Initializes an empty git repository with additional
34 metadata directories for git-svn. The Subversion URL
35 may be specified as a command-line argument, or as full
36 URL arguments to -T/-t/-b. Optionally, the target
37 directory to operate on can be specified as a second
38 argument. Normally this command initializes the current
42 --trunk=<trunk_subdir>;;
44 --tags=<tags_subdir>;;
46 --branches=<branches_subdir>;;
49 These are optional command-line options for init. Each of
50 these flags can point to a relative repository path
51 (--tags=project/tags') or a full url
52 (--tags=https://foo.org/project/tags). The option --stdlayout is
53 a shorthand way of setting trunk,tags,branches as the relative paths,
54 which is the Subversion default. If any of the other options are given
55 as well, they take precedence.
57 Set the 'noMetadata' option in the [svn-remote] config.
59 Set the 'useSvmProps' option in the [svn-remote] config.
61 Set the 'useSvnsyncProps' option in the [svn-remote] config.
62 --rewrite-root=<URL>;;
63 Set the 'rewriteRoot' option in the [svn-remote] config.
65 For transports that SVN handles authentication for (http,
66 https, and plain svn), specify the username. For other
67 transports (eg svn+ssh://), you must include the username in
68 the URL, eg svn+ssh://foo@svn.bar.com/project
70 This allows one to specify a prefix which is prepended
71 to the names of remotes if trunk/branches/tags are
72 specified. The prefix does not automatically include a
73 trailing slash, so be sure you include one in the
74 argument if that is what you want. If --branches/-b is
75 specified, the prefix must include a trailing slash.
76 Setting a prefix is useful if you wish to track multiple
77 projects that share a common repository.
80 Fetch unfetched revisions from the Subversion remote we are
81 tracking. The name of the [svn-remote "..."] section in the
82 .git/config file may be specified as an optional command-line
86 Runs 'init' and 'fetch'. It will automatically create a
87 directory based on the basename of the URL passed to it;
88 or if a second argument is passed; it will create a directory
89 and work within that. It accepts all arguments that the
90 'init' and 'fetch' commands accept; with the exception of
91 '--fetch-all'. After a repository is cloned, the 'fetch'
92 command will be able to update revisions without affecting
93 the working tree; and the 'rebase' command will be able
94 to update the working tree with the latest changes.
97 This fetches revisions from the SVN parent of the current HEAD
98 and rebases the current (uncommitted to SVN) work against it.
100 This works similarly to 'svn update' or 'git-pull' except that
101 it preserves linear history with 'git-rebase' instead of
102 'git-merge' for ease of dcommiting with git-svn.
104 This accepts all options that 'git-svn fetch' and 'git-rebase'
105 accepts. However '--fetch-all' only fetches from the current
106 [svn-remote], and not all [svn-remote] definitions.
108 Like 'git-rebase'; this requires that the working tree be clean
109 and have no uncommitted changes.
113 Do not fetch remotely; only run 'git-rebase' against the
114 last fetched commit from the upstream SVN.
117 Commit each diff from a specified head directly to the SVN
118 repository, and then rebase or reset (depending on whether or
119 not there is a diff between SVN and head). This will create
120 a revision in SVN for each commit in git.
121 It is recommended that you run git-svn fetch and rebase (not
122 pull or merge) your commits against the latest changes in the
124 An optional command-line argument may be specified as an
126 This is advantageous over 'set-tree' (below) because it produces
127 cleaner, more linear history.
130 After committing, do not rebase or reset.
134 This should make it easy to look up svn log messages when svn
135 users refer to -r/--revision numbers.
137 The following features from `svn log' are supported:
140 --revision=<n>[:<n>];;
141 is supported, non-numeric args are not:
142 HEAD, NEXT, BASE, PREV, etc ...
144 it's not completely compatible with the --verbose
145 output in svn log, but reasonably close.
147 is NOT the same as --max-count, doesn't count
148 merged/excluded commits
157 shows the git commit sha1, as well
159 our version of --pretty=oneline
162 NOTE: SVN itself only stores times in UTC and nothing else. The regular svn
163 client converts the UTC time to the local time (or based on the TZ=
164 environment). This command has the same behaviour.
166 Any other arguments are passed directly to `git log'
169 Show what revision and author last modified each line of a file. The
170 output of this mode is format-compatible with the output of
171 `svn blame' by default. Like the SVN blame command,
172 local uncommitted changes in the working copy are ignored;
173 the version of the file in the HEAD revision is annotated. Unknown
174 arguments are passed directly to git-blame.
177 Produce output in the same format as `git blame', but with
178 SVN revision numbers instead of git commit hashes. In this mode,
179 changes that haven't been committed to SVN (including local
180 working-copy edits) are shown as revision 0.
184 When given an SVN revision number of the form 'rN', returns the
185 corresponding git commit hash (this can optionally be followed by a
186 tree-ish to specify which branch should be searched). When given a
187 tree-ish, returns the corresponding SVN revision number.
190 You should consider using 'dcommit' instead of this command.
191 Commit specified commit or tree objects to SVN. This relies on
192 your imported fetch data being up-to-date. This makes
193 absolutely no attempts to do patching when committing to SVN, it
194 simply overwrites files with those specified in the tree or
195 commit. All merging is assumed to have taken place
196 independently of git-svn functions.
199 Recursively finds the svn:ignore property on directories and
200 creates matching .gitignore files. The resulting files are staged to
201 be committed, but are not committed. Use -r/--revision to refer to a
205 Recursively finds and lists the svn:ignore property on
206 directories. The output is suitable for appending to
207 the $GIT_DIR/info/exclude file.
210 Commits the diff of two tree-ish arguments from the
211 command-line. This command is intended for interoperability with
212 git-svnimport and does not rely on being inside an git-svn
213 init-ed repository. This command takes three arguments, (a) the
214 original tree to diff against, (b) the new tree result, (c) the
215 URL of the target Subversion repository. The final argument
216 (URL) may be omitted if you are working from a git-svn-aware
217 repository (that has been init-ed with git-svn).
218 The -r<revision> option is required for this.
221 Shows information about a file or directory similar to what
222 `svn info' provides. Does not currently support a -r/--revision
223 argument. Use the --url option to output only the value of the
227 Lists the properties stored in the Subversion repository about a
228 given file or directory. Use -r/--revision to refer to a specific
232 Gets the Subversion property given as the first argument, for a
233 file. A specific revision can be specified with -r/--revision.
236 Shows the Subversion externals. Use -r/--revision to specify a
245 --shared[={false|true|umask|group|all|world|everybody}]::
246 --template=<template_directory>::
247 Only used with the 'init' command.
248 These are passed directly to linkgit:git-init[1].
253 Used with the 'fetch' command.
255 This allows revision ranges for partial/cauterized history
256 to be supported. $NUMBER, $NUMBER1:$NUMBER2 (numeric ranges),
257 $NUMBER:HEAD, and BASE:$NUMBER are all supported.
259 This can allow you to make partial mirrors when running fetch;
260 but is generally not recommended because history will be skipped
266 Only used with the 'set-tree' command.
268 Read a list of commits from stdin and commit them in reverse
269 order. Only the leading sha1 is read from each line, so
270 git-rev-list --pretty=oneline output can be used.
274 Only used with the 'dcommit', 'set-tree' and 'commit-diff' commands.
276 Remove directories from the SVN tree if there are no files left
277 behind. SVN can version empty directories, and they are not
278 removed by default if there are no files left in them. git
279 cannot version empty directories. Enabling this flag will make
280 the commit to SVN act like git.
282 config key: svn.rmdir
287 Only used with the 'dcommit', 'set-tree' and 'commit-diff' commands.
289 Edit the commit message before committing to SVN. This is off by
290 default for objects that are commits, and forced on when committing
296 --find-copies-harder::
298 Only used with the 'dcommit', 'set-tree' and 'commit-diff' commands.
300 They are both passed directly to git-diff-tree see
301 linkgit:git-diff-tree[1] for more information.
305 config key: svn.findcopiesharder
308 --authors-file=<filename>::
310 Syntax is compatible with the files used by git-svnimport and
313 ------------------------------------------------------------------------
314 loginname = Joe User <user@example.com>
315 ------------------------------------------------------------------------
317 If this option is specified and git-svn encounters an SVN
318 committer name that does not exist in the authors-file, git-svn
319 will abort operation. The user will then have to add the
320 appropriate entry. Re-running the previous git-svn command
321 after the authors-file is modified should continue operation.
323 config key: svn.authorsfile
327 Make git-svn less verbose.
330 --repack-flags=<flags>::
332 These should help keep disk usage sane for large fetches
335 --repack takes an optional argument for the number of revisions
336 to fetch before repacking. This defaults to repacking every
337 1000 commits fetched if no argument is specified.
339 --repack-flags are passed directly to linkgit:git-repack[1].
342 config key: svn.repack
343 config key: svn.repackflags
348 --strategy=<strategy>::
350 These are only used with the 'dcommit' and 'rebase' commands.
352 Passed directly to git-rebase when using 'dcommit' if a
353 'git-reset' cannot be used (see dcommit).
358 This is only used with the 'dcommit' command.
360 Print out the series of git arguments that would show
361 which diffs would be committed to SVN.
372 This sets GIT_SVN_ID (instead of using the environment). This
373 allows the user to override the default refname to fetch from
374 when tracking a single URL. The 'log' and 'dcommit' commands
375 no longer require this switch as an argument.
378 --svn-remote <remote name>::
379 Specify the [svn-remote "<remote name>"] section to use,
380 this allows SVN multiple repositories to be tracked.
384 This is especially helpful when we're tracking a directory
385 that has been moved around within the repository, or if we
386 started tracking a branch and never tracked the trunk it was
387 descended from. This feature is enabled by default, use
388 --no-follow-parent to disable it.
390 config key: svn.followparent
393 CONFIG FILE-ONLY OPTIONS
394 ------------------------
398 svn-remote.<name>.noMetadata::
400 This gets rid of the git-svn-id: lines at the end of every commit.
402 If you lose your .git/svn/git-svn/.rev_db file, git-svn will not
403 be able to rebuild it and you won't be able to fetch again,
404 either. This is fine for one-shot imports.
406 The 'git-svn log' command will not work on repositories using
407 this, either. Using this conflicts with the 'useSvmProps'
408 option for (hopefully) obvious reasons.
411 svn-remote.<name>.useSvmProps::
413 This allows git-svn to re-map repository URLs and UUIDs from
414 mirrors created using SVN::Mirror (or svk) for metadata.
416 If an SVN revision has a property, "svm:headrev", it is likely
417 that the revision was created by SVN::Mirror (also used by SVK).
418 The property contains a repository UUID and a revision. We want
419 to make it look like we are mirroring the original URL, so
420 introduce a helper function that returns the original identity
421 URL and UUID, and use it when generating metadata in commit
424 svn.useSvnsyncProps::
425 svn-remote.<name>.useSvnsyncprops::
426 Similar to the useSvmProps option; this is for users
427 of the svnsync(1) command distributed with SVN 1.4.x and
430 svn-remote.<name>.rewriteRoot::
431 This allows users to create repositories from alternate
432 URLs. For example, an administrator could run git-svn on the
433 server locally (accessing via file://) but wish to distribute
434 the repository with a public http:// or svn:// URL in the
435 metadata so users of it will see the public URL.
437 Since the noMetadata, rewriteRoot, useSvnsyncProps and useSvmProps
438 options all affect the metadata generated and used by git-svn; they
439 *must* be set in the configuration file before any history is imported
440 and these settings should never be changed once they are set.
442 Additionally, only one of these four options can be used per-svn-remote
443 section because they affect the 'git-svn-id:' metadata line.
450 Tracking and contributing to the trunk of a Subversion-managed project:
452 ------------------------------------------------------------------------
453 # Clone a repo (like git clone):
454 git-svn clone http://svn.foo.org/project/trunk
455 # Enter the newly cloned directory:
457 # You should be on master branch, double-check with git-branch
459 # Do some work and commit locally to git:
461 # Something is committed to SVN, rebase your local changes against the
462 # latest changes in SVN:
464 # Now commit your changes (that were committed previously using git) to SVN,
465 # as well as automatically updating your working HEAD:
467 # Append svn:ignore settings to the default git exclude file:
468 git-svn show-ignore >> .git/info/exclude
469 ------------------------------------------------------------------------
471 Tracking and contributing to an entire Subversion-managed project
472 (complete with a trunk, tags and branches):
474 ------------------------------------------------------------------------
475 # Clone a repo (like git clone):
476 git-svn clone http://svn.foo.org/project -T trunk -b branches -t tags
477 # View all branches and tags you have cloned:
479 # Reset your master to trunk (or any other branch, replacing 'trunk'
480 # with the appropriate name):
481 git reset --hard remotes/trunk
482 # You may only dcommit to one branch/tag/trunk at a time. The usage
483 # of dcommit/rebase/show-ignore should be the same as above.
484 ------------------------------------------------------------------------
486 The initial 'git-svn clone' can be quite time-consuming
487 (especially for large Subversion repositories). If multiple
488 people (or one person with multiple machines) want to use
489 git-svn to interact with the same Subversion repository, you can
490 do the initial 'git-svn clone' to a repository on a server and
491 have each person clone that repository with 'git clone':
493 ------------------------------------------------------------------------
494 # Do the initial import on a server
495 ssh server "cd /pub && git-svn clone http://svn.foo.org/project
496 # Clone locally - make sure the refs/remotes/ space matches the server
500 git remote add origin server:/pub/project
501 git config --add remote.origin.fetch=+refs/remotes/*:refs/remotes/*
503 # Initialize git-svn locally (be sure to use the same URL and -T/-b/-t options as were used on server)
504 git-svn init http://svn.foo.org/project
505 # Pull the latest changes from Subversion
507 ------------------------------------------------------------------------
509 REBASE VS. PULL/MERGE
510 ---------------------
512 Originally, git-svn recommended that the remotes/git-svn branch be
513 pulled or merged from. This is because the author favored
514 'git-svn set-tree B' to commit a single head rather than the
515 'git-svn set-tree A..B' notation to commit multiple commits.
517 If you use 'git-svn set-tree A..B' to commit several diffs and you do
518 not have the latest remotes/git-svn merged into my-branch, you should
519 use 'git-svn rebase' to update your work branch instead of 'git pull' or
520 'git merge'. 'pull/merge' can cause non-linear history to be flattened
521 when committing into SVN, which can lead to merge commits reversing
522 previous commits in SVN.
526 Merge tracking in Subversion is lacking and doing branched development
527 with Subversion can be cumbersome as a result. While git-svn can track
528 copy history (including branches and tags) for repositories adopting a
529 standard layout, it cannot yet represent merge history that happened
530 inside git back upstream to SVN users. Therefore it is advised that
531 users keep history as linear as possible inside git to ease
532 compatibility with SVN (see the CAVEATS section below).
537 For the sake of simplicity and interoperating with a less-capable system
538 (SVN), it is recommended that all git-svn users clone, fetch and dcommit
539 directly from the SVN server, and avoid all git-clone/pull/merge/push
540 operations between git repositories and branches. The recommended
541 method of exchanging code between git branches and users is
542 git-format-patch and git-am, or just dcommiting to the SVN repository.
544 Running 'git-merge' or 'git-pull' is NOT recommended on a branch you
545 plan to dcommit from. Subversion does not represent merges in any
546 reasonable or useful fashion; so users using Subversion cannot see any
547 merges you've made. Furthermore, if you merge or pull from a git branch
548 that is a mirror of an SVN branch, dcommit may commit to the wrong
551 'git-clone' does not clone branches under the refs/remotes/ hierarchy or
552 any git-svn metadata, or config. So repositories created and managed with
553 using git-svn should use rsync(1) for cloning, if cloning is to be done
556 Since 'dcommit' uses rebase internally, any git branches you git-push to
557 before dcommit on will require forcing an overwrite of the existing ref
558 on the remote repository. This is generally considered bad practice,
559 see the git-push(1) documentation for details.
561 Do not use the --amend option of git-commit(1) on a change you've
562 already dcommitted. It is considered bad practice to --amend commits
563 you've already pushed to a remote repository for other users, and
564 dcommit with SVN is analogous to that.
569 We ignore all SVN properties except svn:executable. Any unhandled
570 properties are logged to $GIT_DIR/svn/<refname>/unhandled.log
572 Renamed and copied directories are not detected by git and hence not
573 tracked when committing to SVN. I do not plan on adding support for
574 this as it's quite difficult and time-consuming to get working for all
575 the possible corner cases (git doesn't do it, either). Committing
576 renamed and copied files are fully supported if they're similar enough
577 for git to detect them.
582 git-svn stores [svn-remote] configuration information in the
583 repository .git/config file. It is similar the core git
584 [remote] sections except 'fetch' keys do not accept glob
585 arguments; but they are instead handled by the 'branches'
586 and 'tags' keys. Since some SVN repositories are oddly
587 configured with multiple projects glob expansions such those
588 listed below are allowed:
590 ------------------------------------------------------------------------
591 [svn-remote "project-a"]
592 url = http://server.org/svn
593 branches = branches/*/project-a:refs/remotes/project-a/branches/*
594 tags = tags/*/project-a:refs/remotes/project-a/tags/*
595 trunk = trunk/project-a:refs/remotes/project-a/trunk
596 ------------------------------------------------------------------------
598 Keep in mind that the '*' (asterisk) wildcard of the local ref
599 (right of the ':') *must* be the farthest right path component;
600 however the remote wildcard may be anywhere as long as it's own
601 independent path component (surrounded by '/' or EOL). This
602 type of configuration is not automatically created by 'init' and
603 should be manually entered with a text-editor or using
604 linkgit:git-config[1]
608 linkgit:git-rebase[1]
612 Written by Eric Wong <normalperson@yhbt.net>.
616 Written by Eric Wong <normalperson@yhbt.net>.