Skip to content

Commit 6468784

Browse files
LukeShugitster
authored andcommitted
subtree: give the docs a once-over
Just went through the docs looking for anything inaccurate or that can be improved. In the '-h' text, in the man page synopsis, and in the man page description: Normalize the ordering of the list of sub-commands: 'add', 'merge', 'split', 'pull', 'push'. This allows us to kinda separate the lower-level add/merge/split from the higher-level pull/push. '-h' text: - correction: Indicate that split's arg is optional. - clarity: Emphasize that 'pull' takes the 'add'/'merge' flags. man page: - correction: State that all subcommands take options (it seemed to indicate that only 'split' takes any options other than '-P'). - correction: 'split' only guarantees that the results are identical if the flags are identical. - correction: The flag is named '--ignore-joins', not '--ignore-join'. - completeness: Clarify that 'push' always operates on HEAD, and that 'split' operates on HEAD if no local commit is given. - clarity: In the description, when listing commands, repeat what their arguments are. This way the reader doesn't need to flip back and forth between the command description and the synopsis and the full description to understand what's being said. - clarity: In the <variables> used to give command arguments, give slightly longer, descriptive names. Like <local-commit> instead of just <commit>. - clarity: Emphasize that 'pull' takes the 'add'/'merge' flags. - style: In the synopsis, list options before the subcommand. This makes things line up and be much more readable when shown non-monospace (such as in `make html`), and also more closely matches other man pages (like `git-submodule.txt`). - style: Use the correct syntax for indicating the options ([<options>] instead of [OPTIONS]). - style: In the synopsis, separate 'pull' and 'push' from the other lower-level commands. I think this helps readability. - style: Code-quote things in prose that seem like they should be code-quoted, like '.gitmodules', flags, or full commands. - style: Minor wording improvements, like more consistent mood (many of the command descriptions start in the imperative mood and switch to the indicative mode by the end). That sort of thing. - style: Capitalize "ID". - style: Remove the "This option is only valid for XXX command" remarks from each option, and instead rely on the section headings. - style: Since that line is getting edited anyway, switch "behaviour" to American "behavior". - style: Trim trailing whitespace. `todo`: - style: Trim trailing whitespace. Signed-off-by: Luke Shumaker <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e9525a8 commit 6468784

File tree

3 files changed

+87
-93
lines changed

3 files changed

+87
-93
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ OPTS_SPEC="\
2525
git subtree add --prefix=<prefix> <commit>
2626
git subtree add --prefix=<prefix> <repository> <ref>
2727
git subtree merge --prefix=<prefix> <commit>
28+
git subtree split --prefix=<prefix> [<commit>]
2829
git subtree pull --prefix=<prefix> <repository> <ref>
2930
git subtree push --prefix=<prefix> <repository> <ref>
30-
git subtree split --prefix=<prefix> <commit>
3131
--
3232
h,help show the help
3333
q quiet
@@ -40,7 +40,7 @@ b,branch= create a new branch from the split subtree
4040
ignore-joins ignore prior --rejoin commits
4141
onto= try connecting new tree to an existing one
4242
rejoin merge the new branch back into HEAD
43-
options for 'add', 'merge', and 'pull'
43+
options for 'add' and 'merge' (also: 'pull')
4444
squash merge subtree changes as a single commit
4545
"
4646

contrib/subtree/git-subtree.txt

Lines changed: 82 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ git-subtree - Merge subtrees together and split repository into subtrees
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git subtree' add -P <prefix> <commit>
13-
'git subtree' add -P <prefix> <repository> <ref>
14-
'git subtree' pull -P <prefix> <repository> <ref>
15-
'git subtree' push -P <prefix> <repository> <ref>
16-
'git subtree' merge -P <prefix> <commit>
17-
'git subtree' split -P <prefix> [OPTIONS] [<commit>]
12+
'git subtree' [<options>] -P <prefix> add <local-commit>
13+
'git subtree' [<options>] -P <prefix> add <repository> <remote-ref>
14+
'git subtree' [<options>] -P <prefix> merge <local-commit>
15+
'git subtree' [<options>] -P <prefix> split [<local-commit>]
1816

17+
[verse]
18+
'git subtree' [<options>] -P <prefix> pull <repository> <remote-ref>
19+
'git subtree' [<options>] -P <prefix> push <repository> <remote-ref>
1920

2021
DESCRIPTION
2122
-----------
@@ -28,7 +29,7 @@ as a subdirectory of your application.
2829

