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:

SEJeff said...

Why not use get show?

git show $COMMIT_ID

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

Michael said...

You can also simply use
git show "commitish"

anholt said...

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

kabari said...

This is great! Thanks.

etcshadow said...

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