# Re: One question about git-format-patch

2 messages from 2013-07-19 to 2013-07-20. Participants: Junio C Hamano.
Thread: https://gitlist.dev/t/34497

## Junio C Hamano, 2013-07-19 23:06

Subject: Re: One question about git-format-patch
Message-ID: <CAPc5daW6ohYxJP0eyfW0DT_Q-E8v0quweRBwJCAZOVrEMWchjA@mail.gmail.com>
URL: https://gitlist.dev/e/CAPc5daW6ohYxJP0eyfW0DT_Q-E8v0quweRBwJCAZOVrEMWchjA%40mail.gmail.com
In-Reply-To: <804161F448B352478D7503429A0B7F27CA94AC@ex10-mbx-36002.ant.amazon.com>

```
> 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, 2013-07-20 00:32

Subject: Re: One question about git-format-patch
Message-ID: <7vehaut6j5.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vehaut6j5.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CAPc5daW6ohYxJP0eyfW0DT_Q-E8v0quweRBwJCAZOVrEMWchjA@mail.gmail.com>

```
Junio C Hamano <gitster@pobox.com> writes:

>> 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).

```