2930
Subtrees are not to be confused with submodules, which are meant for
3031
the same task. Unlike submodules, subtrees do not need any special
31-
constructions (like .gitmodules files or gitlinks) be present in
32+
constructions (like '.gitmodules' files or gitlinks) be present in
3233
your repository, and do not force end-users of your
3334
repository to do anything special or to understand how subtrees
3435
work. A subtree is just a subdirectory that can be
@@ -59,67 +60,69 @@ project as much as possible. That is, if you make a change that
5960
affects both the library and the main application, commit it in
6061
two pieces. That way, when you split the library commits out
6162
later, their descriptions will still make sense. But if this
62-
isn't important to you, it's not *necessary*. git subtree will
63+
isn't important to you, it's not *necessary*. 'git subtree' will
6364
simply leave out the non-library-related parts of the commit
6465
when it splits it out into the subproject later.
6566

6667

6768
COMMANDS
6869
--------
69-
add::
70+
add <local-commit>::
71+
add <repository> <remote-ref>::
7072
Create the <prefix> subtree by importing its contents
71-
from the given <commit> or <repository> and remote <ref>.
73+
from the given <local-commit> or <repository> and <remote-ref>.
7274
A new commit is created automatically, joining the imported
73-
project's history with your own. With '--squash', imports
75+
project's history with your own. With '--squash', import
7476
only a single commit from the subproject, rather than its
7577
entire history.
7678

77-
merge::
78-
Merge recent changes up to <commit> into the <prefix>
79+
merge <local-commit>::
80+
Merge recent changes up to <local-commit> into the <prefix>
7981
subtree. As with normal 'git merge', this doesn't
8082
remove your own local changes; it just merges those
81-
changes into the latest <commit>. With '--squash',
82-
creates only one commit that contains all the changes,
83+
changes into the latest <local-commit>. With '--squash',
84+
create only one commit that contains all the changes,
8385
rather than merging in the entire history.
8486
+
8587
If you use '--squash', the merge direction doesn't always have to be
8688
forward; you can use this command to go back in time from v2.5 to v2.4,
8789
for example. If your merge introduces a conflict, you can resolve it in
8890
the usual ways.
89-
90-
pull::
91-
Exactly like 'merge', but parallels 'git pull' in that
92-
it fetches the given ref from the specified remote
93-
repository.
94-
95-
push::
96-
Does a 'split' (see below) using the <prefix> supplied
97-
and then does a 'git push' to push the result to the
98-
repository and ref. This can be used to push your
99-
subtree to different branches of the remote repository.
100-
101-
split::
91+
92+
split [<local-commit>]::
10293
Extract a new, synthetic project history from the
103-
history of the <prefix> subtree. The new history
94+
history of the <prefix> subtree of <local-commit>, or of
95+
HEAD if no <local-commit> is given. The new history
10496
includes only the commits (including merges) that
10597
affected <prefix>, and each of those commits now has the
10698
contents of <prefix> at the root of the project instead
10799
of in a subdirectory. Thus, the newly created history
108100
is suitable for export as a separate git repository.
109101
+
110-
After splitting successfully, a single commit id is printed to stdout.
102+
After splitting successfully, a single commit ID is printed to stdout.
111103
This corresponds to the HEAD of the newly created tree, which you can
112104
manipulate however you want.
113105
+
114106
Repeated splits of exactly the same history are guaranteed to be
115-
identical (i.e. to produce the same commit ids). Because of this, if
116-
you add new commits and then re-split, the new commits will be attached
117-
as commits on top of the history you generated last time, so 'git merge'
118-
and friends will work as expected.
107+
identical (i.e. to produce the same commit IDs) as long as the
108+
settings passed to 'split' (such as '--annotate') are the same.
109+
Because of this, if you add new commits and then re-split, the new
110+
commits will be attached as commits on top of the history you
111+
generated last time, so 'git merge' and friends will work as expected.
119112
+
120113
Note that if you use '--squash' when you merge, you should usually not
121114
just '--rejoin' when you split.
122115

116+
pull <repository> <remote-ref>::
117+
Exactly like 'merge', but parallels 'git pull' in that
118+
it fetches the given ref from the specified remote
119+
repository.
120+
121+
push <repository> <remote-ref>::
122+
Does a 'split' using the <prefix> subtree of HEAD and then
123+
does a 'git push' to push the result to the <repository> and
124+
<remote-ref>. This can be used to push your subtree to
125+
different branches of the remote repository.
123126

