Archive for the ‘git’ Category

A better git log and the wonders of git tig

Posted on January 16th, 2011 in git | No Comments »

I was looking for a remote terminal-friendly version of gitk for visualizing branch and merges and as of yet the closest I’ve gotten is this awesome log command (compliments of this well-done git tutorial):

git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short

It wasn’t as full featured as I liked but did the job and doesn’t require installing an extra package. Recently though, I stumbled on a colorful text-based git frontend call tig which is quite handy. Check out the screenshots here. It’s fast and effortless to dig around your repository, drill down wherever you need, and you can even pipe regular git commands to it to see them in interactive full color. Installing it is a breeze with (yum install tig or apt-get install tig) or you can install from source. From here, type tig in your working directory and follow these commands. Checkout tig blame too!

I’d give a longer review on it with screenshots but someone already has here.

I default tig to show the rev-graph (shown here) and use relative dates by adding the following to my global git config in ~/.gitconfig:

   show-date = relative
   author-width = 8
   show-rev-graph = yes

You can really modify the short cut commands and colors to your liking using the man file.

Git: committing only partial changes of a file

Posted on December 30th, 2010 in git | 1 Comment »

or better known as “staging patches”.

So you created some new functionality in a file but you have a lot of other code you’re not quite ready to commit yet. Answer: git add -p . It will interactively go though modified sections of your file asking if you want to “stage this hunk”. Answer y for yes, n for no, q for stop, then commit as usual. You can even split hunks if you want to get more fine-grained.

For more details check out this page.

Using make to concatenate JS files

Posted on December 21st, 2010 in bash, git | No Comments »

In a previous project I used a bash script in conjunction with a git hook to concatenate all my js files and increment build numbers in html file references (cache-kill) after every commit. This was convenient at first, but quickly got annoying as I wasn’t always committing js file changes. I eventually opted to just call the script manually before any deployment to qa or production, thinking I would automate it again one day to only be called when JS files were changed (git hooks probably provide this info).

Today I read up on make. I’ve always used make in the past to build versions of a program for my system but never how it actually worked. When ran, it essentially reads in a list of dependencies, and if the source files have modification times newer than the “built” file, it runs your script to rebuild them. Concatenating javascript files seems like the perfect opportunity for this. I’ll rewrite my bash script to use make, set it as a git hook, and should be able to forget it. Will let you know how it goes.

The wonders of git bisect

Posted on December 5th, 2010 in git | 2 Comments »

I had a bug that crept up on me that wasn’t found until right before a production push. I rolled back the last two commits locally but saw that the issue was still there on the iPhone. Now I’ve heard about the wonders of git bisect but hadn’t had the opportunity to use it – until now and was pleasantly satisfied at how well it did it’s job.

Locating the problem commit:

To quickly locate the exact commit that the issue was introduced I picked an arbitrary date of 15 days ago and saw that the bug didn’t exist at that time. I ran git bisect specifying master as bad and the the commit of 15 days ago as good. git bisect then picks random commits between those two commit ranges until I find the first bad commit. The process involves me calling git bisect bad or git bisect good as I refreshed the iPhone screen. The bug was found in less than five minutes (having called git bisect six times). Fixing the bug however, took a little longer…

For a greater look into git bisect peep this link.

Bonus round

Once you find the problem commit, you can show the details of the comment by doing:

git show 97d7c26dba17ba1a46fb9c6f0bf0e954a92aec74

Cat a specific file by doing:

git show 59010bee586296f0676a9e2255b2bade6b8cea74:public/js/jellycar3/tap.js

What to grab the previous commit before that file and copy it to your local branch? Just do (while in whichever branch):

git show 59010bee586296f0676a9e2255b2bade6b8cea74^:path/to/file/tap.js > tap.js

Git: Ignore changes in a working tree file

Posted on May 21st, 2009 in git | 3 Comments »

Lately, I’ve transferred all my repos over from Subversion to Git and have become familiar enough with the Git SVN bindings to even work on my work projects in Git while still being able to check-in as a regular SVN user.

I’ve found that some usual stuff Subversion would ignore in projects Git doesn’t. The Git exclude file doesn’t work here since these are files being tracked in the working tree that are just specific to your instance. After digging around, I found the proper command to ignore these files:

# ignore changes in a working tree file
git update-index --assume-unchanged .classpath