Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 78 ยท Getting Started

Git vs Subversion, Mercurial and Perforce

Compare Git with Subversion, Mercurial and Perforce: central versus distributed design, branching, binaries and scale, plus how to migrate a repository to Git.

Git is the most widely used version control system today, but it was never the only one, and many teams still run something else. You may inherit a Subversion repository from a company that was founded in 2005, meet Mercurial at an open-source project that adopted it early, or join a game studio that keeps terabytes of art in Perforce. Knowing how these tools differ from Git helps you move between them, argue for (or against) a migration with facts, and understand why Git behaves the way it does.

This lesson compares the design of the four systems, shows two of Git's central ideas in a running example, and then walks through migrating history into Git, including a real conversion you can run in your browser with git fast-import. If you have not yet seen how Git stores data, How Git Works is a good warm-up.

Three generations: local, centralized and distributed

Version control grew up in three steps, and each step fixed a problem of the one before.

Generation Where history lives Examples Problem it solved Problem it left
Local One database on your own machine SCCS (1972, Bell Labs), RCS (early 1980s) Stop copying report_final_v2_REAL.doc; track every change to a file One user at a time, per file, on one computer
Centralized One server; everyone has a working copy CVS (late 1980s), Subversion (2000), Perforce (1995) Many people work together on one project The server is a single point of failure, you need the network to commit or view history, and branching is expensive
Distributed Every clone holds the full history Git (2005), Mercurial (2005), Bazaar (2005, now continued as Breezy), Darcs, Fossil Work offline, commit and branch locally, no single point of failure More concepts to learn (clone, remote, rebase)

Local systems such as RCS stored each file's changes next to the file, in a small ,v history file, and used locks: while you edited a file nobody else could. CVS put RCS behind a server and replaced locking with merging, so two people could edit the same file, but it tracked files one by one: commits were not atomic across files, and renaming a file lost its history. Subversion was designed explicitly as "CVS done right": atomic commits, tracked renames, repository-wide revision numbers. It is still common in companies that began before 2010.

Distributed systems appeared when the Linux kernel community needed to work on a huge project with hundreds of contributors, many offline. The kernel used the proprietary BitKeeper from 2002; when the licence arrangement ended in 2005, Linus Torvalds wrote Git in a few weeks, and Mercurial started in the same month with similar goals. Bazaar, backed by Canonical, followed the same year but lost ground to Git. By the 2010s, hosting services such as GitHub, which are not part of Git, made it the default.

Keep one thing in mind for the rest of this lesson: "distributed" describes where the history lives, not how a team behaves. Most teams still agree on one shared remote that acts as the official copy, so a Git workflow looks centralized in practice while keeping the benefits of local history.

Two families: centralized and distributed

Every version control system answers one question first: where does the history live?

flowchart LR
  subgraph Central["Centralized (Subversion, Perforce)"]
    S[("Server<br/>full history")]
    W1["Working copy A"] --> S
    W2["Working copy B"] --> S
  end
  subgraph Dist["Distributed (Git, Mercurial)"]
    R1[("Clone A<br/>full history")]
    R2[("Clone B<br/>full history")]
    H[("Shared remote<br/>full history")]
    R1 <--> H
    R2 <--> H
  end

In a centralized system only the server has the history; in a distributed one every clone has all of it.

In a centralized system, the server owns the repository. A working copy contains one version of the files plus bookkeeping. Almost every history question (log, diff against an old revision, blame) is a network request, and a commit goes straight to the server. If the server is unreachable, you cannot commit.

In a distributed system every clone is a complete repository. You commit locally, browse history offline and later exchange commits with other repositories through push and pull. A shared remote is a convention, not a technical requirement. The following example shows the consequence: after we delete the "server", the clone still has everything.

Bash Every clone carries the full history

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Perforce and Subversion have ways to reduce the pain (Subversion's svnsync mirrors, Perforce's proxies and edge servers), but the design stays server-first. Mercurial, like Git, is distributed.

Snapshots, deltas and revision numbers

Subversion and Perforce think in changes to a central numbered history. Subversion gives every commit a repository-wide revision number (r1, r2, r3 ...), so "revision 4021" is a single, ordered, global name. Perforce numbers changelists the same way. Numbers like these are only possible when one server hands them out in order.

Git cannot do that, because two people can create commits at the same moment without talking to each other. Instead, a commit's name is the hash of its content, and each commit stores a complete snapshot of the project tree (unchanged files are shared, not copied; see Git Objects). Mercurial uses a mix: it stores deltas in "revlogs" and gives each repository local sequence numbers, but also a stable hash, and tells you to rely only on the hash when sharing.

Topic Subversion Perforce (Helix Core) Mercurial Git
Model Centralized Centralized Distributed Distributed
Commit name Global revision number Global changelist number Local number plus hash Hash
Unit of storage Deltas per file Deltas per file Deltas per file (revlog) Snapshots (trees)
Branches Directory copies Streams or path copies Named branches, bookmarks Cheap pointers
Offline commits No Limited Yes Yes
Staging area No No (pending changelists) No Yes (the index)
Large binary files Fine Excellent (exclusive locks) Weak Needs Git LFS
Partial checkout of one folder Natural Natural Awkward Sparse checkout

Branching is the big difference

In Subversion a branch is a copy of a directory inside the repository, by convention under branches/. The copy is cheap on the server, but merging used to be painful, because the tool had to track by hand which revisions had already been merged; newer versions record merge information in properties and are better. Since a branch is just another folder, you check it out as a second working copy and switch with svn switch.

