Monday, April 20, 2009

git-format-patch for a single commit

One thing that always annoyed me was the weirdness of getting a patch from a single commit somewhen back in the history. Turns out I was just ignorant and reading the man page actually helps, git-format-patch accepts a -<n> option, where <n> is the number of patches you need since the commit (inclusive).

So, because I'm a big fan of tig, add this to your $HOME/.tigrc:

bind generic E !git format-patch -1 %(commit)


Start tig, mark the patch you want, hit "E" to get a nice patch file. Doesn't get much simpler than that.

[update Jun 05 2012]
As SEJeff and Michael point out in the comments
git show $sha
shows a single commit. The output of git show is different to git format-patch though (it cannot be applied via git-am).

5 comments:

  1. Why not use get show?

    git show $COMMIT_ID

    ---
    Jeff Schroeder
    http://www.digitalprognosis.com

    ReplyDelete
  2. You can also simply use
    git show "commitish"

    ReplyDelete
  3. Because git show's output is very different from git format-patch.

    ReplyDelete
  4. `git show --pretty=email $COMMIT_ID` for formatting like format-patch

    ReplyDelete

Comments are moderated thanks to spammers