source: trunk/dports/devel/git/files/git-subtree.1.diff @ 120912

Last change on this file since 120912 was 120912, checked in by ciserlohn@…, 6 years ago

git, git-core: update to version 2.0.0; rename to git (closes #37279) and update all dependent ports

File size: 16.7 KB
  • contrib/subtree/git-subtree.1

    diff -urN a/contrib/subtree/git-subtree.1 b/contrib/subtree/git-subtree.1
    a b  
     1'\" t
     2.\"     Title: git-subtree
     3.\"    Author: [see the "AUTHOR" section]
     4.\" Generator: DocBook XSL Stylesheets v1.78.1 <>
     5.\"      Date: 03/17/2014
     6.\"    Manual: Git Manual
     7.\"    Source: Git 2.0.0
     8.\"  Language: English
     10.TH "GIT\-SUBTREE" "1" "03/17/2014" "Git 2\&.0\&.0" "Git Manual"
     11.\" -----------------------------------------------------------------
     12.\" * Define some portability stuff
     13.\" -----------------------------------------------------------------
     14.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     17.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n(.g .ds Aq \(aq
     19.el       .ds Aq '
     20.\" -----------------------------------------------------------------
     21.\" * set default formatting
     22.\" -----------------------------------------------------------------
     23.\" disable hyphenation
     25.\" disable justification (adjust text to left margin only) l
     27.\" -----------------------------------------------------------------
     29.\" -----------------------------------------------------------------
     30.SH "NAME"
     31git-subtree \- Merge subtrees together and split repository into subtrees
     32.SH "SYNOPSIS"
     35\fIgit subtree\fR add   \-P <prefix> <commit>
     36\fIgit subtree\fR add   \-P <prefix> <repository> <ref>
     37\fIgit subtree\fR pull  \-P <prefix> <repository> <ref>
     38\fIgit subtree\fR push  \-P <prefix> <repository> <ref>
     39\fIgit subtree\fR merge \-P <prefix> <commit>
     40\fIgit subtree\fR split \-P <prefix> [OPTIONS] [<commit>]
     44Subtrees allow subprojects to be included within a subdirectory of the main project, optionally including the subproject\(cqs entire history\&.
     46For example, you could include the source code for a library as a subdirectory of your application\&.
     48Subtrees are not to be confused with submodules, which are meant for the same task\&. Unlike submodules, subtrees do not need any special constructions (like \&.gitmodule files or gitlinks) be present in your repository, and do not force end\-users of your repository to do anything special or to understand how subtrees work\&. A subtree is just a subdirectory that can be committed to, branched, and merged along with your project in any way you want\&.
     50They are also not to be confused with using the subtree merge strategy\&. The main difference is that, besides merging the other project as a subdirectory, you can also extract the entire history of a subdirectory from your project and make it into a standalone project\&. Unlike the subtree merge strategy you can alternate back and forth between these two operations\&. If the standalone library gets updated, you can automatically merge the changes into your project; if you update the library inside your project, you can "split" the changes back out again and merge them back into the library project\&.
     52For example, if a library you made for one application ends up being useful elsewhere, you can extract its entire history and publish that as its own git repository, without accidentally intermingling the history of your application project\&.
     53.if n \{\
     56.RS 4 1 an-trap an-no-space-flag 1 an-break-flag 1 +1
     62\fBTip\fR -1
     66In order to keep your commit messages clean, we recommend that people split their commits between the subtrees and the main project as much as possible\&. That is, if you make a change that affects both the library and the main application, commit it in two pieces\&. That way, when you split the library commits out later, their descriptions will still make sense\&. But if this isn\(cqt important to you, it\(cqs not \fBnecessary\fR\&. git subtree will simply leave out the non\-library\-related parts of the commit when it splits it out into the subproject later\&.
     67.sp .5v
     69.SH "COMMANDS"
     72.RS 4
     73Create the <prefix> subtree by importing its contents from the given <commit> or <repository> and remote <ref>\&. A new commit is created automatically, joining the imported project\(cqs history with your own\&. With
     74\fI\-\-squash\fR, imports only a single commit from the subproject, rather than its entire history\&.
     78.RS 4
     79Merge recent changes up to <commit> into the <prefix> subtree\&. As with normal
     80\fIgit merge\fR, this doesn\(cqt remove your own local changes; it just merges those changes into the latest <commit>\&. With
     81\fI\-\-squash\fR, creates only one commit that contains all the changes, rather than merging in the entire history\&.
     83.if n \{\
     84.RS 4
     87If you use \*(Aq\-\-squash\*(Aq, the merge direction doesn\*(Aqt
     88always have to be forward; you can use this command to
     89go back in time from v2\&.5 to v2\&.4, for example\&.  If your
     90merge introduces a conflict, you can resolve it in the
     91usual ways\&.
     93.if n \{\
     99.RS 4
     100Exactly like
     101\fImerge\fR, but parallels
     102\fIgit pull\fR
     103in that it fetches the given ref from the specified remote repository\&.
     107.RS 4
     108Does a
     110(see below) using the <prefix> supplied and then does a
     111\fIgit push\fR
     112to push the result to the repository and ref\&. This can be used to push your subtree to different branches of the remote repository\&.
     116.RS 4
     117Extract a new, synthetic project history from the history of the <prefix> subtree\&. The new history includes only the commits (including merges) that affected <prefix>, and each of those commits now has the contents of <prefix> at the root of the project instead of in a subdirectory\&. Thus, the newly created history is suitable for export as a separate git repository\&.
     119.if n \{\
     120.RS 4
     123After splitting successfully, a single commit id is
     124printed to stdout\&.  This corresponds to the HEAD of the
     125newly created tree, which you can manipulate however you
     128.if n \{\
     132.if n \{\
     133.RS 4
     136Repeated splits of exactly the same history are
     137guaranteed to be identical (ie\&. to produce the same
     138commit ids)\&.  Because of this, if you add new commits
     139and then re\-split, the new commits will be attached as
     140commits on top of the history you generated last time,
     141so \*(Aqgit merge\*(Aq and friends will work as expected\&.
     143.if n \{\
     147.if n \{\
     148.RS 4
     151Note that if you use \*(Aq\-\-squash\*(Aq when you merge, you
     152should usually not just \*(Aq\-\-rejoin\*(Aq when you split\&.
     154.if n \{\
     158.SH "OPTIONS"
     160\-q, \-\-quiet
     161.RS 4
     162Suppress unnecessary output messages on stderr\&.
     165\-d, \-\-debug
     166.RS 4
     167Produce even more unnecessary output messages on stderr\&.
     170\-P <prefix>, \-\-prefix=<prefix>
     171.RS 4
     172Specify the path in the repository to the subtree you want to manipulate\&. This option is mandatory for all commands\&.
     175\-m <message>, \-\-message=<message>
     176.RS 4
     177This option is only valid for add, merge and pull (unsure)\&. Specify <message> as the commit message for the merge commit\&.
     182.RS 4
     183This option is only valid for add, merge, push and pull commands\&.
     185.if n \{\
     186.RS 4
     189Instead of merging the entire history from the subtree
     190project, produce only a single commit that contains all
     191the differences you want to merge, and then merge that
     192new commit into your project\&.
     194.if n \{\
     198.if n \{\
     199.RS 4
     202Using this option helps to reduce log clutter\&. People
     203rarely want to see every change that happened between
     204v1\&.0 and v1\&.1 of the library they\*(Aqre using, since none of the
     205interim versions were ever included in their application\&.
     207.if n \{\
     211.if n \{\
     212.RS 4
     215Using \*(Aq\-\-squash\*(Aq also helps avoid problems when the same
     216subproject is included multiple times in the same
     217project, or is removed and then re\-added\&.  In such a
     218case, it doesn\*(Aqt make sense to combine the histories
     219anyway, since it\*(Aqs unclear which part of the history
     220belongs to which subtree\&.
     222.if n \{\
     226.if n \{\
     227.RS 4
     230Furthermore, with \*(Aq\-\-squash\*(Aq, you can switch back and
     231forth between different versions of a subtree, rather
     232than strictly forward\&.  \*(Aqgit subtree merge \-\-squash\*(Aq
     233always adjusts the subtree to match the exactly
     234specified commit, even if getting to that commit would
     235require undoing some changes that were added earlier\&.
     237.if n \{\
     241.if n \{\
     242.RS 4
     245Whether or not you use \*(Aq\-\-squash\*(Aq, changes made in your
     246local repository remain intact and can be later split
     247and send upstream to the subproject\&.
     249.if n \{\
     256.RS 4
     257This option is only valid for the split command\&.
     259.if n \{\
     260.RS 4
     263When generating synthetic history, add <annotation> as a
     264prefix to each commit message\&.  Since we\*(Aqre creating new
     265commits with the same commit message, but possibly
     266different content, from the original commits, this can help
     267to differentiate them and avoid confusion\&.
     269.if n \{\
     273.if n \{\
     274.RS 4
     277Whenever you split, you need to use the same
     278<annotation>, or else you don\*(Aqt have a guarantee that
     279the new re\-created history will be identical to the old
     280one\&.  That will prevent merging from working correctly\&.
     281git subtree tries to make it work anyway, particularly
     282if you use \-\-rejoin, but it may not always be effective\&.
     284.if n \{\
     289\-b <branch>, \-\-branch=<branch>
     290.RS 4
     291This option is only valid for the split command\&.
     293.if n \{\
     294.RS 4
     297After generating the synthetic history, create a new
     298branch called <branch> that contains the new history\&.
     299This is suitable for immediate pushing upstream\&.
     300<branch> must not already exist\&.
     302.if n \{\
     308.RS 4
     309This option is only valid for the split command\&.
     311.if n \{\
     312.RS 4
     315If you use \*(Aq\-\-rejoin\*(Aq, git subtree attempts to optimize
     316its history reconstruction to generate only the new
     317commits since the last \*(Aq\-\-rejoin\*(Aq\&.  \*(Aq\-\-ignore\-join\*(Aq
     318disables this behaviour, forcing it to regenerate the
     319entire history\&.  In a large project, this can take a
     320long time\&.
     322.if n \{\
     328.RS 4
     329This option is only valid for the split command\&.
     331.if n \{\
     332.RS 4
     335If your subtree was originally imported using something
     336other than git subtree, its history may not match what
     337git subtree is expecting\&.  In that case, you can specify
     338the commit id <onto> that corresponds to the first
     339revision of the subproject\*(Aqs history that was imported
     340into your project, and git subtree will attempt to build
     341its history from there\&.
     343.if n \{\
     347.if n \{\
     348.RS 4
     351If you used \*(Aqgit subtree add\*(Aq, you should never need
     352this option\&.
     354.if n \{\
     360.RS 4
     361This option is only valid for the split command\&.
     363.if n \{\
     364.RS 4
     367After splitting, merge the newly created synthetic
     368history back into your main project\&.  That way, future
     369splits can search only the part of history that has
     370been added since the most recent \-\-rejoin\&.
     372.if n \{\
     376.if n \{\
     377.RS 4
     380If your split commits end up merged into the upstream
     381subproject, and then you want to get the latest upstream
     382version, this will allow git\*(Aqs merge algorithm to more
     383intelligently avoid conflicts (since it knows these
     384synthetic commits are already part of the upstream
     387.if n \{\
     391.if n \{\
     392.RS 4
     395Unfortunately, using this option results in \*(Aqgit log\*(Aq
     396showing an extra copy of every new commit that was
     397created (the original, and the synthetic one)\&.
     399.if n \{\
     403.if n \{\
     404.RS 4
     407If you do all your merges with \*(Aq\-\-squash\*(Aq, don\*(Aqt use
     408\*(Aq\-\-rejoin\*(Aq when you split, because you don\*(Aqt want the
     409subproject\*(Aqs history to be part of your project anyway\&.
     411.if n \{\
     417Let\(cqs assume that you have a local repository that you would like to add an external vendor library to\&. In this case we will add the git\-subtree repository as a subdirectory of your already existing git\-extensions repository in ~/git\-extensions/:
     419.if n \{\
     420.RS 4
     423$ git subtree add \-\-prefix=git\-subtree \-\-squash \e
     424        git://github\&.com/apenwarr/git\-subtree\&.git master
     426.if n \{\
     430\fImaster\fR needs to be a valid remote ref and can be a different branch name
     432You can omit the \-\-squash flag, but doing so will increase the number of commits that are included in your local repository\&.
     434We now have a ~/git\-extensions/git\-subtree directory containing code from the master branch of git://github\&.com/apenwarr/git\-subtree\&.git in our git\-extensions repository\&.
     437Let\(cqs use the repository for the git source code as an example\&. First, get your own copy of the git\&.git repository:
     439.if n \{\
     440.RS 4
     443$ git clone git://git\&.kernel\&.org/pub/scm/git/git\&.git test\-git
     444$ cd test\-git
     446.if n \{\
     450gitweb (commit 1130ef3) was merged into git as of commit 0a8f4f0, after which it was no longer maintained separately\&. But imagine it had been maintained separately, and we wanted to extract git\(cqs changes to gitweb since that time, to share with the upstream\&. You could do this:
     452.if n \{\
     453.RS 4
     456$ git subtree split \-\-prefix=gitweb \-\-annotate=\*(Aq(split) \*(Aq \e
     457        0a8f4f0^\&.\&. \-\-onto=1130ef3 \-\-rejoin \e
     458        \-\-branch gitweb\-latest
     459$ gitk gitweb\-latest
     460$ git push git@github\&.com:whatever/gitweb\&.git gitweb\-latest:master
     462.if n \{\
     466(We use \fI0a8f4f0^\&.\&.\fR because that means "all the changes from 0a8f4f0 to the current version, including 0a8f4f0 itself\&.")
     468If gitweb had originally been merged using \fIgit subtree add\fR (or a previous split had already been done with \-\-rejoin specified) then you can do all your splits without having to remember any weird commit ids:
     470.if n \{\
     471.RS 4
     474$ git subtree split \-\-prefix=gitweb \-\-annotate=\*(Aq(split) \*(Aq \-\-rejoin \e
     475        \-\-branch gitweb\-latest2
     477.if n \{\
     481And you can merge changes back in from the upstream project just as easily:
     483.if n \{\
     484.RS 4
     487$ git subtree pull \-\-prefix=gitweb \e
     488        git@github\&.com:whatever/gitweb\&.git master
     490.if n \{\
     494Or, using \fI\-\-squash\fR, you can actually rewind to an earlier version of gitweb:
     496.if n \{\
     497.RS 4
     500$ git subtree merge \-\-prefix=gitweb \-\-squash gitweb\-latest~10
     502.if n \{\
     506Then make some changes:
     508.if n \{\
     509.RS 4
     512$ date >gitweb/myfile
     513$ git add gitweb/myfile
     514$ git commit \-m \*(Aqcreated myfile\*(Aq
     516.if n \{\
     520And fast forward again:
     522.if n \{\
     523.RS 4
     526$ git subtree merge \-\-prefix=gitweb \-\-squash gitweb\-latest
     528.if n \{\
     532And notice that your change is still intact:
     534.if n \{\
     535.RS 4
     538$ ls \-l gitweb/myfile
     540.if n \{\
     544And you can split it out and look at your changes versus the standard gitweb:
     546.if n \{\
     547.RS 4
     550git log gitweb\-latest\&.\&.$(git subtree split \-\-prefix=gitweb)
     552.if n \{\
     557Suppose you have a source directory with many files and subdirectories, and you want to extract the lib directory to its own git project\&. Here\(cqs a short way to do it:
     559First, make the new repository wherever you want:
     561.if n \{\
     562.RS 4
     565$ <go to the new location>
     566$ git init \-\-bare
     568.if n \{\
     572Back in your original directory:
     574.if n \{\
     575.RS 4
     578$ git subtree split \-\-prefix=lib \-\-annotate="(split)" \-b split
     580.if n \{\
     584Then push the new branch onto the new empty repository:
     586.if n \{\
     587.RS 4
     590$ git push <new\-repo> split:master
     592.if n \{\
     595.SH "AUTHOR"
     597Written by Avery Pennarun <\m[blue]\fBapenwarr@gmail\&.com\fR\m[]\&\s-2\u[1]\d\s+2>
     598.SH "GIT"
     600Part of the \fBgit\fR(1) suite
     601.SH "NOTES"
     602.IP " 1." 4
     604.RS 4
Note: See TracBrowser for help on using the repository browser.