124127
OPTIONS
125128
-------
@@ -139,19 +142,18 @@ OPTIONS
139142

140143
-m <message>::
141144
--message=<message>::
142-
This option is only valid for add, merge, pull, and split --rejoin.
145+
This option is only valid for 'add', 'merge', 'pull', and 'split --rejoin'.
143146
Specify <message> as the commit message for the merge commit.
144147

148+
OPTIONS FOR 'add' AND 'merge' (ALSO: 'pull')
149+
--------------------------------------------
150+
These options for 'add' and 'merge' may also be given to 'pull' (which
151+
wraps 'merge').
145152

146-
OPTIONS FOR add, merge, and pull
147-
--------------------------------
148153
--squash::
149-
This option is only valid for add, merge, and pull
150-
commands.
151-
+
152-
Instead of merging the entire history from the subtree project, produce
153-
only a single commit that contains all the differences you want to
154-
merge, and then merge that new commit into your project.
154+
Instead of merging the entire history from the subtree project, produce
155+
only a single commit that contains all the differences you want to
156+
merge, and then merge that new commit into your project.
155157
+
156158
Using this option helps to reduce log clutter. People rarely want to see
157159
every change that happened between v1.0 and v1.1 of the library they're
@@ -175,56 +177,48 @@ remain intact and can be later split and send upstream to the
175177
subproject.
176178

177179

178-
OPTIONS FOR split
179-
-----------------
180+
OPTIONS FOR 'split'
181+
-------------------
182+
These options are only valid for 'split'.
183+
180184
--annotate=<annotation>::
181-
This option is only valid for the split command.
182-
+
183-
When generating synthetic history, add <annotation> as a prefix to each
184-
commit message. Since we're creating new commits with the same commit
185-
message, but possibly different content, from the original commits, this
186-
can help to differentiate them and avoid confusion.
185+
When generating synthetic history, add <annotation> as a prefix to each
186+
commit message. Since we're creating new commits with the same commit
187+
message, but possibly different content, from the original commits, this
188+
can help to differentiate them and avoid confusion.
187189
+
188190
Whenever you split, you need to use the same <annotation>, or else you
189191
don't have a guarantee that the new re-created history will be identical
190192
to the old one. That will prevent merging from working correctly. git
191-
subtree tries to make it work anyway, particularly if you use --rejoin,
193+
subtree tries to make it work anyway, particularly if you use '--rejoin',
192194
but it may not always be effective.
193195

194196
-b <branch>::
195197
--branch=<branch>::
196-
This option is only valid for the split command.
197-
+
198-
After generating the synthetic history, create a new branch called
199-
<branch> that contains the new history. This is suitable for immediate
200-
pushing upstream. <branch> must not already exist.
198+
After generating the synthetic history, create a new branch called
199+
<branch> that contains the new history. This is suitable for immediate
200+
pushing upstream. <branch> must not already exist.
201201

202202
--ignore-joins::
203-
This option is only valid for the split command.
204-
+
205-
If you use '--rejoin', git subtree attempts to optimize its history
206-
reconstruction to generate only the new commits since the last
207-
'--rejoin'. '--ignore-join' disables this behaviour, forcing it to
208-
regenerate the entire history. In a large project, this can take a long
209-
time.
203+
If you use '--rejoin', git subtree attempts to optimize its history
204+
reconstruction to generate only the new commits since the last
205+
'--rejoin'. '--ignore-joins' disables this behavior, forcing it to
206+
regenerate the entire history. In a large project, this can take a long
207+
time.
210208

211209
--onto=<onto>::
212-
This option is only valid for the split command.
213-
+
214-
If your subtree was originally imported using something other than git
215-
subtree, its history may not match what git subtree is expecting. In
216-
that case, you can specify the commit id <onto> that corresponds to the
217-
first revision of the subproject's history that was imported into your
218-
project, and git subtree will attempt to build its history from there.
210+
If your subtree was originally imported using something other than git
211+
subtree, its history may not match what git subtree is expecting. In
212+
that case, you can specify the commit ID <onto> that corresponds to the
213+
first revision of the subproject's history that was imported into your
214+
project, and git subtree will attempt to build its history from there.
219215
+
220216
If you used 'git subtree add', you should never need this option.
221217

