skwpspace it’s pronounced ’scoop’. yan pritzker’s home on the web

Blog :: Photography :: About Me

hello, i'm yan

I blog here occasionally. I hope you like it.

Subscribe by Email

planypus

I'm the founder of Planypus, the place to share your plans!

cohesiveft

Accessible, manageable, virtualized application stacks ready to download or deploy to the cloud!

flickr

starlightthe playersredmoon theater - boneyard prayerredmoon theater - boneyard prayer-5redmoon theater - boneyard prayermetal goddessmetal monstersprofessor

Archives

Contact

Reach me at yan at pritzker.ws

Posted
22 April 2008 @ 5am

Tagged
git, sourcecontrol, svn, thoughts, tips

Useful git commands and quirks

Things I’ve learned from my first git experiences. First of all, git is inconsistent as hell. Every command has its own quirks and syntax, so I’m attempting to catalog some of them here. We’ve been using git svn at Planypus as a way to maintain local developer branches and still push to our svn as a central place which then triggers our integration server rebuild, cruise control, and so on.

First, make it look nice

$ git config --global color.diff auto
$ git config --global color.status auto
$ git config --global color.branch auto
$ git config --global color.interactive auto

via tpope

Onwards to the commands…

If you’re using git svn and you want to see changes that you have comitted locally but have not yet dcomitted

git svn dcommit -n

This might give you output that looks like this
diff-tree e784cfa... e784cfa...

BUT, if you want to actually see the changes, what you want is apparently the ‘patch’ output:

git diff-tree -p e784cfa... e784cfa...

If you have uncomitted changes, it’s easy to see them

git diff

BUT, if you’ve already created your commit set (git add) but not comitted, you how have to use

git diff --cached

If you’ve accidentally added some files to your commit set and want to remove them from the index (untrack them), but leave the changes in your working tree

git reset HEAD [file/dir]

To undo local changes (revert in the svn sense)

git checkout [files]

Note that this works as long as the file is not yet in your index. If you’re already tracking it for commit, you’ll need to untrack it first using git reset HEAD [file] before you’re able to check it out.

You can also use this command to check out files from the past by specifying any commit hash:

git checkout [hash] [files]

It’s just that when you don’t specify the hash, it assumes HEAD.

If you’ve got changes you want to just throw away permanently, you can just reset:

git reset --hard

But reset is a powerful command that can also take you back in time. Let’s say you messed up the last commit, you can take yourself back to the way things were right before you comitted:

git reset HEAD^

Notice I didn’t use --hard because that throws away the changes. Instead, this form of the command throws away the commit by taking you to HEAD^ (one commit before HEAD), but it leaves the changes in your working tree. If you want the changes also to be left in your index (ready to be comitted) you can use

git reset --soft HEAD^

If you’re working on something and you decide you want to scrap it or work on it later

git stash

There are lots of fun things you can do with stashes but they’ve been covered on other blogs.

on merging…

If you’ve done a git merge and have some conflicts, launch git mergetool which will take you through the conflicted files one by one using your default merging tool (FileMerge, usually, on OSX) and let you merge them. However be careful. Either because of a misconfig on my end or some other quirk, FileMerge shows the file I pulled from svn as “LOCAL” while my file with changes is “REMOTE” which is counterintuitive to me and caused me to fubar a merge the first time I tried.

Take note that after the merge, you will have files ending with .orig left on your system so you’ll have to manually delete them, unless you have the config mergetool..keepBackup set, but I haven’t tried this yet. Also, after the merge I was getting error messages about having a .git/MERGE_HEAD file, which I couldn’t find enough docs online for, so I just deleted it..and hopefully that did not fubar me.

Well that’s all for now. More might come as I learn to stop worrying and love the git.

P.P.S Many of these commands are not necessary if you use The Git Textmate Bundle and GitNub which integrate together and work very well!


8 Comments

Posted by
Tina Russell
22 April 2008 @ 5am

I finally decided to write a comment on your blog. I just wanted to say good job. I really enjoy reading your posts.

Tina Russell


Posted by
links for 2008-04-23 at Topper’s Blog
23 April 2008 @ 4am

[...] skwpspace – Useful git commands and quirks (tags: git howto tips quirks programming version control interesting toread) [...]


Posted by
links for 2008-04-23 | Libin Pan
23 April 2008 @ 6am

[...] skwpspace – Useful git commands and quirks Useful git commands and quirks (tags: git howto tips versioncontrol scm) [...]


Posted by
Danny
24 April 2008 @ 9am

This might be one for you: http://snippets.dzone.com/posts/show/5348

Git branch on your bash prompt :)


Posted by
Evgeny
24 April 2008 @ 6pm

What if I need to merge a local branch that has a submodule?
It just gives me this :
fatal: cannot read object 8e335ede2d2e4090bfdcd4e552b8596da115b7f9 ‘lib/haml~HEAD’: It is a submodule!
Merge with strategy recursive failed.

and there is no way to fix it, afaik.
stupid git.


Posted by
Yan
24 April 2008 @ 7pm

Haven’t got to submodules quite yet. I’m trying to keep my git workflow extremely simple. I am not particularly interested, for example, in things like amending commits, and so on. Although all this is fun it seems to me that the basic things one needs to do are to commit, pull, and merge. I’m so used to svn that just the ability to do those basic actions is enough, combined with git’s nice local commit ability and ease of branching.


Posted by
Useful git commands and quirks | Blue Night
25 April 2008 @ 1pm

[...] Found this here. More info available, useful. [...]


Posted by
Ryan
26 April 2008 @ 4pm

git config –global color.ui auto is a new catch all in Git 1.5.5 for color configuration


Leave a Comment

The security of working at a startup Elastic Server now with Passenger (mod_rails)