-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathgit-clone-subset.1
85 lines (85 loc) · 3.01 KB
/
git-clone-subset.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
.TH GIT-CLONE-SUBSET 1 2021-02-11
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH NAME
git-clone-subset \-
Clones a subset of a git repository
.SH SYNOPSIS
.B git-clone-subset
.RI [ options ]
.I repository destination-dir pattern
.SH DESCRIPTION
Clones a
.I repository
into a
.I destination-dir
and prune from history all files except the ones matching
.I pattern
by running on the clone:
.br
.B git filter-branch --prune-empty --tree-filter 'git rm ...' -- --all
.br
This effectively creates a clone with a subset of files (and history)
of the original repository. The original repository is not modified.
.sp
Useful for creating a new repository out of a set of files from another
repository, migrating (only) their associated history. Very similar to:
.br
.B git filter-branch --subdirectory-filter
.br
But git-clone-subset works on a path pattern instead of just a single directory.
.SH OPTIONS
.TP 8
.BR \-h , \ \-\-help
show usage information.
.TP 8
.I repository
URL or local path to the git repository to be cloned.
.TP 8
.I destination-dir
Directory to create the clone. Same rules for git-clone applies: it
will be created if it does not exist and it must be empty otherwise.
But, unlike git-clone, this argument is not optional: git-clone uses
several rules to determine the "friendly" basename of a cloned repo,
and git-clone-subset will not risk parse its output, let alone
predict the chosen name.
.TP 8
.I pattern
Glob pattern to match the desired files/dirs. It will be ultimately
evaluated by a call to bash, NOT git or sh, using extended
glob '!(<pattern>)' rule. Quote it or escape it on command line, so it
does not get evaluated prematurely by your current shell. Only a
single pattern is allowed: if more are required, use extglob's "|"
syntax. Globs will be evaluated with bash's shopt dotglob set, so
beware. Patterns should not contain spaces or special chars
like " ' $ ( ) { } `, not even quoted or escaped, since that might
interfere with the !() syntax after pattern expansion.
.sp
Pattern Examples:
.sp
"*.png"
.br
"*.png|*icon*"
.br
"*.h|src/|lib"
.SH LIMITATIONS
Renames are NOT followed. As a workaround, list the rename history
with 'git log --follow --name-status --format='%H' -- file | grep "^[RAD]"'
and include all multiple names of a file in the pattern, as
in "current_name|old_name|initial_name". As a side effect, if a different
file has taken place of an old name, it will be preserved too, and
there is no way around this using this tool.
.sp
There is no (easy) way to keep some files in a dir: using 'dir/foo*'
as pattern will not work. So keep the whole dir and remove files
afterwards, using git filter-branch and a (quite complex) combination
of cloning, remote add, rebase, etc.
.sp
Pattern matching is quite limited, and many of bash's escaping and
quoting does not work properly when pattern is expanded inside !().
.SH SEE ALSO
.B https://github.com/MestreLion/git-tools
.SH AUTHOR
Rodrigo Silva (MestreLion) [email protected]