@@ -3,50 +3,55 @@ git-subtree(1)
3
3
4
4
NAME
5
5
----
6
- git-subtree - add, merge, and split subprojects stored in subtrees
6
+ git-subtree - Merge subtrees together and split repository into subtrees
7
7
8
8
9
9
SYNOPSIS
10
10
--------
11
11
[verse]
12
- 'git subtree' add --prefix=<prefix> <repository> <refspec...>
13
- 'git subtree' pull --prefix=<prefix> <repository> <refspec...>
14
- 'git subtree' push --prefix=<prefix> <repository> <refspec...>
15
- 'git subtree' add --prefix=<prefix> <refspec>
16
- 'git subtree' merge --prefix=<prefix> <refspec>
17
- 'git subtree' split --prefix=<prefix> <refspec...>
18
-
12
+ 'git subtree' add -P <prefix>|--prefix=<prefix> <commit>
13
+ 'git subtree' pull -P <prefix>|--prefix=<prefix> <repository> <refspec...>
14
+ 'git subtree' push -P <prefix>|--prefix=<prefix> <repository> <refspec...>
15
+ 'git subtree' merge -P <prefix>|--prefix=<prefix> <commit>
16
+ 'git subtree' split -P <prefix>|--prefix=<prefix> [OPTIONS] [<commit>]
17
+
19
18
20
19
DESCRIPTION
21
20
-----------
22
- git subtree allows you to include a subproject in your
23
- own repository as a subdirectory, optionally including the
24
- subproject's entire history. For example, you could
25
- include the source code for a library as a subdirectory of your
26
- application.
27
-
28
- You can also extract the entire history of a subdirectory from
29
- your project and make it into a standalone project. For
30
- example, if a library you made for one application ends up being
31
- useful elsewhere, you can extract its entire history and publish
32
- that as its own git repository, without accidentally
33
- intermingling the history of your application project.
21
+ Subtrees allow subprojects to be included within a subdirectory
22
+ of the main project, optionally including the subproject's
23
+ entire history.
34
24
35
- Most importantly, you can alternate back and forth between these
36
- two operations. If the standalone library gets updated, you can
25
+ For example, you could include the source code for a library
26
+ as a subdirectory of your application.
27
+
28
+ Subtrees are not to be confused with submodules, which are meant for
29
+ the same task. Unlike submodules, subtrees do not need any special
30
+ constructions (like .gitmodule files or gitlinks) be present in
31
+ your repository, and do not force end-users of your
32
+ repository to do anything special or to understand how subtrees
33
+ work. A subtree is just a subdirectory that can be
34
+ committed to, branched, and merged along with your project in
35
+ any way you want.
36
+
37
+ They are neither not to be confused with using the subtree merge
38
+ strategy. The main difference is that, besides merging
39
+ of the other project as a subdirectory, you can also extract the
40
+ entire history of a subdirectory from your project and make it
41
+ into a standalone project. Unlike the subtree merge strategy
42
+ you can alternate back and forth between these
43
+ two operations. If the standalone library gets updated, you can
37
44
automatically merge the changes into your project; if you
38
45
update the library inside your project, you can "split" the
39
46
changes back out again and merge them back into the library
40
47
project.
41
48
42
- Unlike the 'git submodule' command, git subtree doesn't produce
43
- any special constructions (like .gitmodule files or gitlinks) in
44
- your repository, and doesn't require end-users of your
45
- repository to do anything special or to understand how subtrees
46
- work. A subtree is just another subdirectory and can be
47
- committed to, branched, and merged along with your project in
48
- any way you want.
49
+ For example, if a library you made for one application ends up being
50
+ useful elsewhere, you can extract its entire history and publish
51
+ that as its own git repository, without accidentally
52
+ intermingling the history of your application project.
49
53
54
+ [TIP]
50
55
In order to keep your commit messages clean, we recommend that
51
56
people split their commits between the subtrees and the main
52
57
project as much as possible. That is, if you make a change that
@@ -128,20 +133,29 @@ OPTIONS
128
133
--debug::
129
134
Produce even more unnecessary output messages on stderr.
130
135
136
+ -P <prefix>::
131
137
--prefix=<prefix>::
132
138
Specify the path in the repository to the subtree you
133
- want to manipulate. This option is currently mandatory
139
+ want to manipulate. This option is mandatory
134
140
for all commands.
135
141
142
+ -m <message>::
143
+ --message=<message>::
144
+ This option is only valid for add, merge and pull (unsure).
145
+ Specify <message> as the commit message for the merge commit.
136
146
137
- OPTIONS FOR add, merge, AND pull
138
- --------------------------------
147
+
148
+ OPTIONS FOR add, merge, push, pull
149
+ ----------------------------------
139
150
--squash::
151
+ This option is only valid for add, merge, push and pull
152
+ commands.
153
+
140
154
Instead of merging the entire history from the subtree
141
155
project, produce only a single commit that contains all
142
156
the differences you want to merge, and then merge that
143
157
new commit into your project.
144
-
158
+
145
159
Using this option helps to reduce log clutter. People
146
160
rarely want to see every change that happened between
147
161
v1.0 and v1.1 of the library they're using, since none of the
@@ -169,6 +183,8 @@ OPTIONS FOR add, merge, AND pull
169
183
OPTIONS FOR split
170
184
-----------------
171
185
--annotate=<annotation>::
186
+ This option is only valid for the split command.
187
+
172
188
When generating synthetic history, add <annotation> as a
173
189
prefix to each commit message. Since we're creating new
174
190
commits with the same commit message, but possibly
@@ -184,12 +200,16 @@ OPTIONS FOR split
184
200
185
201
-b <branch>::
186
202
--branch=<branch>::
203
+ This option is only valid for the split command.
204
+
187
205
After generating the synthetic history, create a new
188
206
branch called <branch> that contains the new history.
189
207
This is suitable for immediate pushing upstream.
190
208
<branch> must not already exist.
191
209
192
210
--ignore-joins::
211
+ This option is only valid for the split command.
212
+
193
213
If you use '--rejoin', git subtree attempts to optimize
194
214
its history reconstruction to generate only the new
195
215
commits since the last '--rejoin'. '--ignore-join'
@@ -198,6 +218,8 @@ OPTIONS FOR split
198
218
long time.
199
219
200
220
--onto=<onto>::
221
+ This option is only valid for the split command.
222
+
201
223
If your subtree was originally imported using something
202
224
other than git subtree, its history may not match what
203
225
git subtree is expecting. In that case, you can specify
@@ -210,6 +232,8 @@ OPTIONS FOR split
210
232
this option.
211
233
212
234
--rejoin::
235
+ This option is only valid for the split command.
236
+
213
237
After splitting, merge the newly created synthetic
214
238
history back into your main project. That way, future
215
239
splits can search only the part of history that has
@@ -231,8 +255,8 @@ OPTIONS FOR split
231
255
subproject's history to be part of your project anyway.
232
256
233
257
234
- EXAMPLE 1
235
- ---------
258
+ EXAMPLE 1. Add command
259
+ ----------------------
236
260
Let's assume that you have a local repository that you would like
237
261
to add an external vendor library to. In this case we will add the
238
262
git-subtree repository as a subdirectory of your already existing
@@ -251,8 +275,8 @@ We now have a ~/git-extensions/git-subtree directory containing code
251
275
from the master branch of git://github.com/apenwarr/git-subtree.git
252
276
in our git-extensions repository.
253
277
254
- EXAMPLE 2
255
- ---------
278
+ EXAMPLE 2. Extract a subtree using commit, merge and pull
279
+ ---------------------------------------------------------
256
280
Let's use the repository for the git source code as an example.
257
281
First, get your own copy of the git.git repository:
258
282
@@ -312,22 +336,24 @@ the standard gitweb:
312
336
313
337
git log gitweb-latest..$(git subtree split --prefix=gitweb)
314
338
315
- EXAMPLE 3
316
- ---------
339
+ EXAMPLE 3. Extract a subtree using branch
340
+ -----------------------------------------
317
341
Suppose you have a source directory with many files and
318
342
subdirectories, and you want to extract the lib directory to its own
319
343
git project. Here's a short way to do it:
320
344
321
345
First, make the new repository wherever you want:
322
- <go to the new location>
323
- git init --bare
346
+
347
+ $ <go to the new location>
348
+ $ git init --bare
324
349
325
350
Back in your original directory:
326
- git subtree split --prefix=lib --annotate="(split)" -b split
351
+
352
+ $ git subtree split --prefix=lib --annotate="(split)" -b split
327
353
328
354
Then push the new branch onto the new empty repository:
329
- git push <new-repo> split:master
330
355
356
+ $ git push <new-repo> split:master
331
357
332
358
333
359
AUTHOR
0 commit comments