coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "git format-patch" question


From: Pádraig Brady
Subject: Re: "git format-patch" question
Date: Tue, 11 Dec 2012 16:44:38 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

On 12/11/2012 04:17 PM, Assaf Gordon wrote:
Hello,

(picking up from a different thread)

Pádraig Brady wrote, On 12/06/2012 06:59 PM:
Generally it's best to get git to send email
or send around formats that git can apply directly,
which includes commit messages and references new files etc.
The handiest way to do that is:

   git format-patch --stdout -1 | gzip > numfmt.5.patch.gz

While working on my development branch, I commit small, specific changes, as so:
  [PATCH 1/6] numfmt: a new command to format numbers
  [PATCH 2/6] numfmt: change SI/IEC parameters to lowercase.
  [PATCH 3/6] numfmt: separate debug/devdebug options.
  [PATCH 4/6] numfmt: fix segfault when no numbers are found.
  [PATCH 5/6] numfmt: improve --field, add more tests.
  [PATCH 6/6] numfmt: add --header option.

Each commit can be just few lines.

When I send a patch the the mailing list, I want to send one 'nice' 'clean' 
patch with my changes, compared to the master branch.

When I use the following command:

    git diff -p --stat master..HEAD > my.patch

And all the changes (multiple commits) I made on my branch compared to master are 
represented as one coherent change in "my.patch" - but this is not convenient 
for you to apply.


However, when I use

     git format-patch --stdout -1 > my.patch

Only the last commit appears.

The alternative:

     git format-patch --stdout master..HEAD > my.patch

Generates a file which will cause multiple commits when imported with "git am" .

When is the recommended way to generate a clean patch which will consolidate 
all my small commits into one?
Or is there another way?

No need to squash to a single diff.
It's best to use the method I suggested,
and then git can apply all the patches in turn.
Just s/-1/-6/ in the command I suggested.
We can squash to the appropriate number of commits,
before the final commit anyway.

If you really want to squash patches locally
to hide trivial adjustments etc. then:

  git rebase -i HEAD~6

Then s/pick/squash/ where needed, and save.

Also it's best for consumers of the patch set,
that you rebase your branch onto the latest master like:

  git checkout master
  git pull origin
  git checkout my_branch
  git rebase master

cheers,
Pádraig.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]