Difference between revisions of "Git"

From CUC3
Jump to navigation Jump to search
import>Jss43
import>Jss43
m
Line 17: Line 17:
 
* branching and merging.
 
* branching and merging.
 
* tab completion on the subcommands (e.g. git commit and svn commit) and a PS1 containing the branch information (see below).
 
* tab completion on the subcommands (e.g. git commit and svn commit) and a PS1 containing the branch information (see below).
* git diff works with graphical diffs (svn is meant to, but good luck on getting it working with xxdiff).
+
* git diff plays nicely with graphical diffs (svn is meant to, but good luck on getting it working with xxdiff).
   
 
==Useful links==
 
==Useful links==

Revision as of 00:17, 1 August 2008

git is the second project that Linus Torvalds has named after himself. It is now on the workstation image.

git is a distributed version control system (DVCS), which offer many advantages over centralised version control systems such as subversion. For git in particular:

  • Ability to use version control without the internet access required to access the wwmm server. I now have the complete history of our code on my laptop. No wifi needed! :-). It also means I can do sequential commits without needing internet access.
  • Branching and merging are *easy* and *lightweight*. This has changed how I work...
  • git-svn provides an interface (in both directions) with a subversion repository. This means that we get all the advantages of using subversion (a centralised server which is backed up and maintained by someone other than us, subversion is installed on more systems, can work with people who are using subversion and don't want to change) with none of the disadvantages (subversion makes branches an absolute pain, especially if you want to just try something out and have a play without polluting the server). The interface is so slick, that I can use git and everyone else use subversion and not know that I'm using git (but I may have just let the cat out of the bag on that one).
  • It's fast.
  • It doesn't screw around with my history or lose files.
  • It's cryptographically secure. (This isn't as bizarre as it sounds!)
  • Linus Torvalds is much smarter than us. Seriously. Oh, and he calls everyone using subversion (and cvs) stupid. Repeatedly. He managed to convince me...

It is somewhat less user friendly in places, but far more powerful, than subversion. It has wonderful graphical interfaces for viewing branches (gitk and qgit).

Things I really miss when I have to use svn:

  • stash.
  • branching and merging.
  • tab completion on the subcommands (e.g. git commit and svn commit) and a PS1 containing the branch information (see below).
  • git diff plays nicely with graphical diffs (svn is meant to, but good luck on getting it working with xxdiff).

Useful links

git-svn links

meld and git diff

Set up git diff to use meld or xxdiff rather than outputting a unified diff by adding, e.g.,

[diff]
   external = meld

to ~/.gitconfig.

Unfortunately git tries to pass more information than xxdiff or meld can handle. Instead add:

[diff]
   external = ~/bin/diff.sh

to ~/.gitconfig where ~/bin/diff.sh contains:

#!/bin/bash
meld $2 $5

and enjoy graphical diff wonderland.

Cool things

Add tab completion for the git subcommands: completion script. Follow the instructions within to set up tab completion. It also contains a handy function that adds the current branch to your PS1. I added:

PS1='\u@\h:\w$(__git_ps1 " [%s]")\$ '

to my .bashrc. This only adds something when I am in a git-controlled directory. If I change directories, it remembers what branch I am in:

james@maruchon:~/work/src$ cd CPMD-NECI
james@maruchon:~/work/src/CPMD-NECI [master]$ git branch
* master
  test
james@maruchon:~/work/src/CPMD-NECI [master]$ git checkout test
Switched to branch "test"
james@maruchon:~/work/src/CPMD-NECI [test]$ cd NECI/
james@maruchon:~/work/src/CPMD-NECI/NECI [master]$ git branch
  exp
* master
james@maruchon:~/work/src/CPMD-NECI/NECI [master]$ git checkout exp
cd -Switched to branch "exp"
james@maruchon:~/work/src/CPMD-NECI/NECI [exp]$ cd -
/home/james/work/src/CPMD-NECI
james@maruchon:~/work/src/CPMD-NECI [test]$ git checkout master
Switched to branch "master"
james@maruchon:~/work/src/CPMD-NECI [master]$ cd NECI/
james@maruchon:~/work/src/CPMD-NECI/NECI [exp]$ git checkout master
Switched to branch "master"
james@maruchon:~/work/src/CPMD-NECI/NECI [master]$ cd
james@maruchon:~$ 

This is very useful (especially as git encourages branching so much!).