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 <http://docbook.sf.net/>
     5.\"      Date: 03/17/2014
     6.\"    Manual: Git Manual
     7.\"    Source: Git 2.0.0
     8.\"  Language: English
     9.\"
     10.TH "GIT\-SUBTREE" "1" "03/17/2014" "Git 2\&.0\&.0" "Git Manual"
     11.\" -----------------------------------------------------------------
     12.\" * Define some portability stuff
     13.\" -----------------------------------------------------------------
     14.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     15.\" http://bugs.debian.org/507673
     16.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
     17.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     18.ie \n(.g .ds Aq \(aq
     19.el       .ds Aq '
     20.\" -----------------------------------------------------------------
     21.\" * set default formatting
     22.\" -----------------------------------------------------------------
     23.\" disable hyphenation
     24.nh
     25.\" disable justification (adjust text to left margin only)
     26.ad l
     27.\" -----------------------------------------------------------------
     28.\" * MAIN CONTENT STARTS HERE *
     29.\" -----------------------------------------------------------------
     30.SH "NAME"
     31git-subtree \- Merge subtrees together and split repository into subtrees
     32.SH "SYNOPSIS"
     33.sp
     34.nf
     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>]
     41.fi
     42.SH "DESCRIPTION"
     43.sp
     44Subtrees allow subprojects to be included within a subdirectory of the main project, optionally including the subproject\(cqs entire history\&.
     45.sp
     46For example, you could include the source code for a library as a subdirectory of your application\&.
     47.sp
     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\&.
     49.sp
     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\&.
     51.sp
     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 \{\
     54.sp
     55.\}
     56.RS 4
     57.it 1 an-trap
     58.nr an-no-space-flag 1
     59.nr an-break-flag 1
     60.br
     61.ps +1
     62\fBTip\fR
     63.ps -1
     64.br
     65.sp
     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
     68.RE
     69.SH "COMMANDS"
     70.PP
     71add
     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\&.
     75.RE
     76.PP
     77merge
     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\&.
     82.sp
     83.if n \{\
     84.RS 4
     85.\}
     86.nf
     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\&.
     92.fi
     93.if n \{\
     94.RE
     95.\}
     96.RE
     97.PP
     98pull
     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\&.
     104.RE
     105.PP
     106push
     107.RS 4
     108Does a
     109\fIsplit\fR
     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\&.
     113.RE
     114.PP
     115split
     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\&.
     118.sp
     119.if n \{\
     120.RS 4
     121.\}
     122.nf
     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
     126want\&.
     127.fi
     128.if n \{\
     129.RE
     130.\}
     131.sp
     132.if n \{\
     133.RS 4
     134.\}
     135.nf
     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\&.
     142.fi
     143.if n \{\
     144.RE
     145.\}
     146.sp
     147.if n \{\
     148.RS 4
     149.\}
     150.nf
     151Note that if you use \*(Aq\-\-squash\*(Aq when you merge, you
     152should usually not just \*(Aq\-\-rejoin\*(Aq when you split\&.
     153.fi
     154.if n \{\
     155.RE
     156.\}
     157.RE
     158.SH "OPTIONS"
     159.PP
     160\-q, \-\-quiet
     161.RS 4
     162Suppress unnecessary output messages on stderr\&.
     163.RE
     164.PP
     165\-d, \-\-debug
     166.RS 4
     167Produce even more unnecessary output messages on stderr\&.
     168.RE
     169.PP
     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\&.
     173.RE
     174.PP
     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\&.
     178.RE
     179.SH "OPTIONS FOR ADD, MERGE, PUSH, PULL"
     180.PP
     181\-\-squash
     182.RS 4
     183This option is only valid for add, merge, push and pull commands\&.
     184.sp
     185.if n \{\
     186.RS 4
     187.\}
     188.nf
     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\&.
     193.fi
     194.if n \{\
     195.RE
     196.\}
     197.sp
     198.if n \{\
     199.RS 4
     200.\}
     201.nf
     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\&.
     206.fi
     207.if n \{\
     208.RE
     209.\}
     210.sp
     211.if n \{\
     212.RS 4
     213.\}
     214.nf
     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\&.
     221.fi
     222.if n \{\
     223.RE
     224.\}
     225.sp
     226.if n \{\
     227.RS 4
     228.\}
     229.nf
     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\&.
     236.fi
     237.if n \{\
     238.RE
     239.\}
     240.sp
     241.if n \{\
     242.RS 4
     243.\}
     244.nf
     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\&.
     248.fi
     249.if n \{\
     250.RE
     251.\}
     252.RE
     253.SH "OPTIONS FOR SPLIT"
     254.PP
     255\-\-annotate=<annotation>
     256.RS 4
     257This option is only valid for the split command\&.
     258.sp
     259.if n \{\
     260.RS 4
     261.\}
     262.nf
     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\&.
     268.fi
     269.if n \{\
     270.RE
     271.\}
     272.sp
     273.if n \{\
     274.RS 4
     275.\}
     276.nf
     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\&.
     283.fi
     284.if n \{\
     285.RE
     286.\}
     287.RE
     288.PP
     289\-b <branch>, \-\-branch=<branch>
     290.RS 4
     291This option is only valid for the split command\&.
     292.sp
     293.if n \{\
     294.RS 4
     295.\}
     296.nf
     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\&.
     301.fi
     302.if n \{\
     303.RE
     304.\}
     305.RE
     306.PP
     307\-\-ignore\-joins
     308.RS 4
     309This option is only valid for the split command\&.
     310.sp
     311.if n \{\
     312.RS 4
     313.\}
     314.nf
     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\&.
     321.fi
     322.if n \{\
     323.RE
     324.\}
     325.RE
     326.PP
     327\-\-onto=<onto>
     328.RS 4
     329This option is only valid for the split command\&.
     330.sp
     331.if n \{\
     332.RS 4
     333.\}
     334.nf
     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\&.
     342.fi
     343.if n \{\
     344.RE
     345.\}
     346.sp
     347.if n \{\
     348.RS 4
     349.\}
     350.nf
     351If you used \*(Aqgit subtree add\*(Aq, you should never need
     352this option\&.
     353.fi
     354.if n \{\
     355.RE
     356.\}
     357.RE
     358.PP
     359\-\-rejoin
     360.RS 4
     361This option is only valid for the split command\&.
     362.sp
     363.if n \{\
     364.RS 4
     365.\}
     366.nf
     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\&.
     371.fi
     372.if n \{\
     373.RE
     374.\}
     375.sp
     376.if n \{\
     377.RS 4
     378.\}
     379.nf
     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
     385repository)\&.
     386.fi
     387.if n \{\
     388.RE
     389.\}
     390.sp
     391.if n \{\
     392.RS 4
     393.\}
     394.nf
     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)\&.
     398.fi
     399.if n \{\
     400.RE
     401.\}
     402.sp
     403.if n \{\
     404.RS 4
     405.\}
     406.nf
     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\&.
     410.fi
     411.if n \{\
     412.RE
     413.\}
     414.RE
     415.SH "EXAMPLE 1. ADD COMMAND"
     416.sp
     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/:
     418.sp
     419.if n \{\
     420.RS 4
     421.\}
     422.nf
     423$ git subtree add \-\-prefix=git\-subtree \-\-squash \e
     424        git://github\&.com/apenwarr/git\-subtree\&.git master
     425.fi
     426.if n \{\
     427.RE
     428.\}
     429.sp
     430\fImaster\fR needs to be a valid remote ref and can be a different branch name
     431.sp
     432You can omit the \-\-squash flag, but doing so will increase the number of commits that are included in your local repository\&.
     433.sp
     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\&.
     435.SH "EXAMPLE 2. EXTRACT A SUBTREE USING COMMIT, MERGE AND PULL"
     436.sp
     437Let\(cqs use the repository for the git source code as an example\&. First, get your own copy of the git\&.git repository:
     438.sp
     439.if n \{\
     440.RS 4
     441.\}
     442.nf
     443$ git clone git://git\&.kernel\&.org/pub/scm/git/git\&.git test\-git
     444$ cd test\-git
     445.fi
     446.if n \{\
     447.RE
     448.\}
     449.sp
     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:
     451.sp
     452.if n \{\
     453.RS 4
     454.\}
     455.nf
     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
     461.fi
     462.if n \{\
     463.RE
     464.\}
     465.sp
     466(We use \fI0a8f4f0^\&.\&.\fR because that means "all the changes from 0a8f4f0 to the current version, including 0a8f4f0 itself\&.")
     467.sp
     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:
     469.sp
     470.if n \{\
     471.RS 4
     472.\}
     473.nf
     474$ git subtree split \-\-prefix=gitweb \-\-annotate=\*(Aq(split) \*(Aq \-\-rejoin \e
     475        \-\-branch gitweb\-latest2
     476.fi
     477.if n \{\
     478.RE
     479.\}
     480.sp
     481And you can merge changes back in from the upstream project just as easily:
     482.sp
     483.if n \{\
     484.RS 4
     485.\}
     486.nf
     487$ git subtree pull \-\-prefix=gitweb \e
     488        git@github\&.com:whatever/gitweb\&.git master
     489.fi
     490.if n \{\
     491.RE
     492.\}
     493.sp
     494Or, using \fI\-\-squash\fR, you can actually rewind to an earlier version of gitweb:
     495.sp
     496.if n \{\
     497.RS 4
     498.\}
     499.nf
     500$ git subtree merge \-\-prefix=gitweb \-\-squash gitweb\-latest~10
     501.fi
     502.if n \{\
     503.RE
     504.\}
     505.sp
     506Then make some changes:
     507.sp
     508.if n \{\
     509.RS 4
     510.\}
     511.nf
     512$ date >gitweb/myfile
     513$ git add gitweb/myfile
     514$ git commit \-m \*(Aqcreated myfile\*(Aq
     515.fi
     516.if n \{\
     517.RE
     518.\}
     519.sp
     520And fast forward again:
     521.sp
     522.if n \{\
     523.RS 4
     524.\}
     525.nf
     526$ git subtree merge \-\-prefix=gitweb \-\-squash gitweb\-latest
     527.fi
     528.if n \{\
     529.RE
     530.\}
     531.sp
     532And notice that your change is still intact:
     533.sp
     534.if n \{\
     535.RS 4
     536.\}
     537.nf
     538$ ls \-l gitweb/myfile
     539.fi
     540.if n \{\
     541.RE
     542.\}
     543.sp
     544And you can split it out and look at your changes versus the standard gitweb:
     545.sp
     546.if n \{\
     547.RS 4
     548.\}
     549.nf
     550git log gitweb\-latest\&.\&.$(git subtree split \-\-prefix=gitweb)
     551.fi
     552.if n \{\
     553.RE
     554.\}
     555.SH "EXAMPLE 3. EXTRACT A SUBTREE USING BRANCH"
     556.sp
     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:
     558.sp
     559First, make the new repository wherever you want:
     560.sp
     561.if n \{\
     562.RS 4
     563.\}
     564.nf
     565$ <go to the new location>
     566$ git init \-\-bare
     567.fi
     568.if n \{\
     569.RE
     570.\}
     571.sp
     572Back in your original directory:
     573.sp
     574.if n \{\
     575.RS 4
     576.\}
     577.nf
     578$ git subtree split \-\-prefix=lib \-\-annotate="(split)" \-b split
     579.fi
     580.if n \{\
     581.RE
     582.\}
     583.sp
     584Then push the new branch onto the new empty repository:
     585.sp
     586.if n \{\
     587.RS 4
     588.\}
     589.nf
     590$ git push <new\-repo> split:master
     591.fi
     592.if n \{\
     593.RE
     594.\}
     595.SH "AUTHOR"
     596.sp
     597Written by Avery Pennarun <\m[blue]\fBapenwarr@gmail\&.com\fR\m[]\&\s-2\u[1]\d\s+2>
     598.SH "GIT"
     599.sp
     600Part of the \fBgit\fR(1) suite
     601.SH "NOTES"
     602.IP " 1." 4
     603apenwarr@gmail.com
     604.RS 4
     605\%mailto:apenwarr@gmail.com
     606.RE
Note: See TracBrowser for help on using the repository browser.