Git (software)

From Wikipedia, the free encyclopedia

Git
Image:git-logo.png
Developer: Linus Torvalds, Junio Hamano
Latest release: 1.5.0.5 / March 18, 2007[1]
OS: POSIX
Use: Revision control system
License: GNU General Public License
Website: http://git.or.cz/

Git is a distributed revision control / software configuration management project created by Linus Torvalds to manage software development of the Linux kernel. Notable users of Git include the Linux kernel, Cairo, ELinks, GNU Core Utilities, GNU LilyPond, Mesa 3D, Wine, most X.org projects, XMMS2, Beryl and One Laptop Per Child.[2]

Git's design was inspired by Monotone.[3] Git was originally designed only as a low-level engine that others could use to write front ends such as Cogito or StGIT.[4] However, the core Git project has since become a complete revision control system that is usable directly.[5]

Git's current software maintenance is overseen by Junio Hamano. Released under the GNU General Public License, version 2, Git is open source software.

Contents

[edit] Name

Linus Torvalds has quipped about the name "git":

"I'm an egotistical bastard, and I name all my projects after myself. First 'Linux', now 'git'"

The official Git wiki also gives a number of alternative explanations for the name.[6]

[edit] Unique characteristics

Git's design is a synthesis of Torvalds' intimate knowledge of maintaining a large distributed development project, and of file system performance. Combined with his urgent need to produce a working system in short order, these factors led to the following characteristics:

  • Strong support for non-linear development. Git supports rapid and convenient branching and merging, and includes powerful tools for visualizing and navigating a non-linear development history. A core assumption in Git is that a change will be merged more often than it is written, as it is passed around various reviewers. Torvalds himself does the most merging and least direct editing, so he has made sure that it works well.
  • Distributed development. Like BitKeeper, Mercurial, SVK and Monotone, Git gives each developer a local copy of the entire development history, and changes are copied from one such repository to another. These changes are imported as additional development branches, and can be merged in the same way as a locally developed branch.
  • Repositories can be easily published via HTTP, FTP, ssh, rsync, or a special git protocol. Git also has a CVS server emulation, which allows one to use existing CVS clients and IDE integrations to access Git repositories.
  • Efficient handling of large projects. Git is very fast, and scales well. It is commonly an order of magnitude faster than other revision control systems, and several orders of magnitude faster on some operations.[citation needed]
  • Cryptographic authentication of history. The Git history is stored in such a way that the name of a particular revision (a "commit" in Git terms) depends upon the complete development history leading up to that commit. Once it is published, it is not possible to change the old versions without it being noticed. (Monotone also has this property.)
  • Toolkit design. Following the Unix tradition, Git is a set of primitive programs written in C, and a large number of shell scripts that provide convenient wrappers. It is easy to chain the components together to do other clever things.
  • Pluggable merge strategies. As part of its toolkit design, git has a well-defined model of an incomplete merge, and it has multiple algorithms for completing it, culminating in telling the user that it is unable to complete the merge automatically and manual editing is required. It is thus easy to experiment with new merge algorithms.
  • Garbage accumulates unless collected. Aborting operations or backing out changes will leave useless dangling objects in the database. These are generally a small fraction of the continuously growing history of wanted objects, but reclaiming the space using git-gc --prune can be slow.

One property of Git that has led to considerable controversy is that it snapshots directory trees of files. The earliest systems for tracking versions of source code, SCCS and RCS, worked on individual files and emphasized the space savings to be gained from delta encoding the (mostly similar) versions. Later revision control systems maintained this notion of a file having an identity across multiple revisions of a project.

Git rejects this concept[7] and does not explicitly record file revision relationships at any level below the source code tree. This has some significant consequences:

  • It is actually slightly more expensive to examine the change history of a single file than the whole project[8]. To obtain a history of changes affecting a given file, Git must walk the global history and then determine whether each change modified that file. This method of examining history does, however, let Git produce with equal efficiency a single history showing the changes to an arbitrary set of files. For example, a subdirectory of the source tree plus an associated global header file.
  • Renames are handled implicitly rather than explicitly. A major complaint with CVS is that it uses the name of a file to identify its revision history, so moving or renaming a file is not possible without either interrupting its history, or renaming the history and thereby making the history inaccurate. Most post-CVS revision control systems solve this by giving a file a unique long-lived name (a sort of inode number) that survives renaming. Git does not record such an identifier, and this is claimed as an advantage[9][10]. Source code files are sometimes split or merged as well as simply renamed[11], and recording this as a simple rename would freeze an inaccurate description of what happened in the (immutable) history. Git addresses the issue by detecting renames while browsing the history of snapshots rather than recording it when making the snapshot[12]. (Briefly, given a file in revision N, a file of the same name in revision N-1 is its default ancestor. However, when there is no like-named file in revision N-1, Git searches for a file that existed only in revision N-1 and is very similar to the new file.) However, it does require more CPU-intensive work every time history is reviewed, and a number of options to adjust the heuristics.

