Monday Git Tips

One project I'm working on at the moment involves finding my way around changes in a codebase that isn't mine - and it's quite large. I was doing pretty well with a combination of git log and git show and in particular two of my favourite existing tricks:

git log --graph --oneline

This shows a lovely condensed view of changes, linked by which branch they came in from so you can sort of see the grouping of commits.

git log [branchname] --not develop

Shows all commits on a given branch which aren't on another one. Ideal for checking what happened on a feature branch, while ignoring the "noise" from the main development branch.

These, however, weren't enough for me to figure out what had been applied where, and which files were being changed in which commit. So I now have some new tricks which are helping me a lot, maybe they're helpful for you too!

git log --stat

This can be combined with the branchname and --not switches as shown above to show which changes are on this branch but not the main one, and which files those changes touched.

git branch --contains [commit identifier]

This one is really useful because of the way I'm working - I have diffs over a range of git commits, but it's not always obvious actually which feature branch I can find those in. This command shows me which have it (use -a to include remote branches) and helps me to orientate myself in a codebase that I don't develop on.

I've added all of these to my git cheat sheet - an actual sheet of paper that hangs over my desk! What else would you add?

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.