@@ -9,13 +9,14 @@ git-subtree - Merge subtrees together and split repository into subtrees
99SYNOPSIS
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
2021DESCRIPTION
2122-----------
@@ -28,7 +29,7 @@ as a subdirectory of your application.
2829
2930Subtrees are not to be confused with submodules, which are meant for
3031the 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
3233your repository, and do not force end-users of your
3334repository to do anything special or to understand how subtrees
3435work. 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
5960affects both the library and the main application, commit it in
6061two pieces. That way, when you split the library commits out
6162later, 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
6364simply leave out the non-library-related parts of the commit
6465when it splits it out into the subproject later.
6566
6667
6768COMMANDS
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+
8587If you use '--squash', the merge direction doesn't always have to be
8688forward; you can use this command to go back in time from v2.5 to v2.4,
8789for example. If your merge introduces a conflict, you can resolve it in
8890the 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.
111103This corresponds to the HEAD of the newly created tree, which you can
112104manipulate however you want.
113105+
114106Repeated 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+
120113Note that if you use '--squash' when you merge, you should usually not
121114just '--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
124127OPTIONS
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+
156158Using this option helps to reduce log clutter. People rarely want to see
157159every 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
175177subproject.
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+
188190Whenever you split, you need to use the same <annotation>, or else you
189191don't have a guarantee that the new re-created history will be identical
190192to 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' ,
192194but 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+
220216If 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+
229223If your split commits end up merged into the upstream subproject, and
230224then 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
240234your project anyway.
241235
242236
243- EXAMPLE 1. Add command
244- ----------------------
237+ EXAMPLE 1. 'add' command
238+ ------------------------
245239Let's assume that you have a local repository that you would like
246240to add an external vendor library to. In this case we will add the
247241git-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
254248name
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
257251of commits that are included in your local repository.
258252
259253We now have a ~/git-extensions/git-subtree directory containing code
260254from the master branch of git://github.com/apenwarr/git-subtree.git
261255in 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+ ---------------------------------------------------------------
265259Let's use the repository for the git source code as an example.
266260First, 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
271265gitweb (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.
273267But imagine it had been maintained separately, and we wanted to
274268extract git's changes to gitweb since that time, to share with
275269the 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 git@github.com:whatever/gitweb.git gitweb-latest:master
282-
276+
283277(We use '0a8f4f0^..' because that means "all the changes from
2842780a8f4f0 to the current version, including 0a8f4f0 itself.")
285279
286280If 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)
288282then 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
315309And notice that your change is still intact:
316-
310+
317311 $ ls -l gitweb/myfile
318312
319313And you can split it out and look at your changes versus
320314the 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+ -------------------------------------------
326320Suppose you have a source directory with many files and
327321subdirectories, and you want to extract the lib directory to its own
328322git project. Here's a short way to do it:
0 commit comments