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