Cyan
Cyan

Reputation: 13948

how to extract commit patches from a git repository

I would like to extract all patches from a git repository, or at least all ancestors from a selected tag or commit.

I need each commit as a separate patch. Each patch should end up into its own file. The command can create a directory or a tar archive.

Closest I could find is git-format-patch, but it outputs everything as a single patch.

Upvotes: 4

Views: 1988

Answers (2)

VonC
VonC

Reputation: 1323223

Warning: using git format-patch -o path/to/folder, with intermediate directories path/to not yet created,... means the command would fail.

"git format-patch -o <outdir>" did an equivalent of "mkdir <outdir>", not "mkdir -p <outdir>", which is being corrected with Git 2.24 (Q4 2019).

See commit edefc31 (11 Oct 2019) by Bert Wesarg (bertwesarg).
(Merged by Junio C Hamano -- gitster -- in commit f1afbb0, 18 Oct 2019)

format-patch: create leading components of output directory

Signed-off-by: Bert Wesarg

'git format-patch -o <outdir>' did an equivalent of 'mkdir <outdir>', not 'mkdir -p <outdir>'.

Avoid the usage of 'adjust_shared_perm' on the leading directories which may have security implications.
Achieved by temporarily disabling of 'config.sharedRepository' like 'git init' does.

And (still with Git 2.24, Q4 2019):

See commit 19c29e5 (21 Oct 2019) by Bert Wesarg (bertwesarg).
(Merged by Junio C Hamano -- gitster -- in commit c555caa, 24 Oct 2019)

t4014: make output-directory tests self-contained

Signed-off-by: Bert Wesarg

As noted by Gábor, the new tests in edefc31873 ("format-patch: create leading components of output directory", 2019-10-11, Git v2.24.0-rc0 -- merge listed in batch #0) cannot be run independently.
Fix this.

Upvotes: 0

qzb
qzb

Reputation: 8808

You can achieve that with git-format-patch:

git format-patch -o patches --root HEAD

It will write patches to patches directory. Of course you can replace HEAD with sha of particular commit or with some tag.

Upvotes: 3

Related Questions