222218
--rejoin::
223-
This option is only valid for the split command.
224-
+
225-
After splitting, merge the newly created synthetic history back into
226-
your main project. That way, future splits can search only the part of
227-
history that has been added since the most recent --rejoin.
219+
After splitting, merge the newly created synthetic history back into
220+
your main project. That way, future splits can search only the part of
221+
history that has been added since the most recent '--rejoin'.
228222
+
229223
If your split commits end up merged into the upstream subproject, and
230224
then you want to get the latest upstream version, this will allow git's
@@ -240,8 +234,8 @@ split, because you don't want the subproject's history to be part of
240234
your project anyway.
241235

242236

243-
EXAMPLE 1. Add command
244-
----------------------
237+
EXAMPLE 1. 'add' command
238+
------------------------
245239
Let's assume that you have a local repository that you would like
246240
to add an external vendor library to. In this case we will add the
247241
git-subtree repository as a subdirectory of your already existing
@@ -253,23 +247,23 @@ git-extensions repository in ~/git-extensions/:
253247
'master' needs to be a valid remote ref and can be a different branch
254248
name
255249

256-
You can omit the --squash flag, but doing so will increase the number
250+
You can omit the '--squash' flag, but doing so will increase the number
257251
of commits that are included in your local repository.
258252

259253
We now have a ~/git-extensions/git-subtree directory containing code
260254
from the master branch of git://github.com/apenwarr/git-subtree.git
261255
in our git-extensions repository.
262256

263-
EXAMPLE 2. Extract a subtree using commit, merge and pull
264-
---------------------------------------------------------
257+
EXAMPLE 2. Extract a subtree using 'commit', 'merge' and 'pull'
258+
---------------------------------------------------------------
265259
Let's use the repository for the git source code as an example.
266260
First, get your own copy of the git.git repository:
267261

268262
$ git clone git://git.kernel.org/pub/scm/git/git.git test-git
269263
$ cd test-git
270264

271265
gitweb (commit 1130ef3) was merged into git as of commit
272-
0a8f4f0, after which it was no longer maintained separately.
266+
0a8f4f0, after which it was no longer maintained separately.
273267
But imagine it had been maintained separately, and we wanted to
274268
extract git's changes to gitweb since that time, to share with
275269
the upstream. You could do this:
@@ -279,14 +273,14 @@ the upstream. You could do this:
279273
--branch gitweb-latest
280274
$ gitk gitweb-latest
281275
$ git push [email protected]:whatever/gitweb.git gitweb-latest:master
282-
276+
283277
(We use '0a8f4f0^..' because that means "all the changes from
284278
0a8f4f0 to the current version, including 0a8f4f0 itself.")
285279

286280
If gitweb had originally been merged using 'git subtree add' (or
287-
a previous split had already been done with --rejoin specified)
281+
a previous split had already been done with '--rejoin' specified)
288282
then you can do all your splits without having to remember any
289-
weird commit ids:
283+
weird commit IDs:
290284

291285
$ git subtree split --prefix=gitweb --annotate='(split) ' --rejoin \
292286
--branch gitweb-latest2
@@ -313,16 +307,16 @@ And fast forward again:
313307
$ git subtree merge --prefix=gitweb --squash gitweb-latest
314308

315309
And notice that your change is still intact:
316-
310+
317311
$ ls -l gitweb/myfile
318312

319313
And you can split it out and look at your changes versus
320314
the standard gitweb:
321315

322316
git log gitweb-latest..$(git subtree split --prefix=gitweb)
323317

324-
EXAMPLE 3. Extract a subtree using branch
325-
-----------------------------------------
318+
EXAMPLE 3. Extract a subtree using a branch
319+
-------------------------------------------
326320
Suppose you have a source directory with many files and
327321
subdirectories, and you want to extract the lib directory to its own
328322
git project. Here's a short way to do it:

contrib/subtree/todo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323

2424
"pull" and "merge" commands should fail if you've never merged
2525
that --prefix before
26-
26+
2727
docs should provide an example of "add"
28-
28+
2929
note that the initial split doesn't *have* to have a commitid
3030
specified... that's just an optimization
3131

3232
if you try to add (or maybe merge?) with an invalid commitid, you
3333
get a misleading "prefix must end with /" message from
3434
one of the other git tools that git-subtree calls. Should
3535
detect this situation and print the *real* problem.
36-
36+
3737
"pull --squash" should do fetch-synthesize-merge, but instead just
3838
does "pull" directly, which doesn't work at all.
3939

0 commit comments

Comments
 (0)