Additionally, people are sometimes upset by the storage model:

  • Periodic explicit object packing. Git stores each newly created object as a separate file. Although individually compressed, this takes a great deal of space and is inefficient. This is solved by the use of "packs" that store a large number of objects in a single file (or network byte stream), delta-compressed among themselves. Packs are compressed using the heuristic that files with the same name are probably similar, but do not depend on it for correctness. Newly created objects (newly added history) are still stored singly, and periodic repacking is required to maintain space efficiency.

Git implements several merging strategies; a non-default can be selected at merge time [1]:

  • resolve: the traditional 3-way merge algorithm.
  • recursive: This is the default when pulling or merging one branch, and is a variant of the 3-way merge algorithm. "When there are more than one common ancestors that can be used for 3-way merge, it creates a merged tree of the common ancestors and uses that as the reference tree for the 3-way merge. This has been reported to result in fewer merge conflicts without causing mis-merges by tests done on actual merge commits taken from Linux 2.6 kernel development history. Additionally this can detect and handle merges involving renames." [2]
  • octopus: This is the default when merging more than two heads.

[edit] Early history

Git development began after many kernel developers were forced to give up access to the proprietary BitKeeper system (see "Zero-cost BitKeeper for Linux and other open source projects"). The ability to use BitKeeper as freeware had been withdrawn by the copyright holder Larry McVoy after he claimed Andrew Tridgell had reverse engineered the BitKeeper protocols in violation of the BitKeeper license. At Linux.Conf.Au 2005, Tridgell demonstrated during his keynote that the reverse engineering process he had used was simply to telnet to the appropriate port of a Bitkeeper server and type "help".[13]

Torvalds wanted a distributed system that he could use like BitKeeper, but none of the available free systems met his needs, particularly his performance needs. From an e-mail he wrote on April 7, 2005 while writing the first prototype:[14]