In Git a branch is a 41-byte file holding a commit hash. Creating one costs nothing, so branching for every idea is normal. Merge commits remember both parents, so Git always knows what has been merged. Compare it with Subversion's folder copies in this snapshot demo:

Bash A snapshot per commit, a branch per pointer

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Mercurial offers two branching styles: permanent named branches (stored in each commit) and bookmarks (movable pointers, closest to Git branches). Many Mercurial users find bookmarks plus the evolve extension comfortable, and its commands are often described as more regular than Git's. Perforce uses streams, a managed hierarchy (mainline, development, release) where changes flow between parents and children under the server's rules.

Where the others are still stronger

Be fair when comparing. Git's weak spots are real:

  • Huge binary assets. Perforce handles multi-gigabyte textures and exclusive locks (so two artists never edit the same unmergeable file) very well. Git needs Git LFS and file locking by convention.
  • Giant monorepos with path permissions. Perforce and Subversion can restrict who sees which folder. Git permissions apply to the whole repository, so you split repositories or use platform features. Techniques such as sparse checkout and partial clones help with size but not with secrecy.
  • A simpler mental model. Subversion has no staging area and no rebase; for a team of non-programmers (designers, writers) that can be a feature.
  • Learning curve. Git's command set is large and inconsistent in places. Mercurial's CLI is smaller.

On the other side, Git wins on speed for local operations, cheap branching, a huge ecosystem (hosting, CI, editors, code review) and the sheer number of developers who already know it, which usually decides the matter in practice.

Migrating a repository to Git

A migration has three questions: how much history to bring, how to map authors, and how to map branches and tags. Plan them before you run a single command.

  1. Decide the history depth. Many teams import everything. If the old repository is huge or messy, import recent history and keep the old server read-only as an archive.
  2. Prepare an author map. Subversion stores only user names such as jdoe; Git wants a name and an email. You write a file mapping one to the other.
  3. Convert, check, and have a few people review the result before you switch everyone over.
  4. Freeze the old system (read-only), push the Git repository to its new home, and update CI, hooks and documentation.

The usual tools are shown below. They need software that our browser sandbox does not include (Subversion, Mercurial, Perforce, Perl), so these blocks are read-only.

Terminal
# read-only: Subversion with the standard trunk/branches/tags layout
git svn clone --stdlayout --authors-file=authors.txt \
    https://svn.example.com/project project-git

# read-only: turn SVN branches and tags into real Git branches and tags
cd project-git
git for-each-ref refs/remotes/origin/tags   # tags arrive as remote branches
git tag v1.0 refs/remotes/origin/tags/v1.0  # repeat per tag, then delete the remote refs

# read-only: Mercurial (hg-fast-export or git-remote-hg)
git init project-git && cd project-git
hg-fast-export.sh -r ../project-hg -A authors.txt

# read-only: Perforce (the git p4 command ships with Git)
git p4 clone //depot/project@all --destination project-git

git svn works revision by revision and can take hours or days on a large repository. After the conversion, tags need special care, because Subversion tags are just directory copies that may have changed after they were created.

Writing your own converter with fast-import

All these tools ultimately feed Git through a plain-text format understood by git fast-import. It reads a stream of commit, from, M (file modification) and tag commands and creates the objects directly. This is also the best way to convert something exotic for which no ready-made tool exists: write a small script that prints the stream.

The next example imports a tiny "old repository" with two revisions and a tag. Fixed timestamps make the result reproducible.

Bash Converting history with git fast-import

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

The mark :1 lines give commits temporary names inside the stream, and from :1 says "my parent is that commit". The author names came from the converter's author map, and the timestamps are Unix seconds. A real converter loops over the old revisions and prints one block per revision.

After any migration, compare the old and new systems at several revisions: check out the same point in both and run diff -r on the trees. Fix problems before developers start working in the new repository.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the main design difference between Subversion and Git?

    Subversion is centralized: the server owns the history and a working copy holds one version. Git is distributed, so each clone is a complete repository that works offline.
  2. 2. Why does Git not use sequential revision numbers like r4021?

    Global ordered numbers need one server. Git names commits by the hash of their content, which any clone can compute without coordination.
  3. 3. Which system is usually best for huge binary assets with exclusive file locks?

    Perforce is built for large binary files and exclusive checkout. Git needs Git LFS and a locking convention for similar workloads.
  4. 4. What does git fast-import read?

    fast-import is the common back end of conversion tools. A converter prints the stream and fast-import creates commits, trees, blobs and tags quickly.
  5. 5. Which step should you plan before running a Subversion to Git conversion?

    Subversion records only user names, so you provide a mapping file to give Git commits proper author names and email addresses.

Summary

  • Subversion and Perforce are centralized: the server owns the history, commits go to it, and revisions have global numbers. Git and Mercurial are distributed: every clone holds the whole history.
  • Git stores snapshots named by content hashes; its branches are tiny pointer files, while Subversion branches are directory copies.
  • Perforce remains strong for huge binary assets, locks and path-level permissions; Git relies on LFS, sparse checkout and splitting repositories.
  • Migrate with git svn, hg-fast-export or git p4 when they fit, or write your own converter that emits a git fast-import stream.
  • Plan history depth, author map and branch and tag mapping first, verify the result against the old system, then freeze the old one.

Next: Status and Diff