threads / discuss / 34497

Re: One question about git-format-patch

Subject: Re: One question about git-format-patch

## tl;dr

2 messages between Jul 19, 2013 and Jul 20, 2013.

replies: 1people: 1as markdown or json

Junio C Hamano· Jul 19, 2013, 23:06 UTC · lore
> I’m a git user, and recently I’ve noticed there’re some differences between
> “$ git format-patch –n” and “$ git format-patch HEAD~n”. According to the
> documentation: “-<n> Prepare patches from the topmost <n> commits.”

Correct. However, HEAD~n will prepare patches for commits that are not ancestor of HEAD~n.

And there may well be a lot more than n such commits, unless you are working on a strictly linear history.

Junio C Hamano· Jul 20, 2013, 00:32 UTC · re: Junio C Hamano · lore
Junio C Hamano <gitster@pobox.com> writes:
Show 9 quoted lines
>> I’m a git user, and recently I’ve noticed there’re some differences between
>> “$ git format-patch –n” and “$ git format-patch HEAD~n”. According to the
>> documentation: “-<n> Prepare patches from the topmost <n> commits.”
>
> Correct.  However, HEAD~n will prepare patches for commits that are
> not ancestor of HEAD~n.
>
> And there may well be a lot more than n such commits, unless you are
> working on a strictly linear history.
Every once in a while, a illustration would help new folks.  

In this history (as always, the time and ancestry topology flows from left to right):

           E-------F---G
          /       /
     A---B---C---D
imagine that your HEAD is at commit G.
 - G~1 == G^ == F
 - G~2 == G^^ == E (suppose F is a merge of D made on E)
 - G~3 == G^^^ == B
 - G~4 == G^^^^ == A

so "git format-patch HEAD~4" will give you B, C, D, E and G (five commits).

Asking for "git format-patch -n 4" does not make much sense in a history like this, but it will give you G, D, C, E and at that point you have seen 4 commits, so you won't get B.

Note that if F were a merge of E made on D, that would make
 - G~2 == G^^ == D
 - G~3 == G^^^ == C
 - G~4 == G^^^^ == B

And "git format-patch HEAD~4" will give you C, D, E and G (four commits).

← back to recent threads