Git fork

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 <lukeshu@datawire.io>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Luke Shumaker and committed by
Junio C Hamano
6468784d e9525a8a

+86 -92
+2 -2
contrib/subtree/git-subtree.sh
··· 25 git subtree add --prefix=<prefix> <commit> 26 git subtree add --prefix=<prefix> <repository> <ref> 27 git subtree merge --prefix=<prefix> <commit> 28 git subtree pull --prefix=<prefix> <repository> <ref> 29 git subtree push --prefix=<prefix> <repository> <ref> 30 - git subtree split --prefix=<prefix> <commit> 31 -- 32 h,help show the help 33 q quiet ··· 40 ignore-joins ignore prior --rejoin commits 41 onto= try connecting new tree to an existing one 42 rejoin merge the new branch back into HEAD 43 - options for 'add', 'merge', and 'pull' 44 squash merge subtree changes as a single commit 45 " 46
··· 25 git subtree add --prefix=<prefix> <commit> 26 git subtree add --prefix=<prefix> <repository> <ref> 27 git subtree merge --prefix=<prefix> <commit> 28 + git subtree split --prefix=<prefix> [<commit>] 29 git subtree pull --prefix=<prefix> <repository> <ref> 30 git subtree push --prefix=<prefix> <repository> <ref> 31 -- 32 h,help show the help 33 q quiet ··· 40 ignore-joins ignore prior --rejoin commits 41 onto= try connecting new tree to an existing one 42 rejoin merge the new branch back into HEAD 43 + options for 'add' and 'merge' (also: 'pull') 44 squash merge subtree changes as a single commit 45 " 46
+81 -87
contrib/subtree/git-subtree.txt
··· 9 SYNOPSIS 10 -------- 11 [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>] 18 19 20 DESCRIPTION 21 ----------- ··· 28 29 Subtrees are not to be confused with submodules, which are meant for 30 the same task. Unlike submodules, subtrees do not need any special 31 - constructions (like .gitmodules files or gitlinks) be present in 32 your repository, and do not force end-users of your 33 repository to do anything special or to understand how subtrees 34 work. A subtree is just a subdirectory that can be ··· 59 affects both the library and the main application, commit it in 60 two pieces. That way, when you split the library commits out 61 later, their descriptions will still make sense. But if this 62 - isn't important to you, it's not *necessary*. git subtree will 63 simply leave out the non-library-related parts of the commit 64 when it splits it out into the subproject later. 65 66 67 COMMANDS 68 -------- 69 - add:: 70 Create the <prefix> subtree by importing its contents 71 - from the given <commit> or <repository> and remote <ref>. 72 A new commit is created automatically, joining the imported 73 - project's history with your own. With '--squash', imports 74 only a single commit from the subproject, rather than its 75 entire history. 76 77 - merge:: 78 - Merge recent changes up to <commit> into the <prefix> 79 subtree. As with normal 'git merge', this doesn't 80 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 rather than merging in the entire history. 84 + 85 If you use '--squash', the merge direction doesn't always have to be 86 forward; you can use this command to go back in time from v2.5 to v2.4, 87 for example. If your merge introduces a conflict, you can resolve it in 88 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:: 102 Extract a new, synthetic project history from the 103 - history of the <prefix> subtree. The new history 104 includes only the commits (including merges) that 105 affected <prefix>, and each of those commits now has the 106 contents of <prefix> at the root of the project instead 107 of in a subdirectory. Thus, the newly created history 108 is suitable for export as a separate git repository. 109 + 110 - After splitting successfully, a single commit id is printed to stdout. 111 This corresponds to the HEAD of the newly created tree, which you can 112 manipulate however you want. 113 + 114 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. 119 + 120 Note that if you use '--squash' when you merge, you should usually not 121 just '--rejoin' when you split. 122 123 124 OPTIONS 125 ------- ··· 139 140 -m <message>:: 141 --message=<message>:: 142 - This option is only valid for add, merge, pull, and split --rejoin. 143 Specify <message> as the commit message for the merge commit. 144 145 146 - OPTIONS FOR add, merge, and pull 147 - -------------------------------- 148 --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. 155 + 156 Using this option helps to reduce log clutter. People rarely want to see 157 every change that happened between v1.0 and v1.1 of the library they're ··· 175 subproject. 176 177 178 - OPTIONS FOR split 179 - ----------------- 180 --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. 187 + 188 Whenever you split, you need to use the same <annotation>, or else you 189 don't have a guarantee that the new re-created history will be identical 190 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, 192 but it may not always be effective. 193 194 -b <branch>:: 195 --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. 201 202 --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. 210 211 --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. 219 + 220 If you used 'git subtree add', you should never need this option. 221 222 --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. 228 + 229 If your split commits end up merged into the upstream subproject, and 230 then you want to get the latest upstream version, this will allow git's ··· 240 your project anyway. 241 242 243 - EXAMPLE 1. Add command 244 - ---------------------- 245 Let's assume that you have a local repository that you would like 246 to add an external vendor library to. In this case we will add the 247 git-subtree repository as a subdirectory of your already existing ··· 253 'master' needs to be a valid remote ref and can be a different branch 254 name 255 256 - You can omit the --squash flag, but doing so will increase the number 257 of commits that are included in your local repository. 258 259 We now have a ~/git-extensions/git-subtree directory containing code 260 from the master branch of git://github.com/apenwarr/git-subtree.git 261 in our git-extensions repository. 262 263 - EXAMPLE 2. Extract a subtree using commit, merge and pull 264 - --------------------------------------------------------- 265 Let's use the repository for the git source code as an example. 266 First, get your own copy of the git.git repository: 267 ··· 269 $ cd test-git 270 271 gitweb (commit 1130ef3) was merged into git as of commit 272 - 0a8f4f0, after which it was no longer maintained separately. 273 But imagine it had been maintained separately, and we wanted to 274 extract git's changes to gitweb since that time, to share with 275 the upstream. You could do this: ··· 279 --branch gitweb-latest 280 $ gitk gitweb-latest 281 $ git push git@github.com:whatever/gitweb.git gitweb-latest:master 282 - 283 (We use '0a8f4f0^..' because that means "all the changes from 284 0a8f4f0 to the current version, including 0a8f4f0 itself.") 285 286 If gitweb had originally been merged using 'git subtree add' (or 287 - a previous split had already been done with --rejoin specified) 288 then you can do all your splits without having to remember any 289 - weird commit ids: 290 291 $ git subtree split --prefix=gitweb --annotate='(split) ' --rejoin \ 292 --branch gitweb-latest2 ··· 313 $ git subtree merge --prefix=gitweb --squash gitweb-latest 314 315 And notice that your change is still intact: 316 - 317 $ ls -l gitweb/myfile 318 319 And you can split it out and look at your changes versus ··· 321 322 git log gitweb-latest..$(git subtree split --prefix=gitweb) 323 324 - EXAMPLE 3. Extract a subtree using branch 325 - ----------------------------------------- 326 Suppose you have a source directory with many files and 327 subdirectories, and you want to extract the lib directory to its own 328 git project. Here's a short way to do it:
··· 9 SYNOPSIS 10 -------- 11 [verse] 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>] 16 17 + [verse] 18 + 'git subtree' [<options>] -P <prefix> pull <repository> <remote-ref> 19 + 'git subtree' [<options>] -P <prefix> push <repository> <remote-ref> 20 21 DESCRIPTION 22 ----------- ··· 29 30 Subtrees are not to be confused with submodules, which are meant for 31 the same task. Unlike submodules, subtrees do not need any special 32 + constructions (like '.gitmodules' files or gitlinks) be present in 33 your repository, and do not force end-users of your 34 repository to do anything special or to understand how subtrees 35 work. A subtree is just a subdirectory that can be ··· 60 affects both the library and the main application, commit it in 61 two pieces. That way, when you split the library commits out 62 later, their descriptions will still make sense. But if this 63 + isn't important to you, it's not *necessary*. 'git subtree' will 64 simply leave out the non-library-related parts of the commit 65 when it splits it out into the subproject later. 66 67 68 COMMANDS 69 -------- 70 + add <local-commit>:: 71 + add <repository> <remote-ref>:: 72 Create the <prefix> subtree by importing its contents 73 + from the given <local-commit> or <repository> and <remote-ref>. 74 A new commit is created automatically, joining the imported 75 + project's history with your own. With '--squash', import 76 only a single commit from the subproject, rather than its 77 entire history. 78 79 + merge <local-commit>:: 80 + Merge recent changes up to <local-commit> into the <prefix> 81 subtree. As with normal 'git merge', this doesn't 82 remove your own local changes; it just merges those 83 + changes into the latest <local-commit>. With '--squash', 84 + create only one commit that contains all the changes, 85 rather than merging in the entire history. 86 + 87 If you use '--squash', the merge direction doesn't always have to be 88 forward; you can use this command to go back in time from v2.5 to v2.4, 89 for example. If your merge introduces a conflict, you can resolve it in 90 the usual ways. 91 92 + split [<local-commit>]:: 93 Extract a new, synthetic project history from the 94 + history of the <prefix> subtree of <local-commit>, or of 95 + HEAD if no <local-commit> is given. The new history 96 includes only the commits (including merges) that 97 affected <prefix>, and each of those commits now has the 98 contents of <prefix> at the root of the project instead 99 of in a subdirectory. Thus, the newly created history 100 is suitable for export as a separate git repository. 101 + 102 + After splitting successfully, a single commit ID is printed to stdout. 103 This corresponds to the HEAD of the newly created tree, which you can 104 manipulate however you want. 105 + 106 Repeated splits of exactly the same history are guaranteed to be 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. 112 + 113 Note that if you use '--squash' when you merge, you should usually not 114 just '--rejoin' when you split. 115 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. 126 127 OPTIONS 128 ------- ··· 142 143 -m <message>:: 144 --message=<message>:: 145 + This option is only valid for 'add', 'merge', 'pull', and 'split --rejoin'. 146 Specify <message> as the commit message for the merge commit. 147 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'). 152 153 --squash:: 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. 157 + 158 Using this option helps to reduce log clutter. People rarely want to see 159 every change that happened between v1.0 and v1.1 of the library they're ··· 177 subproject. 178 179 180 + OPTIONS FOR 'split' 181 + ------------------- 182 + These options are only valid for 'split'. 183 + 184 --annotate=<annotation>:: 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. 189 + 190 Whenever you split, you need to use the same <annotation>, or else you 191 don't have a guarantee that the new re-created history will be identical 192 to the old one. That will prevent merging from working correctly. git 193 + subtree tries to make it work anyway, particularly if you use '--rejoin', 194 but it may not always be effective. 195 196 -b <branch>:: 197 --branch=<branch>:: 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. 201 202 --ignore-joins:: 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. 208 209 --onto=<onto>:: 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. 215 + 216 If you used 'git subtree add', you should never need this option. 217 218 --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'. 222 + 223 If your split commits end up merged into the upstream subproject, and 224 then you want to get the latest upstream version, this will allow git's ··· 234 your project anyway. 235 236 237 + EXAMPLE 1. 'add' command 238 + ------------------------ 239 Let's assume that you have a local repository that you would like 240 to add an external vendor library to. In this case we will add the 241 git-subtree repository as a subdirectory of your already existing ··· 247 'master' needs to be a valid remote ref and can be a different branch 248 name 249 250 + You can omit the '--squash' flag, but doing so will increase the number 251 of commits that are included in your local repository. 252 253 We now have a ~/git-extensions/git-subtree directory containing code 254 from the master branch of git://github.com/apenwarr/git-subtree.git 255 in our git-extensions repository. 256 257 + EXAMPLE 2. Extract a subtree using 'commit', 'merge' and 'pull' 258 + --------------------------------------------------------------- 259 Let's use the repository for the git source code as an example. 260 First, get your own copy of the git.git repository: 261 ··· 263 $ cd test-git 264 265 gitweb (commit 1130ef3) was merged into git as of commit 266 + 0a8f4f0, after which it was no longer maintained separately. 267 But imagine it had been maintained separately, and we wanted to 268 extract git's changes to gitweb since that time, to share with 269 the upstream. You could do this: ··· 273 --branch gitweb-latest 274 $ gitk gitweb-latest 275 $ git push git@github.com:whatever/gitweb.git gitweb-latest:master 276 + 277 (We use '0a8f4f0^..' because that means "all the changes from 278 0a8f4f0 to the current version, including 0a8f4f0 itself.") 279 280 If gitweb had originally been merged using 'git subtree add' (or 281 + a previous split had already been done with '--rejoin' specified) 282 then you can do all your splits without having to remember any 283 + weird commit IDs: 284 285 $ git subtree split --prefix=gitweb --annotate='(split) ' --rejoin \ 286 --branch gitweb-latest2 ··· 307 $ git subtree merge --prefix=gitweb --squash gitweb-latest 308 309 And notice that your change is still intact: 310 + 311 $ ls -l gitweb/myfile 312 313 And you can split it out and look at your changes versus ··· 315 316 git log gitweb-latest..$(git subtree split --prefix=gitweb) 317 318 + EXAMPLE 3. Extract a subtree using a branch 319 + ------------------------------------------- 320 Suppose you have a source directory with many files and 321 subdirectories, and you want to extract the lib directory to its own 322 git project. Here's a short way to do it:
+3 -3
contrib/subtree/todo
··· 23 24 "pull" and "merge" commands should fail if you've never merged 25 that --prefix before 26 - 27 docs should provide an example of "add" 28 - 29 note that the initial split doesn't *have* to have a commitid 30 specified... that's just an optimization 31 ··· 33 get a misleading "prefix must end with /" message from 34 one of the other git tools that git-subtree calls. Should 35 detect this situation and print the *real* problem. 36 - 37 "pull --squash" should do fetch-synthesize-merge, but instead just 38 does "pull" directly, which doesn't work at all. 39
··· 23 24 "pull" and "merge" commands should fail if you've never merged 25 that --prefix before 26 + 27 docs should provide an example of "add" 28 + 29 note that the initial split doesn't *have* to have a commitid 30 specified... that's just an optimization 31 ··· 33 get a misleading "prefix must end with /" message from 34 one of the other git tools that git-subtree calls. Should 35 detect this situation and print the *real* problem. 36 + 37 "pull --squash" should do fetch-synthesize-merge, but instead just 38 does "pull" directly, which doesn't work at all. 39