Git cheat sheet

My own personal cheat sheet of useful Git commands.

diff

git diff --stat --staged (staged in 1.6+, cached in older)

Differences between HEAD and index (i.e., shows changes that have been staged)

git diff -U1 --stat

Reduces the context lines around differences to one line for shorter display. Puts summary (stat) at start of diff.

Categories: 

"Local branches" and BitKeeper

As far as I know, BitKeeper does not seem to support the notion of "local" (intra-repository) branches.

Git supports these, and I've found them very useful. With Git, you can easily have debug/test branches without the overhead or config issues of an entirely different repo. I've even used one branch per bug so I can have several things in the air before merging them into the master branch.

The only way I can see to do this in BitKeeper is to have separate repos, which wastes disk space and adds the trouble of creating and managing separate directory trees in the file system.

Categories: 

Handling BitKeeper merge conflicts

I'm more familiar with Git and its merge process, but I also use BitKeeper and sometimes run into merge conflicts. Here's some info on how to handle them.

Unlike Git, BitKeeper doesn't have the notion of "local" branches, so all merges are from push/pull operations. BitKeeper has a merge command, but it's for merging single files, rather than merging one local branch into another.

Categories: 

Quick and dirty PHP debugging

Xdebug (http://xdebug.org) is probably one of the best ways to debug PHP code. But Xdebug can be difficult to setup, depending on the environment.

If you want an one-liner to see defined variables, try this :


print print_r(array_keys(get_defined_vars()), 1);

If you only want to see a select list of PHP variables, try this which was lifted from the notes at http://php.net/manual/en/function.get-defined-vars.php.


    function getDefinedVars($varList, $excludeList) {
        $temp1 = array_values(array_diff(array_keys($varList), $excludeList));
Categories: 

Git push quirks - How To

I have experience with a number of distributed version control systems (DVCS) including Darcs, BitKeeper, Mercuial, Bazaar and now Git.

Git has a lot going for it, so I've decided to "lease" my soul to it for version control.

Git has some quirks, however. One of them is the notion of "push". Git's push doesn't work as I've come to expect in other DVCSes. Here's a good posting on this quirkiness :

* http://hans.fugal.net/blog/2008/11/10/git-push-is-worse-than-worthless

Categories: 

SSH keys, PuTTY, Keychain etc. resources

Here are some good resources in the area of SSH keys :

## Key-based logins with PuTTY - Excellent How-To with pics

* http://www.howtoforge.com/ssh_key_based_logins_putty

## Good overview of SSH keys - including optional hardeners

* http://www.eng.cam.ac.uk/help/jpmg/ssh/authorized_keys_howto.html

## Good overview of SSH keys, including Keychain to remember passphrases

* http://www.ibm.com/developerworks/linux/library/l-keyc.html
* http://www.gentoo.org/proj/en/keychain/

Note PuTTY's Pageant is a Windows form of Keychain

Categories: 

My Git environment

Here are some things I've done to make Git easier to use. There are probably better ways (ex. Git "native" aliases etc.) to do some of these things, but these work for me. This is a work in progress.

Here are some aliases I put in my .bashrc :

alias gb='git branch'
alias gbv='git branch -v'
alias gbva='git branch -va'

alias gci='git citool'

alias gds='git diff --stat'
alias gdsmfh='git diff --stat master FETCH_HEAD'
alias gdtmfh='git difftool master FETCH_HEAD'

alias gl='git log --pretty=short'
alias glf='git log --pretty=fuller'

Categories: 

Building Git on Ubuntu

To "git" the latest goodies in Git 1.6.x, I like to build it on my systems rather than obtain it thru a package manager.

On Ubuntu server systems, I may be missing some Git build dependencies. I can go into the Makefile and set some values (near the top) to work around this like :

NO_TCLTK=true

It's probably easier, however, to do this to have apt-get grab the build dependencies :

$ aptitude build-dep git-core

This may get some things you may not need (Subversion, CVS), but it makes it easier.

Then just make :

# make prefix=/usr install2
...

Categories: 

Git merge strategies

Here are a few comments about Git merge strategies.

When you do something like git merge FETCH_HEAD, Git will by default apply a recursive strategy when you pull or merge one branch.

I had a case where I had to pull in commits from a "similar but unrelated" Git repository. I did a git fetch to grab the changes into a local FETCH_HEAD. But when I did git merge with the default merge strategy, the merge failed miserably (lots of conflicts).

When I tried the resolve strategy, the merge failed totally :
$ git merge -s resolve FETCH_HEAD

Categories: 

Pages

Subscribe to luhman.org RSS