1

I often have a source tree that did not originate as a git repository. Typically before I begin making changes I add a local git repository. My first commit is invariably a snapshot of the starting state of the tree.

From that point on I create regular commits. Periodically I need to convey my work elsewhere as a series of patches. To do so I want to create patches for all but my very first commit (since that first commit is typically enormous and conveys no useful information).

Is there an easy way to do this without knowing a priori the number of commits in my branch?

John Yates
  • 1,027
  • 1
  • 7
  • 18

1 Answers1

1

You might consider tagging your initial state, before making your commits.

Then a patch would be as simple as:

git format-patch myTag..HEAD --stdout > changes.patch

The tagged initial commit would not be part of that patch.

If you don't want just one patch, count the commits:

count=$(($(git rev-list --count myTag..HEAD) - 1))

git format-patch -${count}
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you very much. You supplied two key items: * tag the initial commit (I can script this) * how to count the number of revisions (I do want multiple patches) – John Yates Jan 22 '18 at 12:58