Skip to content

Commit 7f86ff0

Browse files
Vanuanapenwarr
authored andcommitted
docs: Description, synopsys, options and examples changes.
Description: Made the difference from submodules and the subtree merge strategy clearer. Synopsys and options: Synchronize with 'git subtree -h' output. I hope, properly. Examples: Added example descriptions in captions. Small fixes. Signed-off-by: John Yani <[email protected]>
1 parent 11f1511 commit 7f86ff0

File tree

1 file changed

+69
-43
lines changed

1 file changed

+69
-43
lines changed

git-subtree.txt

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,55 @@ git-subtree(1)
33

44
NAME
55
----
6-
git-subtree - add, merge, and split subprojects stored in subtrees
6+
git-subtree - Merge subtrees together and split repository into subtrees
77

88

99
SYNOPSIS
1010
--------
1111
[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+
1918

2019
DESCRIPTION
2120
-----------
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.
3424

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
3744
automatically merge the changes into your project; if you
3845
update the library inside your project, you can "split" the
3946
changes back out again and merge them back into the library
4047
project.
4148

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.
4953

54+
[TIP]
5055
In order to keep your commit messages clean, we recommend that
5156
people split their commits between the subtrees and the main
5257
project as much as possible. That is, if you make a change that
@@ -128,20 +133,29 @@ OPTIONS
128133
--debug::
129134
Produce even more unnecessary output messages on stderr.
130135

136+
-P <prefix>::
131137
--prefix=<prefix>::
132138
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
134140
for all commands.
135141

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.
136146

137-
OPTIONS FOR add, merge, AND pull
138-
--------------------------------
147+
148+
OPTIONS FOR add, merge, push, pull
149+
----------------------------------
139150
--squash::
151+
This option is only valid for add, merge, push and pull
152+
commands.
153+
140154
Instead of merging the entire history from the subtree
141155
project, produce only a single commit that contains all
142156
the differences you want to merge, and then merge that
143157
new commit into your project.
144-
158+
145159
Using this option helps to reduce log clutter. People
146160
rarely want to see every change that happened between
147161
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
169183
OPTIONS FOR split
170184
-----------------
171185
--annotate=<annotation>::
186+
This option is only valid for the split command.
187+
172188
When generating synthetic history, add <annotation> as a
173189
prefix to each commit message. Since we're creating new
174190
commits with the same commit message, but possibly
@@ -184,12 +200,16 @@ OPTIONS FOR split
184200

185201
-b <branch>::
186202
--branch=<branch>::
203+
This option is only valid for the split command.
204+
187205
After generating the synthetic history, create a new
188206
branch called <branch> that contains the new history.
189207
This is suitable for immediate pushing upstream.
190208
<branch> must not already exist.
191209

192210
--ignore-joins::
211+
This option is only valid for the split command.
212+
193213
If you use '--rejoin', git subtree attempts to optimize
194214
its history reconstruction to generate only the new
195215
commits since the last '--rejoin'. '--ignore-join'
@@ -198,6 +218,8 @@ OPTIONS FOR split
198218
long time.
199219

200220
--onto=<onto>::
221+
This option is only valid for the split command.
222+
201223
If your subtree was originally imported using something
202224
other than git subtree, its history may not match what
203225
git subtree is expecting. In that case, you can specify
@@ -210,6 +232,8 @@ OPTIONS FOR split
210232
this option.
211233

212234
--rejoin::
235+
This option is only valid for the split command.
236+
213237
After splitting, merge the newly created synthetic
214238
history back into your main project. That way, future
215239
splits can search only the part of history that has
@@ -231,8 +255,8 @@ OPTIONS FOR split
231255
subproject's history to be part of your project anyway.
232256

233257

234-
EXAMPLE 1
235-
---------
258+
EXAMPLE 1. Add command
259+
----------------------
236260
Let's assume that you have a local repository that you would like
237261
to add an external vendor library to. In this case we will add the
238262
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
251275
from the master branch of git://github.com/apenwarr/git-subtree.git
252276
in our git-extensions repository.
253277

254-
EXAMPLE 2
255-
---------
278+
EXAMPLE 2. Extract a subtree using commit, merge and pull
279+
---------------------------------------------------------
256280
Let's use the repository for the git source code as an example.
257281
First, get your own copy of the git.git repository:
258282

@@ -312,22 +336,24 @@ the standard gitweb:
312336

313337
git log gitweb-latest..$(git subtree split --prefix=gitweb)
314338

315-
EXAMPLE 3
316-
---------
339+
EXAMPLE 3. Extract a subtree using branch
340+
-----------------------------------------
317341
Suppose you have a source directory with many files and
318342
subdirectories, and you want to extract the lib directory to its own
319343
git project. Here's a short way to do it:
320344

321345
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
324349

325350
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
327353

328354
Then push the new branch onto the new empty repository:
329-
git push <new-repo> split:master
330355

356+
$ git push <new-repo> split:master
331357

332358

333359
AUTHOR

0 commit comments

Comments
 (0)