Branches mapping is a set of rules that establish a correspondence between SVN and Git branches and tags. These rules are defined by branches mapping configuration options in SubGit configuration file.
| Table of Contents |
|---|
Branches and Tags in Subversion.
| Anchor | ||||
|---|---|---|---|---|
|
There are few key Subversion concepts, that matter in the context of SubGit mapping process:
...
A graphical representation of the explained SVN concepts:
Branches and Tags in Git
| Anchor | ||||
|---|---|---|---|---|
|
Unlike SVN, which stores data in the form of a filesystem tree, Git represents its data as a set of snapshots of a filesystem, that is being stored in Git's objects database. Due to this difference, most of Git concepts differ from their SVN counterparts albeit have the same names:
- repository – a directory, that contains Git database and metadata.
- commit – a Git object, that contains containing a pointer to a data snapshot in Git database. Essentially, the commit is a hash-named file in Git database, that contains a reference to a tree object, representing a data snapshot in time.branch file tree snapshot along with author and date information. Commit is identified by its SHA1 hash value.
- branch – a reference to certain commit; a file in a Git database that contains a hash of a certain commit, thus referencing that particular commit.
- master branch – a default branch called master that's being created along with new repository. By agreement, it represents the main line of development, but technically it's just another branch.
- tag – like a branch, a reference to a commit - a file in a Git database that contains a hash of that particular commit. Git supports two kinds of *tags*: *lightweight* and *annotated*; SubGit supports only *lightweight tags*.
A graphical representation of the explained Git concepts:
Mapping Configuration Options
| Anchor | ||||
|---|---|---|---|---|
|
All the mapping configuration assembled in SubGit configuration file. The configuration file is being created at the SVN-to-Git translation beginning by SubGit's configure subcommand. The file , that is situated in subgit subdirectory inside a newly created Git repository:
| Code Block | ||||||
|---|---|---|---|---|---|---|
| ||||||
/GIT_REPOS_PATH … /subgit … /subgit/config |
Here is an example of how the [svn] of the configuration file may look like:
...
- SVN project location:
- url - a URL leading to the SVN project.
- url - a URL leading to the SVN project.
- Branches and tags mapping rules:
- trunk - a path, relative to the URL, that leads to project's trunk.
- branches - a relative path to a directory, containing branches, or a path to a particular branch.
- tags - a relative path to a directory, containing tags, or a path to a particular tag.
- shelves - a relative path to a directory, where *shelves* will be kept.
- Refining mapping rules:
- excludeBranches - a relative path or path pattern with one wildcard, that point to branches or tags, that should be excluded from translation.
- excludeTags - same as excludeBranches.
- excludePath - an expression, representing files to be excluded from the translation.
- includePath - an expression, representing files to be included in the translation.
svn.urlAnchor svn.url svn.url
| Anchor | ||||
|---|---|---|---|---|
|
This option sets a URL to the SVN project, that is being translated into Git repository. SubGit translates a SVN project into a Git repository: not whole SVN repository to Git repository:
...
- Mapping-option - essentially, a mapping option: trunk, branches, tags or shelves.
- Subversion-Path-Pattern – a SVN directory path relative to `svn.url`.
- Git-Reference-Pattern – a path inside Git repository where references will be stored.
svn.trunkAnchor svn.trunk svn.trunk
| Anchor | ||||
|---|---|---|---|---|
|
This setting establishes a correspondence between SVN *trunk* and Git branch that represents the main line of development. Assuming, that SVN "main line of development" is being kept in a directory named trunk and Git master branch represents the "main line" in Git, the mapping may look like this:
...
| Info | ||
|---|---|---|
| ||
|
svn.branchesAnchor svn.branches svn.branches
This setting establishes a correspondence between SVN and Git branches. Its default value assumes standard SVN layout is used, i.e. that a SVN project branches reside in a directory named branches:
...
| Code Block | ||||||
|---|---|---|---|---|---|---|
| ||||||
branches = branches/*:refs/heads/* branches = feature_*:refs/heads/features/* branches = hotfix/*_*:refs/heads/hotfix/*/* branches = special_branch:refs/heads/special_branch |
svn.tagsAnchor svn.tags svn.tags
| Anchor | ||||
|---|---|---|---|---|
|
This setting establishes a correspondence between SVN and Git tags. The default value assumes standard SVN layout:
...
| Code Block | ||||||
|---|---|---|---|---|---|---|
| ||||||
tags = 1.0/*:refs/tags/1.0/* tags = 1.5.*:refs/tags/1.5/* tags = tags/2.0.*/*:refs/tags/2.0/*/* tags = tags/special_tag:refs/tags/special_tag |
svn.shelvesAnchor svn.shelves svn.shelves
| Anchor | ||||
|---|---|---|---|---|
|
Shelves are special entities being introduced by SubGit. SubGit creates shelves when it cannot determine branch name where particular commit belongs to. For example, a shelf will appear in SVN after in the following case:
...
In such case, SubGit will be able to see all the commits, but won’t be able to recognize the branch name to which they belong. So it will place them into shelves SVN directory.
Find more details on the shelves in See a blog post "What are shelves really?" blog post. for more details on shelves.
The setting sets a directory in SVN where shelves will be stored:
...
| Info | ||
|---|---|---|
| ||
|
svn.excludeBranches, svn.excludeTagsAnchor svn.excludeBranches svn.excludeBranches
svn.excludeTagsAnchor svn.excludeBranches svn.excludeBranches
These two settings do reverse job: while all the previous settings tell what to include, these tell SubGit which branches or tags to be excluded from translation. They are interchangeable, any of the two can be used to exclude both *branches* and *tags*.
...
| No Format |
|---|
http://example.com/svn/repository/Project1/branches/feature_* |
svn.excludePath, svn.includePathAnchor svn.excludePath svn.excludePath
| Anchor | ||||
|---|---|---|---|---|
|
These are settings that provide a possibility to exclude (or vice versa, include) some files from translation. It may be useful e.g. if you have some big files in SVN that you don't want to be present in Git repository. The syntax is simple:
excludePath = PATTERNincludePath = PATTERN
| Warning |
|---|
The |
The PATTERN is an expression that represents files to be excluded or included. Its format is described below:
- The
PATTERNcan be recursive and non-recursive.- A
PATTERNis treated as recursive if it doesn't contain slashes "/". SubGit will recursively search all specified trunk, branches and tags directories and exclude all files whose names match to thePATTERN.
A recursive example:excludePath = *.html
SubGit will exclude all the *.html files in all the mapped directories. A
PATTERNis treated as non-recursive if it does contain one or more slashes "/". SubGit will exclude any files in trunk, branches and tags directories, paths to which match to thePATTERN.
A non-recursive example:
excludePath = */*.html
SubGit will search for *.html files in second level directories within trunk, branches and tags directories, i.e. it will exclude the following files:No Format nopanel true http://example.com/svn/project/trunk/*/*.html http://example.com/svn/project/branches/*/*/*.html http://example.com/svn/project/tags/*/*/*.html
- A
A particular non-recursive
PATTERNcase with leading slash "/" represents a particular path to be excluded or included. E.g., if standard SVN project layout is used andsvn.urlis set to the following:No Format nopanel true http://example.com/svn/projectAnd
svn.includePathis set like this:Code Block language text theme FadeToGrey title svn.includePath includePath = /DocsSuch the setting will include only 'Docs' directory within trunk, branches and tags directories: that means SubGit will translate only paths below:
No Format nopanel true http://example.com/svn/project/trunk/Docs http://example.com/svn/project/branches/*/Docs http://example.com/svn/project/tags/*/DocsSimilarly, the following settings will exclude all the *.html files within 'Docs' directory in trunk, branches and tags directories:
Code Block language text theme FadeToGrey title svn.excludePath excludePath = /Docs/*.htmlThat is such setting will exclude the following paths:
No Format nopanel true http://example.com/svn/project/trunk/Docs/*.html http://example.com/svn/project/branches/*/Docs/*.html http://example.com/svn/project/tags/*/Docs/*.html- Trailing slash "/" in non-recursive
PATTERNis not allowed. - A wildcard "*" means as any number of legal symbols. It can be used both in recursive or non-recursive patterns.
- A question mark "?" means any one legal symbol. It can be used both in recursive or non-recursive patterns.
Brackets "[ ]" set a list of possible characters in the
PATTERN:Code Block language text theme FadeToGrey title svn.excludePath excludePath = [aoe]*.htmlSuch the setting will recursively exclude all the \*.html files which name starts with 'a', 'o' or 'e'.
Spaces within the
PATTERNare allowed:Code Block language text theme FadeToGrey title excludePath excludePath = some file name excludePath = some directory/*.exebut leading and trailing spaces need to be quoted:
Code Block language text theme FadeToGrey title svn.includePath includePath = "filename " includePath = "directory /*.exe"otherwise, SubGit will ignore leading/trailing spaces.
Warning Note, that if you have two directories or files at the same SVN file structure level, whose names differ only by leading or trailing spaces - say, "Docs" and "Docs " — that one containing trailing or leading spaces will not be imported/mirrored!
Two consecutive asterisks "**" in non-recursive
PATTERNmean path of any length.A
PATTERNwith leading asterisks:Code Block language text theme FadeToGrey title excludePath excludePath = **/foo/*.exemeans foo directory with *.exe files anywhere in SVN project. Leading asterisks pattern has some peculiarity: if you have a directory where all the files match given
PATTERN– then not only files will be excluded, the directory itself will not be mirrored/imported as well. Thus, if foo directory contains only *.exe files, then foo will not be imported/mirrored.Trailing asterisks allows to create non-recursive pattern that will match to directories only, namely:
Code Block language text theme FadeToGrey title svn.excludePath excludePath = Docs/**will exclude Docs directory in trunk, branches and tags root, but won't touch files with the name Docs.
Two consecutive asterisks within path pattern mean a path of any length; that is, setting like:
Code Block language text theme FadeToGrey title svn.excludePath excludePath = Docs/**/*.exewill exclude any *.exe files in Docs directory and all its subdirectories.
When branches, tags or paths are excluded from the translation with the help of one of the above options, modifications to those branches or paths made in Subversion project would not be translated to Git, as well as changes in Git repository made to those locations would not appear in Subversion.
Related documentation.
Branches and tags mapping examples

