Monday, March 8, 2010

git format-patch for specific commit-ids

for revision ranges, appending ^! (which appropriate escaping) to a commit-id causes it to represent that range beginning/ending with that commit-id inclusively instead of exclusively. So for specifying a revision range consisting of exactly one specific revision (let's call it r1), you can specify r1^! r1

And if you want to generate a patch from all your commits while ignoring all other commits:

for c in `git log --author=Clark | grep ^commit | awk '{print $2}'`; do
git format-patch "$c^\!" "$c";


  1. Is the bang really necessary? I just tried,
    git format-patch 6ca0b75a2c4229db2f1d6453b121174208cd502c^..6ca0b75a2c4229db2f1d6453b121174208cd502c

    That worked fine for cooking up a single commit. Likewise you could also use syntax like,

    git format-patch 6ca0b75a2c4229db2f1d6453b121174208cd502c~1..6ca0b75a2c4229db2f1d6453b121174208cd502c

    The "~n" syntax is powerful and lets you step backwards relatively through n commits from an absolute commit id.

    So if you just committed four (4) patches and want to share the first three (3) you could use,

    git format-patch HEAD~3..HEAD^

    That will leave out the most recent commit, aka commit #4, aka HEAD.

    1. Your solutions don't solve the problem presented by Rob. He is only interested in his patches. There is no guarantee those patches are in consecutive order, your solutions only work (with no further massaging) if they are.

  2. This comment has been removed by a blog administrator.