User:PEZ/Git things

From Robowiki
< User:PEZ
Revision as of 14:11, 13 November 2011 by PEZ (talk | contribs) (About empty directories)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Thought I could use a wiki page here as a solutions log for git tricks I stumble across.

Resources

The Git Pro book and site has been absolutely invaluable to me to get rid of the feeling that Git always surprises me. http://progit.org/ I have the .epub on both my iPhone and iPad.

A few days ago I found this really cool site about figuring git out: http://think-like-a-git.net/ It's really fun to read too.

Git and empty directories

Git isn't designed to track directories. It tracks files. The best way to still keep directories needed for structure is to add .gitignore files to the directories with this content:

   # Ignore everything in this directory
   *
   # Except this file
   !.gitignore

Here's the Stackoverflow answer that taught me this. Upvote!

Gitconfig

Some things to consider keeping in ~/.gitconfig.

Colors

Colored highlights help me a lot when trying to make sense of Git output.

   [color]
     ui = true

Graph log

Yes, a GUI tool is often best to get an overview of the history. But I tend to stay at my prompt often and then this alias comes in handy:

   [alias]
     lg = log --graph --color --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

Oneliners

(Of course, some of these can be turned into git aliases or functions in your shell if you find you use them often.)

git summary

A bit like hg summary.

   $ git log -1 --summary --stat

Undelete

You knew there was a file named foo.txt some time ago and want it back? Try this:

   $ git rev-list -n 1 HEAD -- foo.txt
   b193eecf895e45b4f875eb4e6030f2c2e9fac897
   $ git checkout b193eecf895e45^ -- foo.txt