However, the SCMs I've looked at make this hard. One of the things (the main thing, in fact) I've been working at is to make that process really efficient. If it takes half a minute to apply a patch and remember the changeset boundary etc. (and quite frankly, that's fast for most SCMs around for a project the size of Linux), then a series of 250 emails (which is not unheard of at all when I sync with Andrew, for example) takes two hours. If one of the patches in the middle doesn't apply, things are bad bad bad.

Now, BK wasn't a speed deamon either (actually, compared to everything else, BK is a speed deamon, often by one or two orders of magnitude), and took about 10-15 seconds per email when I merged with Andrew. HOWEVER, with BK that wasn't as big of an issue, since the BK<->BK merges were so easy, so I never had the slow email merges with any of the other main developers. So a patch-application-based SCM "merger" actually would need to be faster than BK is. Which is really really really hard.

So I'm writing some scripts to try to track things a whole lot faster. Initial indications are that I should be able to do it almost as quickly as I can just apply the patch, but quite frankly, I'm at most half done, and if I hit a snag maybe that's not true at all. Anyway, the reason I can do it quickly is that my scripts will not be an SCM, they'll be a very specific "log Linus' state" kind of thing. That will make the linear patch merge a lot more time-efficient, and thus possible.

(If a patch apply takes three seconds, even a big series of patches is not a problem: if I get notified within a minute or two that it failed half-way, that's fine, I can then just fix it up manually. That's why latency is critical - if I'd have to do things effectively "offline", I'd by definition not be able to fix it up when problems happen).

The development of Git began on April 3, 2005.[15] The project was announced on April 6, 2005,[16] and became self-hosting as of April 7, 2005.[17]

The first merge of multiple branches was done on April 18, 2005.[18]

Torvalds achieved his performance goals; on April 29, 2005, the nascent Git was benchmarked recording patches to the Linux kernel tree at the rate of 6.7 per second.[19]

On June 16, 2005, the kernel 2.6.12 release was managed by Git.[20]

While strongly influenced by BitKeeper, Torvalds deliberately attempted to avoid conventional approaches, leading to a very novel design.[21] He developed the system until it was usable by technical users, then turned over maintenance on July 26, 2005 to Junio Hamano, a major contributor to the project.[22] Hamano was responsible for the 1.0 release on December 21, 2005,[23] and is maintainer to the present day.

[edit] Implementation

Like BitKeeper, Git does not use a centralized server. However, Git's primitives are not inherently a SCM system. Torvalds explains,[24]

In many ways you can just see git as a filesystem — it's content-addressable, and it has a notion of versioning, but I really really designed it coming at the problem from the viewpoint of a filesystem person (hey, kernels is what I do), and I actually have absolutely zero interest in creating a traditional SCM system.

(Note that his opinion has changed since then.)[25]

Git has two data structures, a mutable index that caches information about the working directory and the next revision to be committed, and an immutable, append-only object database containing four types of objects:

  • A blob object is the content of a file. Blob objects have no names, timestamps, or other metadata.
  • A tree object is the equivalent of a directory: it contains a list of filenames, each with some type bits and the name of a blob or tree object that is that file, symbolic link, or directory's contents. This object describes a snapshot of the source tree.
  • A commit object links tree objects together into a history. It contains the name of a tree object (of the top-level source directory), a timestamp, a log message, and the names of zero or more parent commit objects.
  • A tag object is a container that contains reference to another object and can hold additional meta-data related to another object. Most commonly it is used to store a digital signature of a commit object corresponding to a particular release of the data being tracked by Git.

The object database can hold any kind of object. An intermediate layer, the index, serves as connection point between the object database and the working tree.

Each object is identified by a SHA-1 hash of its contents. Git computes the hash, and uses this value for the object's name. The object is put into a directory matching the first two characters of its hash. The rest of the hash is used as the file name for that object.

Git stores each revision of a file as a unique blob object. The relationships between the blobs can be found through examining the tree and commit objects. Newly added objects are stored in their entirety using zlib compression. This can consume a large amount of hard disk space quickly, so objects can be combined into packs, which use delta compression to save space, storing blobs as their changes relative to other blobs.

[edit] Using Git

Git is quite easy to use. First, the (relatively small) changes are downloaded and unpacked, then there is some chatter about the merge process, including the SHA-1 hashes of the objects being merged, and the files that required non-trivial merging. Finally, there is a summary of the changes that were made, and how large they are. The changes are automatically checked in, but can be easily reverted if they are not wanted.

What is noteworthy is that:

  • After the initial bulk download, communication for the merge is small and efficient.
  • No permission or assistance from the original tree repository is required.
  • The merged version now has, not just the total change made in development (as might be produced by a patch), but the complete development history of those changes.
  • It could have been done equivalently in the other order. The only difference would have been which ancestor was listed as the "first parent" of the merge.

[edit] Portability

Git is targeted to run on Linux, but can be used on other Unix-like operating systems including BSD, Solaris and Darwin. Git is extremely fast on POSIX-based systems such as Linux.[26]

Git does not run natively on Microsoft Windows; git runs on Windows by using Cygwin (a POSIX emulation), but this requires the installation and use of Cygwin.[27] Git on Windows is noticeably slower,[28] due to git's heavy use of file system features that are particularly fast on Linux.[29] In addition, many people find Cygwin installation too large and invasive for typical Windows use.[30]

Many projects support both POSIX and Windows. Such projects typically avoid using an SCM system that poorly supports Windows, even if most developers use POSIX-based systems. Examples of projects that have publicly ruled out any use of git, due to git's poor support of Windows, include Mozilla[31] and Ruby.[32]

Various approaches for improving git Windows support have been discussed.

A native Microsoft Windows port (using MinGW) is approaching completion,[33] but there is more work to be done, including handling of CRLF line endings.[34] Porting Git to Windows is difficult due to a number of architecture issues.[35]

In some cases (particularly for anonymous remote access), support for Windows users can be provided via git-cvsserver (which emulates a CVS server, allowing use of Windows CVS clients). Other alternatives include:[36]

  • EclipseIDE-based GIT client, based on a pure Java implementation of GIT's internals
  • A libgit + cygwin.dll Windows Explorer extension (perhaps based on TortoiseSVN)

"libifying" the lowest-level git operations would in theory enable re-implementation of the lowest-level components for Windows without rewriting the rest.[37]

These efforts would generally help to improve performance and ease installation on Windows; it is not clear that any of these efforts would help with the issue of different permission models.

[edit] Related projects

[edit] Projects built on top of Git

  • git-gui is a Tk based GUI for common Git operations. This project is bundled and shipped as part of Git 1.5.0 and later (accessed by running git gui).
  • Cogito (homepage) - Petr Baudiš maintains a set of scripts called Cogito (formerly git-pasky), a revision control system that uses Git as its backend.
  • StGIT (homepage) - Stacked GIT is a Python application providing similar functionality to Quilt (homepage) (i.e. pushing/popping patches to/from a stack) on top of Git, to manage patches until they get merged upstream.
  • pg (Patchy GIT) is a shell script wrapper around Git to help the user manage a set of patches to files. pg is somewhat like Quilt or StGIT, but it does have a slightly different feature set.
  • DarcsGit is an enhancement to Darcs enabling it to interact with Git repositories.
  • bzr git support plugin is a plugin for Bazaar to read Git trees. Though still in alpha stage, it provides enough support for bzrk visualisation.

[edit] Web interfaces

  • gitweb – a Perl implementation maintained by Kay Sievers. Used at kernel.org
  • wit – a Python implementation maintained by Christian Meder.
  • gitarella – a Ruby implementation maintained by Diego Pettenò
  • git-php – a PHP implementation by Zack Bartel

[edit] History visualization

  • gitk is a simple Tcl/Tk GUI for browsing history of Git repositories easily, distributed with Git.
  • QGit (SourceForge project page) is a Qt GUI for browsing history of Git repositories, similar to gitk.

[edit] References

  1. ^ Junio C Hamano (2007-03-18). GIT 1.5.0.5.
  2. ^ http://git.or.cz/gitwiki/GitProjects
  3. ^ http://lkml.org/lkml/2005/4/8/9
  4. ^ Linus Torvalds (2005-04-08). Re: Kernel SCM saga.
  5. ^ Linus Torvalds (2006-03-23). Re: Errors GITtifying GCC and Binutils.
  6. ^ GitFaq: Why the 'git' name?
  7. ^ Linus Torvalds (2005-04-10). Re: more git updates...
  8. ^ Bruno Haible (2007-02-11). how to speed up "git log"?.
  9. ^ Linus Torvalds (2006-03-01). Re: impure renames / history tracking.
  10. ^ Junio C Hamano (2006-03-24). Re: Errors GITtifying GCC and Binutils.
  11. ^ Junio C Hamano (2006-03-23). Re: Errors GITtifying GCC and Binutils.
  12. ^ Linus Torvalds (2006-11-28). Re: git and bzr., on using git-blame to show code moved between source files
  13. ^ Jonathan Corbet (2005-04-20). How Tridge reverse engineered BitKeeper.
  14. ^ Linus Torvalds (2005-04-07). Re: Kernel SCM saga...
  15. ^ Linus Torvalds (2007-02-27). Re: Trivia: When did git self-host?.
  16. ^ Linus Torvalds (2005-04-06). Kernel SCM saga...
  17. ^ Linus Torvalds (2007-02-27). Re: Trivia: When did git self-host?.
  18. ^ Linus Torvalds (2005-04-17). First ever real kernel git merge!.
  19. ^ Matt Mackall (2005-04-29). Mercurial 0.4b vs git patchbomb benchmark.
  20. ^ Linux Kernel Mailing List (2005-06-17). Linux 2.6.12.
  21. ^ Linus Torvalds (2006-10-20). Re: VCS comparison table. A discussion of Git vs. BitKeeper
  22. ^ Linus Torvalds (2005-07-27). Meet the new maintainer....
  23. ^ Junio C Hamano (2005-12-21). ANNOUNCE: GIT 1.0.0.
  24. ^ Linus Torvalds (2005-04-10). Re: more git updates....
  25. ^ Linus Torvalds (2006-03-23). Re: Errors GITtifying GCC and Binutils.
  26. ^ http://weblogs.mozillazine.org/jst/archives/2006/11/vcs_performance.html
  27. ^ Shawn Pearce (2006-10-24). Re: VCS comparison table.
  28. ^ Johannes Schindelin (2007-01-01). Re: [PATCH] Speedup recursive by flushing index only once for all.
  29. ^ Linus Torvalds (2005-09-24). Re: git 0.99.7b doesn't build on Cygwin.
  30. ^ http://www.gelato.unsw.edu.au/archives/git/0506/5736.html
  31. ^ http://weblogs.mozillazine.org/preed/2006/11/version_control_system_shootou.html
  32. ^ http://www.ruby-forum.com/topic/87174
  33. ^ Han-Wen Nienhuys (2007-02-07). MinGW binary installer available.
  34. ^ Mark Levedahl (2007-02-11). mingw, windows, crlf/lf, and git.
  35. ^ Alex Riesen (2006-03-02). windows problems summary.
  36. ^ http://git.or.cz/gitwiki/WindowsInstall
  37. ^ http://www.gelato.unsw.edu.au/archives/git/0603/17470.html

[edit] See also

[edit] External links