-
What’s in the commit?
I’m as reluctant as the next person to read a slab of text when I’m just looking for information. So just a short one today.
Say you want to see what exactly you are adding to a repository with a commit. Here’s a handy command:
git commit -vThe important thing here is the
-v(shorthand for the--verbose) flag. When the editor opens up with the commit message, the diff between the current HEAD and the commit will be added to the message. This is useful if you want to see, at a glance, all the changes that the commit will introduce.There are a couple of points to be aware of, though. Firstly, the extra diff does not have the preceding
#character which marks a line as a comment, so this diff is included in the message. We might think of this as a tautology. The diff is immediately available between any two commits withgit diffanyway. But if you want to highlight a particular change in a commit message this is an easy way to get a complete diff that can be edited to fit any purpose.Secondly, Why get the diff at the commit stage when you can get one before committing using
git diff --cachedas explained in my previous post? I can’t speak for everyone, but sometimes it occurs to me to look at the diff as I am typing thegit commitcommand. Rather than change my line of thought I just pass the-vflag and edit the commit message. Of course it helps if you are competent with your editor. Git defaults to a flavour of vi. But if you would rather use your preferred editor have a look at this post from my personal site which should give you some pointers until I write a fuller post here.This technique is particularly useful if, like me, you make lots of small commits on a working branch which you then rebase and squash down to larger chunks of commits on a main branch. That way, the changes are small and focussed and easy to look over in the commit editor.
Posted on April 6, 2010 with 2 notes ()
-
365git posted this
-