git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: One question about git-format-patch

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 20, 2013, 00:32 UTC
Message-ID
<7vehaut6j5.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CAPc5daW6ohYxJP0eyfW0DT_Q-E8v0quweRBwJCAZOVrEMWchjA@mail.gmail.com>
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).

Previous: Junio C Hamano
Message 2 of 2 in “Re: One question about git-format-patch”
  1. Junio C HamanoJul 19, 2013
  2. Junio C HamanoJul 20, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.