365Git

  1. Search
  2. About
  3. Subscribe
  4. Archive
  5. Random

365Git

Regular small snippets and workflows for Git

My original plan of a post everyday turned out to be unrealistic, but I'll carry on posting as regularly as I can.

Find me @abizern on twitter if you have anything you'd like me to cover.

Newer
Older
  • 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 -v

    The 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 with git diff anyway. 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 --cached as 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 the git commit command. Rather than change my line of thought I just pass the -v flag 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.

    Tagged: git commit git-diff verbose day14 editor

    Posted on April 6, 2010 with 2 notes ()

    1. 365git posted this

Field Notes Theme. Designed by Manasto Jones. Powered by Tumblr.