1
0
Fork 0

Indent with two spaces in zh files

converted tabs to spaces also. but these commits is limited in the zh
version.

the reason I did this:

 - long lines is prone to conflict
 - the use of tab disturbs the indentation when switching editors
   without proper tab space setting, which you may never get it right.
   so why not give up and use spaces instead.

those changes is limited to the zh translation.

Merge remote-tracking branch 'upstream/gh-pages' into gh-pages

Conflicts:
	.gitignore
	_layouts/zh_reference.html
	zh/basic/index.html
	zh/branching/index.html
	zh/creating/index.html
	zh/index.html
	zh/inspect/index.html
	zh/remotes/index.html
This commit is contained in:
dotnil 2012-11-29 20:16:37 +08:00
commit 0f4505c1e2
25 changed files with 1281 additions and 886 deletions

3
.gitignore vendored
View File

@ -1,5 +1,4 @@
_site
*~
\.*.swp
.gitignore
.*.swp
.DS_Store

105
LICENSE.md Normal file
View File

@ -0,0 +1,105 @@
# License
The prose, course text, slide layouts, class outlines, diagrams, HTML, CSS, and Markdown code in the set of educational materials located in this repository are licensed as _CC BY-NC 3.0_. The Octocat, GitHub logo and other already-copyrighted and already-reserved trademarks and images are not covered by this license.
------------------------
# Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
This is a [human-readable summary](http://creativecommons.org/licenses/by-nc-sa/3.0/) of the [Legal Code (the full license)](http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode).
## You are free:
* to Share — to copy, distribute and transmit the work
* to Remix — to adapt the work
## Under the following conditions:
* Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
* Noncommercial — You may not use this work for commercial purposes.
* Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
## With the understanding that:
* Waiver — Any of the above conditions can be waived if you get permission from the copyright holder.
* Public Domain — Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license.
* Other Rights — In no way are any of the following rights affected by the license:
* Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations;
* The author's moral rights;
* Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.
Notice — For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.
--------------------------------
# Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM ITS USE.
License
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
1. Definitions
"Adaptation" means a work based upon the Work, or upon the Work and other pre-existing works, such as a translation, adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogram or performance and includes cinematographic adaptations or any other form in which the Work may be recast, transformed, or adapted including in any form recognizably derived from the original, except that a work that constitutes a Collection will not be considered an Adaptation for the purpose of this License. For the avoidance of doubt, where the Work is a musical work, performance or phonogram, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered an Adaptation for the purpose of this License.
"Collection" means a collection of literary or artistic works, such as encyclopedias and anthologies, or performances, phonograms or broadcasts, or other works or subject matter other than works listed in Section 1(g) below, which, by reason of the selection and arrangement of their contents, constitute intellectual creations, in which the Work is included in its entirety in unmodified form along with one or more other contributions, each constituting separate and independent works in themselves, which together are assembled into a collective whole. A work that constitutes a Collection will not be considered an Adaptation (as defined above) for the purposes of this License.
"Distribute" means to make available to the public the original and copies of the Work or Adaptation, as appropriate, through sale or other transfer of ownership.
"License Elements" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, Noncommercial, ShareAlike.
"Licensor" means the individual, individuals, entity or entities that offer(s) the Work under the terms of this License.
"Original Author" means, in the case of a literary or artistic work, the individual, individuals, entity or entities who created the Work or if no individual or entity can be identified, the publisher; and in addition (i) in the case of a performance the actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram the producer being the person or legal entity who first fixes the sounds of a performance or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the broadcast.
"Work" means the literary and/or artistic work offered under the terms of this License including without limitation any production in the literary, scientific and artistic domain, whatever may be the mode or form of its expression including digital form, such as a book, pamphlet and other writing; a lecture, address, sermon or other work of the same nature; a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb show; a musical composition with or without words; a cinematographic work to which are assimilated works expressed by a process analogous to cinematography; a work of drawing, painting, architecture, sculpture, engraving or lithography; a photographic work to which are assimilated works expressed by a process analogous to photography; a work of applied art; an illustration, map, plan, sketch or three-dimensional work relative to geography, topography, architecture or science; a performance; a broadcast; a phonogram; a compilation of data to the extent it is protected as a copyrightable work; or a work performed by a variety or circus performer to the extent it is not otherwise considered a literary or artistic work.
"You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
"Publicly Perform" means to perform public recitations of the Work and to communicate to the public those public recitations, by any means or process, including by wire or wireless means or public digital performances; to make available to the public Works in such a way that members of the public may access these Works from a place and at a place individually chosen by them; to perform the Work to the public by any means or process and the communication to the public of the performances of the Work, including by public digital performance; to broadcast and rebroadcast the Work by any means including signs, sounds or images.
"Reproduce" means to make copies of the Work by any means including without limitation by sound or visual recordings and the right of fixation and reproducing fixations of the Work, including storage of a protected performance or phonogram in digital form or other electronic medium.
2. Fair Dealing Rights. Nothing in this License is intended to reduce, limit, or restrict any uses free from copyright or rights arising from limitations or exceptions that are provided for in connection with the copyright protection under copyright law or other applicable laws.
3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:
to Reproduce the Work, to incorporate the Work into one or more Collections, and to Reproduce the Work as incorporated in the Collections;
to create and Reproduce Adaptations provided that any such Adaptation, including any translation in any medium, takes reasonable steps to clearly label, demarcate or otherwise identify that changes were made to the original Work. For example, a translation could be marked "The original work was translated from English to Spanish," or a modification could indicate "The original work has been modified.";
to Distribute and Publicly Perform the Work including as incorporated in Collections; and,
to Distribute and Publicly Perform Adaptations.
The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. Subject to Section 8(f), all rights not expressly granted by Licensor are hereby reserved, including but not limited to the rights described in Section 4(e).
4. Restrictions. The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:
You may Distribute or Publicly Perform the Work only under the terms of this License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms on the Work that restrict the terms of this License or the ability of the recipient of the Work to exercise the rights granted to that recipient under the terms of the License. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Work, You may not impose any effective technological measures on the Work that restrict the ability of a recipient of the Work from You to exercise the rights granted to that recipient under the terms of the License. This Section 4(a) applies to the Work as incorporated in a Collection, but this does not require the Collection apart from the Work itself to be made subject to the terms of this License. If You create a Collection, upon notice from any Licensor You must, to the extent practicable, remove from the Collection any credit as required by Section 4(d), as requested. If You create an Adaptation, upon notice from any Licensor You must, to the extent practicable, remove from the Adaptation any credit as required by Section 4(d), as requested.
You may Distribute or Publicly Perform an Adaptation only under: (i) the terms of this License; (ii) a later version of this License with the same License Elements as this License; (iii) a Creative Commons jurisdiction license (either this or a later license version) that contains the same License Elements as this License (e.g., Attribution-NonCommercial-ShareAlike 3.0 US) ("Applicable License"). You must include a copy of, or the URI, for Applicable License with every copy of each Adaptation You Distribute or Publicly Perform. You may not offer or impose any terms on the Adaptation that restrict the terms of the Applicable License or the ability of the recipient of the Adaptation to exercise the rights granted to that recipient under the terms of the Applicable License. You must keep intact all notices that refer to the Applicable License and to the disclaimer of warranties with every copy of the Work as included in the Adaptation You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Adaptation, You may not impose any effective technological measures on the Adaptation that restrict the ability of a recipient of the Adaptation from You to exercise the rights granted to that recipient under the terms of the Applicable License. This Section 4(b) applies to the Adaptation as incorporated in a Collection, but this does not require the Collection apart from the Adaptation itself to be made subject to the terms of the Applicable License.
You may not exercise any of the rights granted to You in Section 3 above in any manner that is primarily intended for or directed toward commercial advantage or private monetary compensation. The exchange of the Work for other copyrighted works by means of digital file-sharing or otherwise shall not be considered to be intended for or directed toward commercial advantage or private monetary compensation, provided there is no payment of any monetary compensation in con-nection with the exchange of copyrighted works.
If You Distribute, or Publicly Perform the Work or any Adaptations or Collections, You must, unless a request has been made pursuant to Section 4(a), keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing entity, journal) for attribution ("Attribution Parties") in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; (ii) the title of the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and, (iv) consistent with Section 3(b), in the case of an Adaptation, a credit identifying the use of the Work in the Adaptation (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). The credit required by this Section 4(d) may be implemented in any reasonable manner; provided, however, that in the case of a Adaptation or Collection, at a minimum such credit will appear, if a credit for all contributing authors of the Adaptation or Collection appears, then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors. For the avoidance of doubt, You may only use the credit required by this Section for the purpose of attribution in the manner set out above and, by exercising Your rights under this License, You may not implicitly or explicitly assert or imply any connection with, sponsorship or endorsement by the Original Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the Work, without the separate, express prior written permission of the Original Author, Licensor and/or Attribution Parties.
For the avoidance of doubt:
Non-waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme cannot be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License;
Waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme can be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License if Your exercise of such rights is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(c) and otherwise waives the right to collect royalties through any statutory or compulsory licensing scheme; and,
Voluntary License Schemes. The Licensor reserves the right to collect royalties, whether individually or, in the event that the Licensor is a member of a collecting society that administers voluntary licensing schemes, via that society, from any exercise by You of the rights granted under this License that is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(c).
Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or Collections, You must not distort, mutilate, modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author's honor or reputation. Licensor agrees that in those jurisdictions (e.g. Japan), in which any exercise of the right granted in Section 3(b) of this License (the right to make Adaptations) would be deemed to be a distortion, mutilation, modification or other derogatory action prejudicial to the Original Author's honor and reputation, the Licensor will waive or not assert, as appropriate, this Section, to the fullest extent permitted by the applicable national law, to enable You to reasonably exercise Your right under Section 3(b) of this License (right to make Adaptations) but not otherwise.
5. Representations, Warranties and Disclaimer
UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING AND TO THE FULLEST EXTENT PERMITTED BY APPLICABLE LAW, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO THIS EXCLUSION MAY NOT APPLY TO YOU.
6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
7. Termination
This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Adaptations or Collections from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.
8. Miscellaneous
Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
Each time You Distribute or Publicly Perform an Adaptation, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.
The rights granted under, and the subject matter referenced, in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction in which the License terms are sought to be enforced according to the corresponding provisions of the implementation of those treaty provisions in the applicable national law. If the standard suite of rights granted under applicable copyright law includes additional rights not granted under this License, such additional rights are deemed to be included in the License; this License is not intended to restrict the license of any rights under applicable law.
Creative Commons Notice
Creative Commons is not a party to this License, and makes no warranty whatsoever in connection with the Work. Creative Commons will not be liable to You or any party on any legal theory for any damages whatsoever, including without limitation any general, special, incidental or consequential damages arising in connection to this license. Notwithstanding the foregoing two (2) sentences, if Creative Commons has expressly identified itself as the Licensor hereunder, it shall have all rights and obligations of Licensor.
Except for the limited purpose of indicating to the public that the Work is licensed under the CCPL, Creative Commons does not authorize the use by either party of the trademark "Creative Commons" or any related trademark or logo of Creative Commons without the prior written consent of Creative Commons. Any permitted use will be in compliance with Creative Commons' then-current trademark usage guidelines, as may be published on its website or otherwise made available upon request from time to time. For the avoidance of doubt, this trademark restriction does not form part of this License.
Creative Commons may be contacted at http://creativecommons.org/.

2
NOTES
View File

@ -1,7 +1,7 @@
Introduction
(how git is different)
Getting and Creating Projects
Getting & Creating Projects
* init
* clone

View File

@ -27,7 +27,7 @@
<!-- <li><a id="menu_cookbook" href="/cookbook.html">Cookbook</a></li> -->
<li><a id="menu_about" href="/about.html">About</a></li>
<li>&#167;</li>
<li><a href="http://github.com/schacon/git-reference">Site Source</a></li>
<li><a href="http://github.com/github/git-reference">Site Source</a></li>
</ul>
<br/>
&nbsp;

View File

@ -8,8 +8,8 @@
<link rel="stylesheet" type="text/css" href="/css/grid.css" media="screen" />
<link rel="stylesheet" type="text/css" href="/css/layout.css" media="screen" />
<link rel="stylesheet" type="text/css" href="/css/nav.css" media="screen" />
<!--[if IE 6]><link rel="stylesheet" type="text/css" href="/zh//css/ie6.css" media="screen" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" type="text/css" href="/zh//css/ie.css" media="screen" /><![endif]-->
<!--[if IE 6]><link rel="stylesheet" type="text/css" href="/css/ie6.css" media="screen" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" type="text/css" href="/css/ie.css" media="screen" /><![endif]-->
<script type="text/javascript" src="/js/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="/js/action.js"></script>
@ -27,7 +27,7 @@
<!-- <li><a id="menu_cookbook" href="/zh/cookbook.html">Cookbook</a></li> -->
<li><a id="menu_about" href="/zh/about.html">关于</a></li>
<li>&#167;</li>
<li><a href="https://github.com/schacon/git-reference">网站源码</a></li>
<li><a href="http://github.com/github/git-reference">网站源码</a></li>
</ul>
<br/>
&nbsp;

View File

@ -38,7 +38,7 @@ layout: reference
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-add.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-add">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-2.html#tracking_new_files">book</a>
</span>
<a name="add">git add</a>
@ -130,7 +130,7 @@ layout: reference
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-status.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-status">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-2.html#checking_the_status_of_your_files">book</a>
</span>
<a name="status">git status</a>
@ -214,7 +214,7 @@ layout: reference
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-diff.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-diff">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-2.html#viewing_your_staged_and_unstaged_changes">book</a>
</span>
<a name="diff">git diff</a>
@ -416,7 +416,7 @@ index 2aabb6e..2ae9ba4 100644
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-commit.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-commit">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-2.html#committing_your_changes">book</a>
</span>
<a name="commit">git commit</a>
@ -596,7 +596,7 @@ Further paragraphs come after blank lines.
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-reset.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-reset">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-4.html#unstaging_a_staged_file">book</a>
</span>
<a name="reset">git reset HEAD</a>
@ -694,7 +694,7 @@ M hello.rb
<div class="box">
<h2>
<span class="docs">
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-rm.html">docs</a> &nbsp;
<a href="http://git-scm.com/docs/git-rm">docs</a> &nbsp;
<a href="http://progit.org/book/ch2-2.html#removing_files">book</a>
</span>
<a name="rm-mv">git rm</a>
@ -747,5 +747,5 @@ M hello.rb
</div>
</div>
<p><a href="/branching">On to Branching and Merging &#187;</a></p>
<p><a class="page-button next-page" href="/branching">On to Branching and Merging &#187;</a></p>

View File

@ -38,7 +38,7 @@ layout: reference
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-branch.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-branch">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch3-2.html">book</a>
</span>
<a name="branch">git branch</a>
@ -49,7 +49,7 @@ layout: reference
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-checkout.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-checkout">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch3-2.html">book</a>
</span>
<a name="checkout">git checkout</a>
@ -226,7 +226,7 @@ Deleted branch testing (was 78b2670).
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-merge">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch3-2.html#basic_merging">book</a>
</span>
<a name="merge">git merge</a>
@ -292,7 +292,6 @@ HelloWorld.hello
<pre>
<b>$ git checkout -b change_class</b>
M hello.rb
Switched to a new branch 'change_class'
<b>$ vim hello.rb </b>
<b>$ head -1 hello.rb </b>
@ -421,7 +420,7 @@ nearly every programming language.
<p>You can see that Git inserts standard merge conflict markers, much like
Subversion, into files when it gets a merge conflict. Now it's up to us
to resolve them. We will do it manually here, but check out
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html">git mergetool</a>
<a href="http://git-scm.com/docs/git-mergetool">git mergetool</a>
if you want Git to fire up a graphical mergetool
(like kdiff3, emerge, p4merge, etc) instead.
</p>
@ -473,7 +472,7 @@ M README
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-log.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-log">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch6-1.html#commit_ranges">book</a>
</span>
<a name="log">git log</a>
@ -665,6 +664,9 @@ b7ae93b added from ruby
front of the branch that we don't want to see. For instance, if we want
to see the commits that are in the 'erlang' branch that are not in the
'master' branch, we can do <code>erlang ^master</code>, or vice versa.
Note that the Windows command-line treats <code>^</code> as a special
character, in which case you'll need to surround <code>^master</code>
in quotes.
</p>
<pre>
@ -693,7 +695,7 @@ ab5ab4c added erlang
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-tag.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-tag">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-6.html">book</a>
</span>
<a name="tag">git tag</a>
@ -775,5 +777,5 @@ ab5ab4c added erlang
</div>
</div>
<p><a href="/remotes">On to Sharing and Updating Projects &#187;</a></p>
<p><a class="page-button next-page" href="/remotes">On to Sharing and Updating Projects &#187;</a></p>

View File

@ -23,7 +23,7 @@ layout: reference
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-init.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-init">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-1.html#initializing_a_repository_in_an_existing_directory">book</a>
</span>
<a name="init">git init</a>
@ -74,7 +74,7 @@ Initialized empty Git repository in /opt/konichiwa/.git/
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-clone.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-clone">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-1.html#cloning_an_existing_repository">book</a>
</span>
<a name="clone">git clone</a>
@ -134,4 +134,4 @@ config index <span class="blue">objects</span>
</div>
</div>
<p><a href="/basic">On to Basic Snapshotting &#187;</a></p>
<p><a class="page-button next-page" href="/basic">On to Basic Snapshotting &#187;</a></p>

0
css/960.css Executable file → Normal file
View File

0
css/grid.css Executable file → Normal file
View File

0
css/ie.css Executable file → Normal file
View File

0
css/ie6.css Executable file → Normal file
View File

77
css/layout.css Executable file → Normal file
View File

@ -3,17 +3,18 @@
Grey Box Method - Layout CSS
----------------------------------------------- */
body {
html, body {
border-top: 5px solid #000;
color: #333;
padding: 0 0 40px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#about_me img { border: 5px solid #333; margin: 3px; }
.info { background: #fff; padding: 10px;}
.article { border-bottom: 5px solid #c9182f; padding-bottom: 10px; margin-bottom: 15px;}
.article { border-bottom: 5px solid rgb(20,120,200); padding-bottom: 10px; margin-bottom: 15px;}
.non_home_box {
display: none;
@ -24,7 +25,7 @@ body {
background: #fff;
}
#reflist h3 a {
color: #c9182f;
color: rgb(20,120,200);
}
#reflist h4 { font-size: 0.9em; }
#reflist .block { margin: 0; padding: 0; }
@ -45,7 +46,7 @@ p.nutshell {
.box code.code {
white-space:pre;
font-family:monospace;
font-family: Consolas, 'Liberation Mono', Courier, monospace;
padding: 8px;
background: #ffe;
display: block;
@ -62,7 +63,7 @@ pre b { color: #111; }
.hl { background: #eea; }
.box h4 {
font-family:monospace;
font-family: Consolas, 'Liberation Mono', Courier, monospace;
margin-top: 20px;
color: #833;
}
@ -87,7 +88,7 @@ pre b { color: #111; }
}
ul#menu {
background: #c9182f;
background: rgb(20,120,200);
padding: .5em;
display: inline;
color: #fff;
@ -99,7 +100,6 @@ ul#menu li {
padding-right: 10px;
padding-left: 10px;
display:inline;
font-family: "inconsolata-1","inconsolata-2";
font-size: 1.1em;
}
@ -123,6 +123,65 @@ a {
a:hover {
color:#333;
}
a.page-button {
background: #e4eafa none 0 0 repeat-x;
border: solid 1px #c9172e;
color: #c9172e;
cursor: pointer;
display: inline-block;
font-weight: bold;
font-size: 12px;
line-height: 100%;
margin: 1px;
padding: 0.8em 1em;
position: relative;
text-decoration: none;
text-shadow: #fff 0 1px 0;
vertical-align: middle;
white-space: nowrap;
float:right;
background-image: -moz-linear-gradient(-90deg,
#eeeeee 1%,
#fdf6f7 5%,
#fae9eb 70%,
#f7dcdf 100%);
background-image: -webkit-gradient(linear,left top,left bottom,
color-stop(0.01, #eee),
color-stop(0.05, #fdf6f7),
color-stop(0.70, #fae9eb),
color-stop(1, #f7dcdf));
}
a.next-page {
border-right: none;
margin-right: 26px;
padding-right: 0;
}
a.next-page:after, a.prev-page:after {
border: solid 1px #c9172e;
content: '';
display: block;
position: absolute;
top: .37em;
width: 1.7em;
height: 1.7em;
text-shadow: none;
z-index: -1;
}
a.next-page:after {
right: -.97em;
-moz-transform: rotate(-45deg);
background-image: -moz-linear-gradient(-135deg,
#eeeeee 1%,
#fdf6f7 5%,
#fae9eb 70%,
#f7dcdf 100%);
-webkit-transform:rotate(-45deg);
background-image: -webkit-gradient(linear,100% 0%, 0% 100%,
color-stop(0.01, #eee),
color-stop(0.05, #fdf6f7),
color-stop(0.70, #fae9eb),
color-stop(1, #f7dcdf));
}
/* headings
----------------------------------------------- */
@ -130,7 +189,7 @@ h1, h2, h3, h4, h5, h6 {line-height:1.2em; margin-bottom:.3em;}
h2 {margin-top:1em; }
h5 {font-size:1.2em;}
h6 {font-size:1em; text-transform:uppercase;}
h3 { color: #c9182f; }
h3 { color: rgb(20,120,200); }
h1 a {
font-weight:normal;
@ -239,7 +298,7 @@ p {
margin-bottom:1em;
}
blockquote {
font-family: "inconsolata-1","inconsolata-2";
font-family: Consolas, 'Liberation Mono', Courier, monospace;
padding-left:1em;
border-left:4px solid #ccc;
}

0
css/nav.css Executable file → Normal file
View File

0
css/reset.css Executable file → Normal file
View File

0
css/text.css Executable file → Normal file
View File

View File

@ -15,7 +15,7 @@ layout: reference
<p>
Each section will link to the next section, so it can be used
as a tutorial. Every page will also link to more in-depth
Git documentation such as the offical manual pages and relevant
Git documentation such as the official manual pages and relevant
sections in the <a href="http://progit.org">Pro Git book</a>,
so you can learn more about any of
the commands. First, we'll start with thinking about source code
@ -28,7 +28,7 @@ layout: reference
<h2>How to Think Like Git</h2>
<div class="block">
<p>
This first thing that is important to understand about Git is
The first thing that is important to understand about Git is
that it thinks about version control very differently than
Subversion or Perforce or whatever SCM you may be used to. It
is often easier to learn Git by trying to forget your assumptions
@ -109,4 +109,4 @@ layout: reference
</div>
</div>
<p><a href="/creating">On to Getting and Creating Projects &#187;</a></p>
<p><a class="page-button next-page" href="/creating">On to Getting and Creating Projects &#187;</a></p>

View File

@ -30,7 +30,7 @@ layout: reference
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-log.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-log">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-3.html">book</a>
</span>
<a name="log">git log</a>
@ -73,7 +73,7 @@ b532581 make "git unpack-file" a built-in
<h4>
git log --since --before
<small>filter commits by date authored</small>
<small>filter commits by date committed</small>
</h4>
<p>
@ -309,7 +309,7 @@ Date: Fri Jun 4 12:58:53 2010 +0200
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-diff.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-diff">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch5-3.html#determining_what_is_introduced">book</a>
</span>
<a name="diff">git diff</a>

View File

@ -43,7 +43,7 @@ layout: reference
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-remote.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-remote">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-5.html#showing_your_remotes">book</a>
</span>
<a name="remote">git remote</a>
@ -80,8 +80,8 @@ layout: reference
<b>$ git remote</b>
origin
<b>$ git remote -v</b>
origin git@github.com:schacon/git-reference.git (fetch)
origin git@github.com:schacon/git-reference.git (push)
origin git@github.com:github/git-reference.git (fetch)
origin git@github.com:github/git-reference.git (push)
</pre>
<p>You see the URL there twice because Git allows you to have different
@ -94,7 +94,7 @@ origin git@github.com:schacon/git-reference.git (push)
</h4>
<p>If you want to share a locally created repository, or you want to take
contributions from someone elses repository - if you want to interact in
contributions from someone else's repository - if you want to interact in
any way with a new repository, it's generally easiest to add it as a remote.
You do that by running <code>git remote add [alias] [url]</code>. That
adds <code>[url]</code> under a local remote named <code>[alias]</code>.</p>
@ -159,7 +159,7 @@ github git@github.com:schacon/hw.git (push)
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-fetch">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-5.html#fetching_and_pulling_from_your_remotes">book</a>
</span>
<a name="fetch">git fetch</a>
@ -170,7 +170,7 @@ github git@github.com:schacon/hw.git (push)
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-pull.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-pull">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/">book</a>
</span>
<a name="pull">git pull</a>
@ -193,9 +193,9 @@ github git@github.com:schacon/hw.git (push)
immediately followed by a <code>git merge</code> of the branch on that remote
that is tracked by whatever branch you are currently in. I personally don't much
like this command - I prefer running <code>fetch</code> and <code>merge</code>
seperately. Less magic, less problems. However, if you like this idea, you
separately. Less magic, less problems. However, if you like this idea, you
can read about it in more detail in the
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-pull.html">official docs</a>.
<a target="new" href="http://git-scm.com/docs/git-pull">official docs</a>.
</p>
<p>Assuming you have a remote all set up and you want to pull in updates, you
@ -254,7 +254,7 @@ From github.com:schacon/hw
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-push.html">docs</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-push">docs</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-5.html#pushing_to_your_remotes">book</a>
</span>
<a name="push">git push</a>
@ -340,4 +340,4 @@ fast-forwards' section of 'git push --help' for details.
</div>
</div>
<p><a href="/inspect">On to Inspection and Comparison &#187;</a></p>
<p><a class="page-button next-page" href="/inspect">On to Inspection and Comparison &#187;</a></p>

View File

@ -7,11 +7,11 @@ layout: zh_reference
<span class="docs">
<a target="new" href="http://progit.org/book/ch2-2.html"></a>
</span>
基本快照
基本快照
</h2>
<div class="block">
<p>
Git 的所有工作就是创建与保存你的项目的快照以及之后的快照对比等工作。本章将对有关创建与提交你的项目的快照的命令作介绍。
Git 的工作就是创建和保存你的项目的快照及与之后的快照进行对比。本章将对有关创建与提交你的项目的快照的命令作介绍。
</p>
<p>
@ -19,7 +19,9 @@ layout: zh_reference
</p>
<p class="nutshell">
<strong>一言以蔽之</strong>,使用 <code>git add</code> 添加需要追踪的新文件和待提交的更改,然后使用 <code>git status</code><code>git diff</code> 查看有何改动,最后用 <code>git commit</code> 将你的快照记录。这就是你要用的基本流程,绝大部分时候都是这样的。
<strong>简而言之</strong>,使用 <code>git add</code> 添加需要追踪的新文件和待提交的更改,
然后使用 <code>git status</code><code>git diff</code> 查看有何改动,
最后用 <code>git commit</code> 将你的快照记录。这就是你要用的基本流程,绝大部分时候都是这样的。
</p>
</div>
@ -37,10 +39,13 @@ layout: zh_reference
<div class="block">
<p>
在 Git 中,在提交你修改的文件之前,你需要把它们添加到缓存。如果该文件是新的,你可以执行 <code>git add</code> 将该文件添加到缓存,但是,即使该文件已经被追踪了 —— 也就是说,曾经提交过了 —— 你仍然需要执行 <cpde>git add</code> 将新更改的文件添加到缓存去。让我们看几个例子:
在 Git 中,在提交你修改的文件之前,你需要把它们添加到缓存。如果该文件是新创建的,你可以执行
<code>git add</code> 将该文件添加到缓存,但是,即使该文件已经被追踪了 —— 也就是说,曾经提交过了 ——
你仍然需要执行 <cpde>git add</code> 将新更改的文件添加到缓存去。让我们看几个例子:
</p>
<p>回到我们的 Hello World 示例,初始化该项目之后,我们就要用 <code>git add</code> 将我们的文件添加进去了。我们可以用 <code>git status</code> 看看我们的项目的当前状态。
<p>回到我们的 Hello World 示例,初始化该项目之后,我们就要用 <code>git add</code> 将我们的文件添加进去了。
我们可以用 <code>git status</code> 看看我们的项目的当前状态。
</p>
<pre>
@ -49,13 +54,13 @@ layout: zh_reference
<span class="red">??</span> hello.rb
</pre>
我们有俩尚未被追踪的文件,得添加一下。
<p>我们有俩尚未被追踪的文件,得添加一下。</p>
<pre>
<b>$ git add README hello.rb</b>
</pre>
现在我们再执行 <code>git status</code>,就可以看到这俩文件已经加上去了。
<p>现在我们再执行 <code>git status</code>,就可以看到这俩文件已经加上去了。</p>
<pre>
<b>$ git status -s</b>
@ -64,7 +69,11 @@ layout: zh_reference
</pre>
<p class="aside">
新项目中,添加所有文件很普遍,可以在当前工作目录执行命令:<code>git add .</code>。因为 Git 会递归地将你执行命令时所在的目录中的所有文件添加上去,所以如果你将当前的工作目录作为参数,它就会追踪那儿的所有文件了。如此,<code>git add .</code> 就和 <code>git add README hello.rb</code> 有一样的效果。此外,效果一致的还有 <code>git add *</code>,不过那只是因为我们这还木有子目录,不需要递归地添加新文件。
新项目中,添加所有文件很普遍,可以在当前工作目录执行命令:<code>git add .</code>
因为 Git 会递归地将你执行命令时所在的目录中的所有文件添加上去,所以如果你将当前的工作目录作为参数,
它就会追踪那儿的所有文件了。如此,<code>git add .</code> 就和 <code>git add README hello.rb</code>
有一样的效果。
此外,效果一致的还有 <code>git add *</code>,不过那只是因为我们这还木有子目录,不需要递归地添加新文件。
</p>
<p>好了,现在我们改个文件,再跑一下 <code>git status</code>,有点古怪。</p>
@ -75,13 +84,15 @@ layout: zh_reference
<span class="green">A</span> hello.rb
</pre>
<p>
“AM” 状态的意思是,这个文件在我们将它添加到缓存之后又有改动。这意味着如果我们现在提交快照,我们记录的将是上次跑 <code>git add</code> 的时候的文件版本而不是现在在磁盘中的这个。Git 并不认为磁盘中的文件与你想快照的文件必须是一致的 —— (如果你需要它们一致,)得用 <code>git add</code> 命令告诉它。
<p>“AM” 状态的意思是,这个文件在我们将它添加到缓存之后又有改动。这意味着如果我们现在提交快照,
我们记录的将是上次跑 <code>git add</code> 的时候的文件版本,而不是现在在磁盘中的这个。
Git 并不认为磁盘中的文件与你想快照的文件必须是一致的 —— (如果你需要它们一致,)得用 <code>git add</code> 命令告诉它。
</p>
<p class="nutshell">
<strong>一言以蔽之</strong>
当你要将你的修改包含在即将提交的快照里的时候,执行 <code>git add</code>。任何你没有添加的改动都不会被包含在内 —— 这意味着你可以比绝大多数其他源代码版本控制系统更精确地归置你的快照。
当你要将你的修改包含在即将提交的快照里的时候,执行 <code>git add</code>
任何你没有添加的改动都不会被包含在内 —— 这意味着你可以比绝大多数其他源代码版本控制系统更精确地归置你的快照。
</p>
<p>请查看《Pro Git》中 <code>git add</code> 的 “-p” 参数,以了解更多关于提交文件的灵活性的例子。
@ -102,7 +113,10 @@ layout: zh_reference
</h2>
<div class="block">
<p>正如你在 <code>git add</code> 小节中所看到的,你可以执行 <code>git status</code> 命令查看你的代码在缓存与当前工作目录的状态。我演示该命令的时候加了 <code>-s</code> 参数,以获得简短的结果输出。若没有这个标记,命令 <code>git status</code> 将告诉你更多的提示与上下文欣喜。以下便是同样状态下,有跟没有 <code>-s</code> 参数的输出对比。简短的输出如下:
<p>正如你在 <code>git add</code> 小节中所看到的,你可以执行 <code>git status</code>
命令查看你的代码在缓存与当前工作目录的状态。我演示该命令的时候加了 <code>-s</code> 参数,以获得简短的结果输出。
若没有这个标记,命令 <code>git status</code> 将告诉你更多的提示与上下文欣喜。
以下便是同样状态下,有跟没有 <code>-s</code> 参数的输出对比。简短的输出如下:
</p>
<pre>
@ -111,7 +125,7 @@ layout: zh_reference
<span class="green">A</span> hello.rb
</pre>
而同样的状态,详细的输出看起来是这样的:
<p>而同样的状态,详细的输出看起来是这样的:</p>
<pre>
<b>$ git status</b>
@ -144,7 +158,8 @@ layout: zh_reference
<span class="red">D</span> hello.rb
</pre>
你可以看到,在简短输出中,有两栏。第一栏是缓存的,第二栏则是工作目录的。所以假设你临时提交了 README 文件,然后又改了些,并且没有执行 <code>git add</code>,你会看到这个:
<p>你可以看到,在简短输出中,有两栏。第一栏是缓存的,第二栏则是工作目录的。
所以假设你临时提交了 README 文件,然后又改了些,并且没有执行 <code>git add</code>,你会看到这个:</p>
<pre>
<b>$ git status -s</b>
@ -153,7 +168,8 @@ layout: zh_reference
</pre>
<p class="nutshell">
<strong>一言以蔽之</strong>,执行 <code>git status</code> 以查看在你上次提交之后有啥被修改或者临时提交了,从而决定自己是否需要提交一次快照,同时也能知道有什么改变被记录进去了。
<strong>一言以蔽之</strong>,执行 <code>git status</code> 以查看在你上次提交之后有啥被修改或者临时提交了,
从而决定自己是否需要提交一次快照,同时也能知道有什么改变被记录进去了。
</p>
</div>
@ -170,7 +186,9 @@ layout: zh_reference
</h2>
<div class="block">
<p><code>git diff</code> 有两个主要的应用场景。我们将在此介绍其一,在 <a href="/inspect">检阅与对照</a> 一章中,我们将介绍其二。我们这里介绍的方式是用此命令描述已临时提交的或者已修改但尚未提交的改动。
<p><code>git diff</code> 有两个主要的应用场景。我们将在此介绍其一,
<a href="/inspect">检阅与对照</a> 一章中,我们将介绍其二。
我们这里介绍的方式是用此命令描述已临时提交的或者已修改但尚未提交的改动。
</p>
<h4>
@ -201,7 +219,9 @@ index d62ac43..8d15d50 100644
end
</pre>
<p>所以,<code>git status</code>显示你上次提交更新至后所更改或者写入缓存的改动,而 <code>git diff</code> 一行一行地显示这些改动具体是啥。通常执行完 <code>git status</code> 之后接着跑一下 <code>git diff</code> 是个好习惯。
<p>所以,<code>git status</code>显示你上次提交更新至后所更改或者写入缓存的改动,
<code>git diff</code> 一行一行地显示这些改动具体是啥。
通常执行完 <code>git status</code> 之后接着跑一下 <code>git diff</code> 是个好习惯。
</p>
<h4>
@ -209,7 +229,9 @@ index d62ac43..8d15d50 100644
<small>#查看已缓存的改动</small>
</h4>
<p><code>git diff --cached</code> 命令会告诉你有哪些内容已经写入缓存了。也就是说,此命令显示的是接下来要写入快照的内容。所以,如果你将上述示例中的 <code>hello.rb</code> 写入缓存,因为 <code>git diff</code> 显示的是尚未缓存的改动,所以在此执行它不会显示任何信息。
<p><code>git diff --cached</code> 命令会告诉你有哪些内容已经写入缓存了。
也就是说,此命令显示的是接下来要写入快照的内容。所以,如果你将上述示例中的 <code>hello.rb</code>
写入缓存,因为 <code>git diff</code> 显示的是尚未缓存的改动,所以在此执行它不会显示任何信息。
</p>
<pre>
@ -251,7 +273,10 @@ index d62ac43..8d15d50 100644
<small>查看已缓存的与未缓存的所有改动</small>
</h4>
<p>如果你想一并查看已缓存的与未缓存的改动,可以执行 <code>git diff HEAD</code> ——也就是说你要看到的是工作目录与上一次提交的更新的区别,无视缓存。假设我们又改了些 <code>ruby.rb</code> 的内容,那缓存的与未缓存的改动我们就都有了。以上三个 <code>diff</code> 命令的结果如下:
<p>如果你想一并查看已缓存的与未缓存的改动,可以执行 <code>git diff HEAD</code> ——
也就是说你要看到的是工作目录与上一次提交的更新的区别,无视缓存。
假设我们又改了些 <code>ruby.rb</code> 的内容,那缓存的与未缓存的改动我们就都有了。
以上三个 <code>diff</code> 命令的结果如下:
</p>
<pre>
<b>$ vim hello.rb </b>
@ -305,7 +330,8 @@ index 2aabb6e..2ae9ba4 100644
<small>显示摘要而非整个 diff</small>
</h4>
<p>如果我们不想要看整个 diff 输出,但是又想比 <code>git status</code> 详细点,就可以用 <code>--stat</code> 选项。该选项使它显示摘要而非全文。上文示例在使用 <code>--stat</code> 选项时,输出如下:
<p>如果我们不想要看整个 diff 输出,但是又想比 <code>git status</code> 详细点,
就可以用 <code>--stat</code> 选项。该选项使它显示摘要而非全文。上文示例在使用 <code>--stat</code> 选项时,输出如下:
</p>
<pre>
@ -327,8 +353,9 @@ index 2aabb6e..2ae9ba4 100644
<p class="nutshell">
<strong>一言以蔽之</strong>
执行 <code>git diff</code> 来查看执行 <code>git status</code> 的结果的详细信息 —— 一行一行地显示这些文件是如何被修改或写入缓存的。
<strong>简而言之</strong>
执行 <code>git diff</code> 来查看执行 <code>git status</code> 的结果的详细信息 ——
一行一行地显示这些文件是如何被修改或写入缓存的。
</p>
</div>
@ -346,7 +373,9 @@ index 2aabb6e..2ae9ba4 100644
<div class="block">
<p>现在你使用 <code>git add</code> 命令将想要快照的内容写入了缓存,执行 <code> git commit</code> 就将它实际存储快照了。Git 为你的每一个提交都记录你的名字与电子邮箱地址,所以第一步是告诉 Git 这些都是啥。
<p>现在你使用 <code>git add</code> 命令将想要快照的内容写入了缓存,
执行 <code> git commit</code> 就将它实际存储快照了。
Git 为你的每一个提交都记录你的名字与电子邮箱地址,所以第一步是告诉 Git 这些都是啥。
</p>
<pre>
@ -366,7 +395,8 @@ index 2aabb6e..2ae9ba4 100644
1 files changed, 2 insertions(+), 1 deletions(-)
</pre>
<p>现在我们已经记录了快照。如果我们再执行 <code>git status</code>,会看到我们有一个“干净的工作目录”。这意味着我们在最近一次提交之后,没有做任何改动 —— 在我们的项目中没有未快照的工作。
<p>现在我们已经记录了快照。如果我们再执行 <code>git status</code>,会看到我们有一个“干净的工作目录”。
这意味着我们在最近一次提交之后,没有做任何改动 —— 在我们的项目中没有未快照的工作。
</p>
<pre>
@ -375,7 +405,8 @@ index 2aabb6e..2ae9ba4 100644
nothing to commit (working directory clean)
</pre>
<p>如果你漏掉了 <code>-m</code> 选项Git 会尝试为你打开一个编辑器以填写提交信息。如果 Git 在你对它的配置中找不到相关信息,默认会打开 <code>vim</code>。屏幕会像这样:
<p>如果你漏掉了 <code>-m</code> 选项Git 会尝试为你打开一个编辑器以填写提交信息。
如果 Git 在你对它的配置中找不到相关信息,默认会打开 <code>vim</code>。屏幕会像这样:
</p>
<pre>
@ -429,7 +460,10 @@ nothing to commit (working directory clean)
</pre>
<p class="aside">
提交注解是很重要的。因为 Git 很大一部分能耐就是它在组织本地提交和与他人分享的弹性,它很给力地能够让你为逻辑独立的改变写三到四条提交注解,以便你的工作被同仁审阅。因为提交与推送改动是有区别的,请务必花时间将各个逻辑独立的改动放到另外一个提交,并附上一份良好的提交注解,以使与你合作的人能够方便地了解你所做的,以及你为何要这么做。
提交注解是很重要的。因为 Git 很大一部分能耐就是它在组织本地提交和与他人分享的弹性,
它很给力地能够让你为逻辑独立的改变写三到四条提交注解,以便你的工作被同仁审阅。因为提交与推送改动是有区别的,
请务必花时间将各个逻辑独立的改动放到另外一个提交,并附上一份良好的提交注解,
以使与你合作的人能够方便地了解你所做的,以及你为何要这么做。
</p>
<h4>
@ -437,7 +471,11 @@ nothing to commit (working directory clean)
<small>自动将在提交前将已记录、修改的文件放入缓存区</small>
</h4>
<p>如果你觉得 <code>git add</code> 提交缓存的流程太过繁琐Git 也允许你用 <code>-a</code> 选项跳过这一步。基本上这句话的意思就是,为任何已有记录的文件执行 <code>git add</code> —— 也就是说,任何在你最近的提交中已经存在,并且之后被修改的文件。这让你能够用更 Subversion 方式的流程,修改些文件,然后想要快照所有所做的改动的时候执行 <code>git commit -a</code>。不过你仍然需要执行 <code>git add</code> 来添加新文件,就像 Subversion 一样。
<p>如果你觉得 <code>git add</code> 提交缓存的流程太过繁琐Git 也允许你用 <code>-a</code> 选项跳过这一步。
基本上这句话的意思就是,为任何已有记录的文件执行 <code>git add</code> ——
也就是说,任何在你最近的提交中已经存在,并且之后被修改的文件。
这让你能够用更 Subversion 方式的流程,修改些文件,然后想要快照所有所做的改动的时候执行 <code>git commit -a</code>
不过你仍然需要执行 <code>git add</code> 来添加新文件,就像 Subversion 一样。
</p>
<pre>
@ -458,15 +496,18 @@ nothing to commit (working directory clean)
1 files changed, 2 insertions(+), 1 deletions(-)
</pre>
<p>注意,如果你不缓存改动,直接执行 <code>git commit</code>Git 会直接给出 <code>git status</code> 命令的输出,提醒你啥也没缓存。我已将该消息中的重要部分高亮,它说没有添加需要提交的缓存。如果你使用 <code>-a</code>,它会缓存并提交每个改动(不含新文件)。
<p>注意,如果你不缓存改动,直接执行 <code>git commit</code>Git 会直接给出 <code>git status</code>
命令的输出,提醒你啥也没缓存。我已将该消息中的重要部分高亮,它说没有添加需要提交的缓存。
如果你使用 <code>-a</code>,它会缓存并提交每个改动(不含新文件)。
</p>
<p>
现在你就完成了整个快照的流程 ——改些文件,然后用 <code>git add</code> 将要提交的改动提交到缓存,用 <code>git status</code><code>git diff</code> 看看你都改了啥,最后 <code>git commit</code> 永久地保存快照。
现在你就完成了整个快照的流程 ——改些文件,然后用 <code>git add</code> 将要提交的改动提交到缓存,
<code>git status</code><code>git diff</code> 看看你都改了啥,最后 <code>git commit</code> 永久地保存快照。
</p>
<p class="nutshell">
<strong>一言以蔽</strong>,执行 <code>git commit</code> 记录缓存区的快照。这个快照就可以用来做比较、分享以及,如果需要,恢复。
<strong>简而言</strong>,执行 <code>git commit</code> 记录缓存区的快照。如果需要的话,这个快照可以用来做比较、共享以及恢复。
</p>
</div>
@ -483,14 +524,19 @@ nothing to commit (working directory clean)
</h2>
<div class="block">
<p><code>git reset</code> 可能是人类写的最费解的命令了。我用 Git 有些年头了,甚至还写了本书,但有的时候还是会搞不清它会做什么。所以,我只说三个明确的,通常有用的调用。请你跟我一样尽管用它 —— 因为它可以很有用。
<p><code>git reset</code> 可能是人类写的最费解的命令了。
我用 Git 有些年头了,甚至还写了本书,但有的时候还是会搞不清它会做什么。
所以,我只说三个明确的,通常有用的调用。请你跟我一样尽管用它 —— 因为它可以很有用。
</p>
<p>在此例中,我们可以用它来将不小心缓存的东东取消缓存。假设你修改了两个文件,想要将它们记录到两个不同的提交中去。你应该缓存并提交一个,再缓存并提交另外一个。如果你不小心两个都缓存了,那要如何才能<i>取消</i>缓存呢?你可以用 <code>git reset HEAD -- file</code>。技术上说,在这里你不需要使用 <code>--</code> —— 它用来告诉 Git 这时你已经不再列选项,剩下的是文件路径了。不过养成使用它分隔选项与路径的习惯很重要,即使在你可能并不需要的时候。
<p>在此例中,我们可以用它来将不小心缓存的东东取消缓存。假设你修改了两个文件,想要将它们记录到两个不同的提交中去。
你应该缓存并提交一个,再缓存并提交另外一个。如果你不小心两个都缓存了,那要如何才能<i>取消</i>缓存呢?
你可以用 <code>git reset HEAD -- file</code>
技术上说,在这里你不需要使用 <code>--</code> —— 它用来告诉 Git 这时你已经不再列选项,剩下的是文件路径了。
不过养成使用它分隔选项与路径的习惯很重要,即使在你可能并不需要的时候。
</p>
<p>好,让我们看看取消缓存是什么样子的。这里我们有两个最近提交之后又有所改动的文件。我们将两个都缓存,并取消缓存其中一个。
</p>
<p>好,让我们看看取消缓存是什么样子的。这里我们有两个最近提交之后又有所改动的文件。我们将两个都缓存,并取消缓存其中一个。</p>
<pre>
<b>$ git status -s</b>
@ -513,14 +559,19 @@ M hello.rb
</p>
<p class="aside">
如果你好奇,它实际的操作是将该文件在“索引”中的校验和重置为最近一次提交中的值。<code>git add</code> 会计算一个文件的校验和,将它添加到“索引”中,而 <code>git reset HEAD</code> 将它改写回原先的,从而取消缓存。
如果你好奇,它实际的操作是将该文件在“索引”中的校验和重置为最近一次提交中的值。
<code>git add</code> 会计算一个文件的校验和,将它添加到“索引”中,
<code>git reset HEAD</code> 将它改写回原先的,从而取消缓存操作。
</p>
<p class="tip">
如果你想直接执行 <code>git unstage</code>,你可以在 Git 中配置个别名。执行 <code>git config --global alias.unstage "reset HEAD"</code> 即可。一旦执行完它,你就可以直接用 <code>git unstage [file]</code> 作为代替了。
如果你想直接执行 <code>git unstage</code>,你可以在 Git 中配置个别名。
执行 <code>git config --global alias.unstage "reset HEAD"</code> 即可。
一旦执行完它,你就可以直接用 <code>git unstage [file]</code> 作为代替了。
</p>
<p>如果你忘了取消缓存的命令Git 的常规 <code>git status</code> 输出的提示会很有帮助。例如,在你有已缓存的文件时,如果你不带 <code>-s</code> 执行 <code>git status</code>,它将告诉你怎样取消缓存:
<p>如果你忘了取消缓存的命令Git 的常规 <code>git status</code> 输出的提示会很有帮助。
例如,在你有已缓存的文件时,如果你不带 <code>-s</code> 执行 <code>git status</code>,它将告诉你怎样取消缓存:
</p>
<pre>
@ -535,7 +586,7 @@ M hello.rb
</pre>
<p class="nutshell">
<strong>一言以蔽</strong>,执行 <code>git reset HEAD</code> 以取消之前 <code>git add</code> 添加,但不希望包含在下一提交快照中的缓存。
<strong>简而言</strong>,执行 <code>git reset HEAD</code> 以取消之前 <code>git add</code> 添加,但不希望包含在下一提交快照中的缓存。
</p>
</div>
@ -554,11 +605,14 @@ M hello.rb
<div class="block">
<p>
<code>git rm</code> 会将条目从缓存区中移除。这与 <code>git reset HEAD</code> 将条目取消缓存是有区别的。“取消缓存”的意思就是将缓存区恢复为我们做出修改之前的样子。在另一方面,<code>git rm</code> 则将该文件彻底从缓存区踢出,因此它不再下一个提交快照之内,进而有效地删除它。
<code>git rm</code> 会将条目从缓存区中移除。这与 <code>git reset HEAD</code> 将条目取消缓存是有区别的。
“取消缓存”的意思就是将缓存区恢复为我们做出修改之前的样子。
在另一方面,<code>git rm</code> 则将该文件彻底从缓存区踢出,因此它不再下一个提交快照之内,进而有效地删除它。
</p>
<p>
默认情况下,<code>git rm file</code> 会将文件从缓存区和你的硬盘中(工作目录)删除。如果要在工作目录中留着该文件,可以使用 <code>git rm --cached</code>
默认情况下,<code>git rm file</code> 会将文件从缓存区和你的硬盘中(工作目录)删除。
如果要在工作目录中留着该文件,可以使用 <code>git rm --cached</code>
</p>
<h4>
@ -567,15 +621,20 @@ M hello.rb
</h4>
<p>
不像绝大多数其他版本控制系统Git 并不记录记录文件重命名。它反而只记录快照并对比快照以找到有啥文件可能被重命名了。如果一个文件从更新中删除了而在下次快照中新添加的另一个文件的内容与它很相似Git 就知道这极有可能是个重命名。因此,虽然有 <code>git mv</code> 命令,但它有点多余 —— 它做得所有事情就是 <code>git rm --cached</code>,重命名磁盘上的文件,然后再执行 <code>git add</code> 把新文件添加到缓存区。你并不需要用它,不过如果觉得这样容易些,尽管用吧。
不像绝大多数其他版本控制系统Git 并不记录记录文件重命名。它反而只记录快照,并对比快照以找到有啥文件可能被重命名了。
如果一个文件从更新中删除了而在下次快照中新添加的另一个文件的内容与它很相似Git 就知道这极有可能是个重命名。
因此,虽然有 <code>git mv</code> 命令,但它有点多余 —— 它做得所有事情就是 <code>git rm --cached</code>
重命名磁盘上的文件,然后再执行 <code>git add</code> 把新文件添加到缓存区。
你并不需要用它,不过如果觉得这样容易些,尽管用吧。
</p>
<p class="aside">
我自己不会用此命令的普通形式 —— 删除文件。通常直接从硬盘删除文件,然后执行 <code>git commit -a</code> 会简单些。它会自动将删除的文件从索引中移除。
我自己并不使用此命令的普通形式 —— 删除文件。通常直接从硬盘删除文件,然后执行 <code>git commit -a</code> 会简单些。
它会自动将删除的文件从索引中移除。
</p>
<p class="nutshell">
<strong>一言以蔽</strong>
<strong>简而言</strong>
执行 <code>git rm</code> 来删除 Git 追踪的文件。它还会删除你的工作目录中的相应文件。
</p>

View File

@ -10,11 +10,17 @@ layout: zh_reference
分支与合并
</h2>
<div class="block">
<p>分支是我最喜欢的 Git 特性之一。如果你用过其他版本控制系统,把你所知的分支给忘记,倒可能更有帮助些 —— 事实上,以我们使用分支的方式,把 Git 的分支看作 <i>上下文</i> 反而更合适。当你检出分支时,你可以在两三个不同的分支之间来回切换。
<p>分支是我最喜欢的 Git 特性之一。如果你用过其他版本控制系统,把你所知的分支给忘记,倒可能更有帮助些 ——
事实上,以我们使用分支的方式,把 Git 的分支看作 <i>上下文</i> 反而更合适。
当你检出分支时,你可以在两三个不同的分支之间来回切换。
</p>
<p class="nutshell">
<b>一言以蔽之</b>,你可以执行 <code>git branch (branchname)</code> 来创建分支,使用 <code>git checkout (branchname)</code> 命令切换到该分支在该分支的上下文环境中提交快照等之后可以很容易地来回切换。当你切换分支的时候Git 会用该分支的最后提交的快照替换你的工作目录的内容,所以多个分支不需要多个目录。使用 <code>git merge</code> 来合并分支。你可以多次合并到统一分支,也可以选择在合并之后直接删除被并入的分支。
<b>简而言之</b>,你可以执行 <code>git branch (branchname)</code> 来创建分支,
使用 <code>git checkout (branchname)</code> 命令切换到该分支,在该分支的上下文环境中,
提交快照等之后可以很容易地来回切换。当你切换分支的时候Git 会用该分支的最后提交的快照替换你的工作目录的内容,
所以多个分支不需要多个目录。使用 <code>git merge</code> 来合并分支。你可以多次合并到统一分支,
也可以选择在合并之后直接删除被并入的分支。
</p>
</div>
@ -42,7 +48,9 @@ layout: zh_reference
</h2>
<div class="block">
<p><code>git branch</code> 命令是 Git 中的通用分支管理工具,可以通过它完成多项任务。我们先说你会用到的最多的命令 —— 列出分支、创建分支和删除分支。我们还会介绍用来切换分支的 <code>git checkout</code> 命令。
<p><code>git branch</code> 命令是 Git 中的通用分支管理工具,可以通过它完成多项任务。
我们先说你会用到的最多的命令 —— 列出分支、创建分支和删除分支。
我们还会介绍用来切换分支的 <code>git checkout</code> 命令。
</p>
<h4>
@ -50,7 +58,8 @@ layout: zh_reference
<small>列出可用的分支</small>
</h4>
<p>没有参数是,<code>git branch</code> 会列出你在本地的分支。你所在的分支的行首会有个星号作标记。如果你开启了<a href="http://progit.org/book/ch7-1.html#colors_in_git">彩色模式</a>,当前分支会用绿色显示。
<p>没有参数时,<code>git branch</code> 会列出你在本地的分支。你所在的分支的行首会有个星号作标记。
如果你开启了<a href="http://progit.org/book/ch7-1.html#colors_in_git">彩色模式</a>,当前分支会用绿色显示。
</p>
<pre>
@ -58,7 +67,10 @@ $ git branch
* <span class="green">master</span>
</pre>
<p>此例的意思就是我们有一个叫做“master”的分支并且该分支是当前分支。当你执行 <code>git init</code> 的时候,缺省情况下 Git 就会为你创建“master”分支。但是这名字一点特殊意味都没有 —— 事实上你并不非得要一个叫做“master”的分支。不过由于它是缺省分支名的缘故绝大部分项目都有这个分支。
<p>此例的意思就是我们有一个叫做“master”的分支并且该分支是当前分支。
当你执行 <code>git init</code> 的时候,缺省情况下 Git 就会为你创建“master”分支。
但是这名字一点特殊意味都没有 —— 事实上你并不非得要一个叫做“master”的分支。
不过由于它是缺省分支名的缘故,绝大部分项目都有这个分支。
</p>
<h4>
@ -75,7 +87,10 @@ $ git branch
testing
</pre>
<p>现在我们可以看到有了一个新分支。当你以此方式在上次提交更新之后创建了新分支如果后来又有更新提交然后又切换到了“testing”分支Git 将还原你的工作目录到你创建分支时候的样子 —— 你可以把它看作一个记录你当前进度的书签。让我们实际运用看看 —— 我们用 <code>git checkout (branch)</code> 切换到我们要修改的分支。
<p>现在我们可以看到,有了一个新分支。当你以此方式在上次提交更新之后创建了新分支,如果后来又有更新提交,
然后又切换到了“testing”分支Git 将还原你的工作目录到你创建分支时候的样子 ——
你可以把它看作一个记录你当前进度的书签。让我们实际运用看看 ——
我们用 <code>git checkout (branch)</code> 切换到我们要修改的分支。
</p>
<pre>
@ -115,7 +130,10 @@ README hello.rb more.txt test.txt
</h4>
<p>
通常情况下你会更希望立即切换到新分支从而在该分支中操作然后当此分支的开发日趋稳定时将它合并到稳定版本的分支例如“master”中去。执行 <code>git branch newbranch; git checkout newbranch</code> 也很简单,不过 Git 还为你提供了快捷方式:<code>git checkout -b newbranch</code>
通常情况下,你会更希望立即切换到新分支,从而在该分支中操作,然后当此分支的开发日趋稳定时,
将它合并到稳定版本的分支例如“master”中去。
执行 <code>git branch newbranch; git checkout newbranch</code> 也很简单,
不过 Git 还为你提供了快捷方式:<code>git checkout -b newbranch</code>
</p>
<pre>
@ -142,11 +160,14 @@ Switched to branch 'master'
README hello.rb more.txt test.txt
</pre>
<p>如你所见,我们创建了一个分支,在该分支的上下文中移除了一些文件,然后切换回我们的主分支,那些文件又回来了。使用分支将工作切分开来,从而让我们能够在不同上下文中做事,并来回切换。
<p>如你所见,我们创建了一个分支,在该分支的上下文中移除了一些文件,然后切换回我们的主分支,那些文件又回来了。
使用分支将工作切分开来,从而让我们能够在不同上下文中做事,并来回切换。
</p>
<p>
创建新分支,在其中完成一部分工作,完成之后将它合并到主分支并删除。你会觉得这很方便,因为这么做很快很容易。如此,当你觉得这部分工作并不靠谱,舍弃它很容易。并且,如果你必须回到稳定分支做些事情,也可以很方便地这个独立分支的工作先丢在一边,完成要事之后再切换回来。
创建新分支,在其中完成一部分工作,完成之后将它合并到主分支并删除。你会觉得这很方便,因为这么做很快很容易。
如此,当你觉得这部分工作并不靠谱,舍弃它很容易。并且,如果你必须回到稳定分支做些事情,
也可以很方便地这个独立分支的工作先丢在一边,完成要事之后再切换回来。
</p>
<h4>
@ -154,7 +175,9 @@ README hello.rb more.txt test.txt
<small>删除分支</small>
</h4>
<p>假设我们要删除一个分支比如上例中的“testing”分支该分支没啥特殊的内容了可以执行 <code>git branch -d (branch)</code> 把它删掉。
<p>假设我们要删除一个分支比如上例中的“testing”分支该分支没啥特殊的内容了
可以执行 <code>git branch -d (branch)</code> 把它删掉。
</p>
<pre>
<b>$ git branch</b>
@ -167,7 +190,7 @@ Deleted branch testing (was 78b2670).
</pre>
<p class="nutshell">
<b>一言以蔽</b> 使用 <code>git branch</code> 列出现有的分支、创建新分支以及删除不必要或者已合并的分支。
<b>简而言</b> 使用 <code>git branch</code> 列出现有的分支、创建新分支以及删除不必要或者已合并的分支。
</p>
</div>
@ -184,7 +207,11 @@ Deleted branch testing (was 78b2670).
</h2>
<div class="block">
<p>一旦某分支有了独立内容,你终究会希望将它合并回到你的主分支。你可以使用 <code>git merge</code> 命令将任何分支合并到当前分支中去。我们那上例中的“removals”分支为例。假设我们创建了一个分支移除了一些文件并将它提交到该分支其实该分支是与我们的主分支也就是“master”独立开来的。要想将这些移除操作包含在主分支中你可以将“removals”分支合并回去。
<p>一旦某分支有了独立内容,你终究会希望将它合并回到你的主分支。
你可以使用 <code>git merge</code> 命令将任何分支合并到当前分支中去。
我们那上例中的“removals”分支为例。假设我们创建了一个分支移除了一些文件并将它提交到该分支
其实该分支是与我们的主分支也就是“master”独立开来的。
要想将这些移除操作包含在主分支中你可以将“removals”分支合并回去。
</p>
<pre>
@ -209,7 +236,9 @@ Fast-forward
更多复杂合并
</h4>
<p>当然合并并不仅仅是简单的文件添加、移除的操作Git 也会合并修改 —— 事实上,它很会合并修改。举例,我们看看在某分支中编辑某个文件,然后在另一个分支中把它的名字改掉再做些修改,最后将这俩分支合并起来。你觉得会变成一坨 shi我们试试看。
<p>当然合并并不仅仅是简单的文件添加、移除的操作Git 也会合并修改 —— 事实上,它很会合并修改。
举例,我们看看在某分支中编辑某个文件,然后在另一个分支中把它的名字改掉再做些修改,
最后将这俩分支合并起来。你觉得会变成一坨 shi我们试试看。
</p>
<pre>
@ -240,7 +269,10 @@ class HiWorld
1 files changed, 2 insertions(+), 4 deletions(-)
</pre>
<p>然后,将重命名类操作提交到 “change_class” 分支中。现在,假如切换回 “master” 分支我们可以看到类名恢复到了我们切换到 “change_class” 分支之前的样子。现在,再做些修改(即代码中的输出),同时将文件名从 <code>hello.rb</code> 改为 <code>ruby.rb</code>
<p>然后,将重命名类操作提交到 “change_class” 分支中。
现在,假如切换回 “master” 分支我们可以看到类名恢复到了我们切换到 “change_class” 分支之前的样子。
现在,再做些修改(即代码中的输出),同时将文件名从 <code>hello.rb</code> 改为 <code>ruby.rb</code>
</p>
<pre>
<b>$ git checkout master</b>
@ -267,7 +299,9 @@ index 2aabb6e..bf64b17 100644
rename hello.rb => ruby.rb (65%)
</pre>
<p>现在这些改变已经记录到我的 “master” 分支了。请注意,这里类名还是 “HelloWorld”而不是 “HiWorld”。然后我想将类名的改变合并过来我把 “change_class” 分支合并过来就行了。但是我已经将文件名都改掉了Git 知道该怎么办么?
<p>现在这些改变已经记录到我的 “master” 分支了。请注意,这里类名还是 “HelloWorld”而不是 “HiWorld”。
然后我想将类名的改变合并过来,我把 “change_class” 分支合并过来就行了。
但是我已经将文件名都改掉了Git 知道该怎么办么?
</p>
<pre>
@ -297,7 +331,9 @@ HiWorld.hello
合并冲突
</h4>
<p>那么Git 合并很有魔力,我们再也不用处理合并冲突了,对吗?不太确切。不同分支中修改了相同区块的代码,电脑自己猜不透神马的情况下,冲突就摆在我们面前了。我们看看两个分支中改了同一行代码的例子。
<p>那么Git 合并很有魔力,我们再也不用处理合并冲突了,对吗?不太确切。
不同分支中修改了相同区块的代码,电脑自己猜不透神马的情况下,冲突就摆在我们面前了。
我们看看两个分支中改了同一行代码的例子。
<p>
<pre>
@ -342,7 +378,10 @@ This project has examples of hello world in
nearly every programming language.
</pre>
<p>你可以看到Git 在产生合并冲突的地方插入了标准的与 Subversion 很像的合并冲突标记。轮到我们去解决这些冲突了。在这里我们就手动把它解决。如果你要 Git 打开一个图形化的合并工具,可以看看 <a href="http://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html">git 合并工具</a>(比如 kdiff3、emerge、p4merge 等)。
<p>你可以看到Git 在产生合并冲突的地方插入了标准的与 Subversion 很像的合并冲突标记。
轮到我们去解决这些冲突了。在这里我们就手动把它解决。如果你要 Git 打开一个图形化的合并工具,
可以看看 <a href="http://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html">git 合并工具</a>
(比如 kdiff3、emerge、p4merge 等)。
</p>
<pre>
@ -360,7 +399,9 @@ index 9103e27,69cad1a..0000000
This project has examples of hello world in
</pre>
<p>在 Git 中,处理合并冲突的时候有个很酷的提示。如果你执行 <code>git diff</code>,就像我演示的这样,它会告诉你冲突的两方,和你是如何解决的。现在是时候把它标记为已解决了。在 Git 中,我们可以用 <code>git add</code> —— 要告诉 Git 文件冲突已经解决,你必须把它写入缓存区。
<p>在 Git 中,处理合并冲突的时候有个很酷的提示。
如果你执行 <code>git diff</code>,就像我演示的这样,它会告诉你冲突的两方,和你是如何解决的。
现在是时候把它标记为已解决了。在 Git 中,我们可以用 <code>git add</code> —— 要告诉 Git 文件冲突已经解决,你必须把它写入缓存区。
</p>
<pre>
@ -377,7 +418,8 @@ M README
</p>
<p class="nutshell">
<b>一言以蔽之</b> 使用 <code>git merge</code> 将另一个分支并入当前的分支中去。Git 会自动以最佳方式将两个不同快照中独特的工作合并到一个新快照中去。
<b>简而言之</b> 使用 <code>git merge</code> 将另一个分支并入当前的分支中去。
Git 会自动以最佳方式将两个不同快照中独特的工作合并到一个新快照中去。
</p>
</div>
@ -395,15 +437,21 @@ M README
<div class="block">
<p>
到目前为止我们已经提交快照到项目中在不同的各自分离的上下文中切换但假如我们忘了自己是如何到目前这一步的那该怎么办或者假如我们想知道此分支与彼分支到底有啥区别Git 提供了一个告诉你使你达成当前快照的所有提交消息的工具,叫做 <code>git log</code>
<p>到目前为止,我们已经提交快照到项目中,在不同的各自分离的上下文中切换,
但假如我们忘了自己是如何到目前这一步的那该怎么办?或者假如我们想知道此分支与彼分支到底有啥区别?
Git 提供了一个告诉你使你达成当前快照的所有提交消息的工具,叫做 <code>git log</code>
</p>
<p>
要理解日志log命令你需要了解当执行 <code>git commit</code> 以存储一个快照的时候都有啥信息被保存了。除了文件详单、提交消息和提交者的信息Git 还保存了你的此次提交所基于的快照。也就是,假如你克隆了一个项目,你是在什么快照的基础上做的修改而得到新保存的快照的?这有益于为项目进程提供上下文,使 Git 能够弄明白谁做了什么改动。如果 Git 有你的快照所基于的快照的话,它就能自动判断你都改变了什么。而新提交所基于的提交,被称作新提交的“父亲”。
<p>要理解日志log命令你需要了解当执行 <code>git commit</code> 以存储一个快照的时候,都有啥信息被保存了。
除了文件详单、提交消息和提交者的信息Git 还保存了你的此次提交所基于的快照。
也就是,假如你克隆了一个项目,你是在什么快照的基础上做的修改而得到新保存的快照的?
这有益于为项目进程提供上下文,使 Git 能够弄明白谁做了什么改动。
如果 Git 有你的快照所基于的快照的话,它就能自动判断你都改变了什么。而新提交所基于的提交,被称作新提交的“父亲”。
</p>
<p>某分支的按时间排序的“父亲”列表,当你在该分支时,可以执行 <code>git log</code> 以查看。例如,如果我们在本章中操作的 Hello World 项目中执行 <code>git log</code>,我们可以看到已提交的消息。
<p>某分支的按时间排序的“父亲”列表,当你在该分支时,可以执行 <code>git log</code> 以查看。
例如,如果我们在本章中操作的 Hello World 项目中执行 <code>git log</code>,我们可以看到已提交的消息。
</p>
<pre>
<b>$ git log</b>
@ -474,10 +522,15 @@ b7ae93b added from ruby
* 17f4acf first commit
</pre>
<p>现在我们可以更清楚明了地看到何时工作分叉、又何时归并。这对查看发生了什么、应用了什么改变很有帮助,并且极大地帮助你管理你的分支。让我们创建一个分支,在里头做些事情,然后切回到主分支,也做点事情,然后看看 <code>log</code> 命令是如何帮助我们理清这俩分支上都发生了啥的。
<p>现在我们可以更清楚明了地看到何时工作分叉、又何时归并。
这对查看发生了什么、应用了什么改变很有帮助,并且极大地帮助你管理你的分支。
让我们创建一个分支,在里头做些事情,然后切回到主分支,也做点事情,然后看看 <code>log</code>
命令是如何帮助我们理清这俩分支上都发生了啥的。
</p>
<p>首先我们创建一个分支,来添加 Erlang 编程语言的 Hello World 示例 —— 我们想要在一个分支里头做这个,以避免让可能还不能工作的代码弄乱我们的稳定分支。这样就可以切来切去,片叶不沾身。
<p>首先我们创建一个分支,来添加 Erlang 编程语言的 Hello World 示例 ——
我们想要在一个分支里头做这个,以避免让可能还不能工作的代码弄乱我们的稳定分支。
这样就可以切来切去,片叶不沾身。
</p>
<pre>
@ -517,7 +570,10 @@ README ruby.rb
1 files changed, 2 insertions(+), 2 deletions(-)
</pre>
<p>现在假设我们有段时间不做这个项目了我们做别的去了。当我们回来的时候我们想知道“erlang”分支都是啥而主分支的进度又是怎样。仅仅看分支的名字我们是无从知道自己还在里面有 Haskell 的改动的,但是用 <code>git log</code> 我们就可以。如果你在命令行中提供一个分支名字,它就会显示该分支历史中“可及”的提交,即从该分支创立起可追溯的影响了最终的快照的提交。
<p>现在假设我们有段时间不做这个项目了,我们做别的去了。
当我们回来的时候我们想知道“erlang”分支都是啥而主分支的进度又是怎样。
仅仅看分支的名字,我们是无从知道自己还在里面有 Haskell 的改动的,但是用 <code>git log</code> 我们就可以。
如果你在命令行中提供一个分支名字,它就会显示该分支历史中“可及”的提交,即从该分支创立起可追溯的影响了最终的快照的提交。
</p>
<pre>
@ -533,10 +589,13 @@ b7ae93b added from ruby
17f4acf first commit
</pre>
<p>如此,我们很容易就看到分支里头还包括了 Haskell 代码(高亮显示了)。更酷的是,我们很容易地告诉 Git我们只对某个分支中可及的提交感兴趣。换句话说某分支中与其他分支相比唯一的提交。
<p>如此,我们很容易就看到分支里头还包括了 Haskell 代码(高亮显示了)。
更酷的是,我们很容易地告诉 Git我们只对某个分支中可及的提交感兴趣。换句话说某分支中与其他分支相比唯一的提交。
</p>
<p>在此例中如果我们想要合并“erlang”分支我们需要看当合并的时候都有啥提交会作用到我们的快照上去。我们告诉 Git 的方式是,在不想要看到的分支前放一个 <code>^</code>。例如如果我们想要看“erlang”分支中但不在主分支中的提交我们可以用 <code>erlang ^master</code>,或者反之。
<p>在此例中如果我们想要合并“erlang”分支我们需要看当合并的时候都有啥提交会作用到我们的快照上去。
我们告诉 Git 的方式是,在不想要看到的分支前放一个 <code>^</code>
例如如果我们想要看“erlang”分支中但不在主分支中的提交我们可以用 <code>erlang ^master</code>,或者反之。
</p>
<pre>
@ -551,7 +610,7 @@ ab5ab4c added erlang
</p>
<p class="nutshell">
<b>一言以蔽</b> 使用 <code>git log</code> 列出促成当前分支目前的快照的提交历史记录。这使你能够看到项目是如何到达现在的状况的。
<b>简而言</b> 使用 <code>git log</code> 列出促成当前分支目前的快照的提交历史记录。这使你能够看到项目是如何到达现在的状况的。
</p>
</div>
@ -570,10 +629,17 @@ ab5ab4c added erlang
<div class="block">
<p>
如果你达到一个重要的阶段,并希望永远记住那个特别的提交快照,你可以使用 <code>git tag</code> 给它打上标签。该 <code>tag</code> 命令基本上会给该特殊提交打上永久的书签,从而使你在将来能够用它与其他提交比较。通常,你会在切取一个发布版本或者交付一些东西的时候打个标签。
如果你达到一个重要的阶段,并希望永远记住那个特别的提交快照,你可以使用 <code>git tag</code> 给它打上标签。
<code>tag</code> 命令基本上会给该特殊提交打上永久的书签,从而使你在将来能够用它与其他提交比较。
通常,你会在切取一个发布版本或者交付一些东西的时候打个标签。
</p>
<p>比如说,我们想为我们的 Hello World 项目发布一个“1.0”版本。我们可以用 <code>git tag -a v1.0</code> 命令给最新一次提交打上(<code>HEAD</code>“v1.0”的标签。<code>-a</code> 选项意为“创建一个带注解的标签”,从而使你为标签添加注解。绝大部分时候都会这么做的。不用 <code>-a</code> 选项也可以执行的,但它不会记录这标签是啥时候打的,谁打的,也不会让你添加个标签的注解。我推荐一直创建带注解的标签。</p>
<p>比如说,我们想为我们的 Hello World 项目发布一个“1.0”版本。
我们可以用 <code>git tag -a v1.0</code> 命令给最新一次提交打上(<code>HEAD</code>“v1.0”的标签。
<code>-a</code> 选项意为“创建一个带注解的标签”,从而使你为标签添加注解。绝大部分时候都会这么做的。
不用 <code>-a</code> 选项也可以执行的,但它不会记录这标签是啥时候打的,谁打的,也不会让你添加个标签的注解。
我推荐一直创建带注解的标签。
</p>
<pre>
<b>$ git tag -a v1.0 </b>
@ -604,7 +670,10 @@ ab5ab4c added erlang
<p>如果我们有新提交,该标签依然会待在该提交的边上,所以我们已经给那个特定快照永久打上标签,并且能够将它与未来的快照做比较。
</p>
<p>不过我们并不需要给当前提交打标签。如果我们忘了给某个提交打标签,又将它发布了,我们可以给它追加标签。在相同的命令末尾加上提交的 SHA执行就可以了。例如假设我们发布了提交 <code>558151a</code>(几个提交之前的事情了),但是那时候忘了给它打标签。我们现在也可以:</p>
<p>不过我们并不需要给当前提交打标签。如果我们忘了给某个提交打标签,又将它发布了,我们可以给它追加标签。
在相同的命令末尾加上提交的 SHA执行就可以了。
例如,假设我们发布了提交 <code>558151a</code>(几个提交之前的事情了),但是那时候忘了给它打标签。
我们现在也可以:</p>
<pre>
<b>$ git tag -a v0.9 558151a</b>

View File

@ -6,11 +6,12 @@ layout: zh_reference
<h2>获取与创建项目</h2>
<div class="block">
<p>
你得现有一个 Git 仓库,才能用它进行操作。仓库是 Git 存放你要保存的快照的数据的地方。
你得先有一个 Git 仓库,才能用它进行操作。仓库是 Git 存放你要保存的快照的数据的地方。
</p>
<p>
拥有一个 Git 仓库的途径有两种。在已有的目录中,初始化一个新的,其一。比如一个新的项目,或者一个已存在的项目,但该项目尚未有版本控制。如果你想要复制一份别人的项目,或者与别人合作某个项目,也可以从一个公开的 Git 仓库克隆,其二。本章将对两者都做介绍。
<p>拥有一个 Git 仓库的途径有两种。在已有的目录中,初始化一个新的,其一。
比如一个新的项目,或者一个已存在的项目,但该项目尚未有版本控制。如果你想要复制一份别人的项目,
或者与别人合作某个项目,也可以从一个公开的 Git 仓库克隆,其二。本章将对两者都做介绍。
</p>
</div>
</div>
@ -33,7 +34,10 @@ layout: zh_reference
README hello.rb
</pre>
在这个项目里头,我们会用各种编程语言写 "Hello World" 实例。到目前为止,我们只有 Ruby 的,不过,这才刚上路嘛。为了开始用 Git 对这个项目作版本控制,我们执行一下 <code>git init</code>
<p>
在这个项目里头,我们会用各种编程语言写 "Hello World" 实例。
到目前为止,我们只有 Ruby 的,不过,这才刚上路嘛。为了开始用 Git 对这个项目作版本控制,我们执行一下 <code>git init</code>
</p>
<pre>
<b>$ git init</b>
@ -41,7 +45,9 @@ Initialized empty Git repository in /opt/konichiwa/.git/
# 在 /opt/konichiwa/.git 目录初始化空 Git 仓库完毕。
</pre>
现在你可以看到在你的项目目录中有个 <code>.git</code> 的子目录。这就是你的 Git 仓库了,所有有关你的此项目的快照数据都存放在这里。
<p>现在你可以看到在你的项目目录中有个 <code>.git</code> 的子目录。
这就是你的 Git 仓库了,所有有关你的此项目的快照数据都存放在这里。
</p>
<pre>
<b>$ ls -a</b>
@ -51,7 +57,8 @@ Initialized empty Git repository in /opt/konichiwa/.git/
恭喜,现在你就有了一个 Git 仓库的架子,可以开始快照你的项目了。
<p class="nutshell">
<strong>一言以蔽之</strong>,用 <code>git init</code> 来在目录中创建新的 Git 仓库。你可以在任何时候、任何目录中这么做,完全是本地化的。
<strong>简而言之</strong>,用 <code>git init</code> 来在目录中创建新的 Git 仓库。
你可以在任何时候、任何目录中这么做,完全是本地化的。
</p>
</div>
@ -67,8 +74,8 @@ Initialized empty Git repository in /opt/konichiwa/.git/
<span class="desc">复制一个 Git 仓库,以上下其手</span>
</h2>
<div class="block">
<p>
如果你需要与他人合作一个项目,或者想要拷贝一个项目,看看代码,你就可以克隆那个项目。执行 <code>git clone [url]</code>[url] 为你想要拷贝的项目,就可以了。
<p>如果你需要与他人合作一个项目,或者想要复制一个项目,看看代码,你就可以克隆那个项目。
执行 <code>git clone [url]</code>[url] 为你想要复制的项目,就可以了。
</p>
<pre>
@ -84,8 +91,9 @@ Resolving deltas: 100% (35/35), done.
README Rakefile <span class="blue">lib</span>
</pre>
<p>
上述操作将拷贝该项目的全部记录,让你本地拥有这些。并且该操作将拷贝该项目的主分支,是你能够查看代码,或编辑修改。进到该目录中,你会看到 <code>.git</code> 子目录。所有的项目数据都存在那里。
<p>上述操作将复制该项目的全部记录,让你本地拥有这些。并且该操作将拷贝该项目的主分支,
使你能够查看代码,或编辑、修改。进到该目录中,你会看到 <code>.git</code> 子目录。
所有的项目数据都存在那里。
</p>
<pre>
@ -98,15 +106,16 @@ HEAD description <span class="blue">info</span> packed-refs
config index <span class="blue">objects</span>
</pre>
<p>
默认情况下Git 会按照你提供的 URL 所指示的项目的名称创建你的本地项目目录。通常就是该 URL 最后一个 <code>/</code> 之后的任何东西。如果你想要一个不一样的名字,你可以在该命令后加上它,就在那个 URL 后面。
<p>默认情况下Git 会按照你提供的 URL 所指示的项目的名称创建你的本地项目目录。
通常就是该 URL 最后一个 <code>/</code> 之后的任何东西。如果你想要一个不一样的名字,
你可以在该命令后加上它,就在那个 URL 后面。
</p>
<p class="nutshell">
<strong>一言以蔽</strong>,使用 <code>git clone</code> 本地拷贝一个 Git 仓库,让自己能够查看该项目,或者动手修改
<strong>简而言</strong>,使用 <code>git clone</code> 拷贝一个 Git 仓库到本地,让自己能够查看该项目,或者进行修改。
</p>
</div>
</div>
<p><a href="/zh/basic">接下来:简单快照 &#187;</a></p>
<p><a href="/zh/basic">接下来:基本快照 &#187;</a></p>

View File

@ -5,10 +5,13 @@ layout: zh_reference
<h2>Git 手册简介</h2>
<div class="block">
<p>
本站为 Git 参考手册。目的是为学习与记忆 Git 使用中最重要、最普遍的命令提供快速翻阅。这些命令以你可能需要的操作类型划分,并且将提供日常使用中需要的一些常用的命令以及参数。
本站为 Git 参考手册。目的是为学习与记忆 Git 使用中最重要、最普遍的命令提供快速翻阅。
这些命令以你可能需要的操作类型划分,并且将提供日常使用中需要的一些常用的命令以及参数。
</p>
<p>
每个章节都有到下一个章节的链接,所以本手册也可以当作一个入门指导。每个页面还有一个深度 Git 文档阅读的链接,比如官方的使用手册页面或者<a href="http://progit.org">《Pro Git》</a>书中的相关章节,以便于你学习了解更多的 Git 命令。首先,我们要从如何以 Git 的思维方式管理源代码开始。
每个章节都有到下一个章节的链接,所以本手册也可以当作一个入门指导。
每个页面还有一个深度 Git 文档阅读的链接,比如官方的使用手册页面或者 <a href="http://progit.org">《Pro Git》</a>
书中的相关章节,以便于你学习了解更多的 Git 命令。首先,我们要从如何以 Git 的思维方式管理源代码开始。
</p>
</div>
</div>
@ -17,11 +20,13 @@ layout: zh_reference
<h2>如何以 Git 的方式思考</h2>
<div class="block">
<p>
懂得 Git第一件重要的事情就是要知道它与 Subversion、Perforce 或者任何你用过的版本控制工具都有着很大的差别。通常,忘掉你预想的版本控制方式,改以 Git 的方式思考,能够帮助你更好地学习 Git。
懂得 Git第一件重要的事情就是要知道它与 Subversion、Perforce 或者任何你用过的版本控制工具都有着很大的差别。
通常,忘掉你预想的版本控制方式,改以 Git 的方式思考,能够帮助你更好地学习 Git。
</p>
<p>
让我们从头开始。假设你正在设计一个新的源代码管理系统。在你使用某个工具之前,是如何完成基本的源码版本控制工作的呢?十有八九,你只是在项目到达某些阶段的时候,对项目做一份拷贝。
让我们从头开始。假设你正在设计一个新的源代码管理系统。在你使用某个工具之前,是如何完成基本的源码版本控制工作的呢?
十有八九,你只是在项目到达某些阶段的时候,对项目做一份拷贝。
</p>
<pre> $ cp -R project project.bak </pre>
@ -37,7 +42,8 @@ layout: zh_reference
<pre> $ cp -R project project.2010-06-01.bak </pre>
<p>
如此,你就有了一堆项目在各个阶段的快照,来作比较、查看。使用这种模式,你还可以有效地与人分享项目变更。如果你会在项目到达一定阶段的时候给它打个包,丢到自己的网站上,那其他的开发者们,就能很方便地下载它,做点改动,并给你补丁回馈。
如此,你就有了一堆项目在各个阶段的快照,来作比较、查看。使用这种模式,你还可以有效地与人分享项目变更。
如果你会在项目到达一定阶段的时候给它打个包,丢到自己的网站上,那其他的开发者们,就能很方便地下载它,做点改动,并给你补丁回馈。
</p>
<pre>
@ -45,26 +51,29 @@ layout: zh_reference
$ unzip project.2010-06-01.zip
$ cp -R project.2010-06-01 project-my-copy
$ cd project-my-copy
$ (改了些东西)
$ (做了某些修改)
$ diff project-my-copy project.2010-06-01 > change.patch
$ (email change.patch)</pre>
$ (通过E-mail发送修改补丁)</pre>
<p>
以此方式,原先的开发者就能将其他人的改动应用到他的项目中去,其他开发者也能了解你做的变更。其实这便是许多开源项目采用过多年的协作方式。
</p>
<p>
这办法其实很好使,所以假设我们现在想要写个工具,让这个办法更快、更简单。我们与其实现一个工具以记录每个文件的版本,可能不如去实现个工具以使创建、储存项目的快照更加方便,不用每次都去人肉作整个项目的拷贝。
这办法其实很好使,所以假设我们现在想要写个工具,让这个办法更快、更简单。
我们与其实现一个工具以记录每个文件的版本,可能不如去实现个工具以使创建、储存项目的快照更加方便,不用每次都去人肉作整个项目的拷贝。
</p>
<p>
这就是 Git 的精要所在。你通过 <code>git commit</code>告诉 Git 你想保存一份项目快照Git 就会为你的项目中的各个文件的当前状态存一份记录。之后,绝大部分的 Git 命令都围绕这些记录展开。比如查看它们的区别diff提取它们的内容等等。
这就是 Git 的精要所在。你通过 <code>git commit</code>告诉 Git 你想保存一份项目快照,
Git 就会为你的项目中的各个文件的当前状态存一份记录。之后,绝大部分的 Git 命令都围绕这些记录展开。
比如查看它们的区别diff提取它们的内容等等。
</p>
<center><img src="./images/snapshots.png"/></center>
<p>
如果你可以将 Git 看作一个排序、对比以及合并项目更新的工具,那就容易理解状况和正确做事了。
如果你将 Git 看作一个排序、对比以及合并项目更新的工具,那就容易理解状况和正确做事了。
</p>
</div>

View File

@ -11,11 +11,14 @@ layout: zh_reference
</h2>
<div class="block">
<p>
现在你有了一堆分支短期的主题、长期的特性或者其它。怎样追踪他们呢Git 有一组工具,可以帮助你弄明白工作是在哪儿完成的,两个分支间的区别是啥,等等。
现在你有了一堆分支,短期的主题、长期的特性或者其它。怎样追踪他们呢?
Git 有一组工具,可以帮助你弄明白工作是在哪儿完成的,两个分支间的区别是啥,等等。
</p>
<p class="nutshell">
<b>一言以蔽之</b> 执行 <code>git log</code> 找到你的项目历史中的特定提交 —— 按作者、日期、内容或者历史记录。执行 <code>git diff</code> 比较历史记录中的两个不同的点 —— 通常是为了看看两个分支有啥区别,或者从某个版本到另一个版本,你的软件都有啥变化。
<b>简而言之</b> 执行 <code>git log</code> 找到你的项目历史中的特定提交 ——
按作者、日期、内容或者历史记录。执行 <code>git diff</code> 比较历史记录中的两个不同的点 ——
通常是为了看看两个分支有啥区别,或者从某个版本到另一个版本,你的软件都有啥变化。
</p>
</div>
</div>
@ -32,7 +35,11 @@ layout: zh_reference
<div class="block">
<p>
通过查看分支中另一分支看不到的提交记录,我们已经看到如何用 <code>git log</code> 来比较分支。(如果你不记得了,它看起来是这样的:<code>git log branchA ^branchB</code>)。而且,你也可以用 <code>git log</code> 去寻找特定的提交。在此,我们会看到一些更广为使用的 <code>git log</code> 选项,不过哪有很多。完整的清单可以看看官方文档。
通过查看分支中另一分支看不到的提交记录,我们已经看到如何用 <code>git log</code> 来比较分支。
(如果你不记得了,它看起来是这样的:<code>git log branchA ^branchB</code>)。
而且,你也可以用 <code>git log</code> 去寻找特定的提交。
在此,我们会看到一些更广为使用的 <code>git log</code> 选项,不过哪有很多。
完整的清单可以看看官方文档。
</p>
<h4>
@ -41,7 +48,11 @@ layout: zh_reference
</h4>
<p>
要过滤你的提交历史,只寻找某个特定作者的提交,你可以使用 <code>--author</code> 选项。例如,比方说我们要找 Git 源码中 Linus 提交的部分。我们可以执行类似 <code>git log --author=Linus</code> 的命令。这个查找是大小写敏感的,并且也会检索电子邮箱地址。我在此例中使用 <code>-[number]</code> 选项,以限制结果为最近 [number] 次的提交。
要过滤你的提交历史,只寻找某个特定作者的提交,你可以使用 <code>--author</code> 选项。
例如,比方说我们要找 Git 源码中 Linus 提交的部分。
我们可以执行类似 <code>git log --author=Linus</code> 的命令。
这个查找是大小写敏感的,并且也会检索电子邮箱地址。
我在此例中使用 <code>-[number]</code> 选项,以限制结果为最近 [number] 次的提交。
</p>
<pre>
@ -59,7 +70,9 @@ b532581 make "git unpack-file" a built-in
</h4>
<p>
如果你要指定一个你感兴趣的日期范围以过滤你的提交,可以执行几个选项 —— 我用 <code>--since</code><code>--before</code>,但是你也可以用 <code>--until</code><code>--after</code>。例如,如果我要看 Git 项目中三周前且在四月十八日之后的所有提交,我可以执行这个(我还用了 <code>--no-merges</code> 选项以隐藏合并提交):
如果你要指定一个你感兴趣的日期范围以过滤你的提交,可以执行几个选项 ——
我用 <code>--since</code><code>--before</code>,但是你也可以用 <code>--until</code><code>--after</code>
例如,如果我要看 Git 项目中三周前且在四月十八日之后的所有提交,我可以执行这个(我还用了 <code>--no-merges</code> 选项以隐藏合并提交):
</p>
<pre>
@ -81,7 +94,8 @@ b6c8d2d Documentation/remote-helpers: Add invocation section
</h4>
<p>
你或许还想根据提交注释中的某个特定短语查找提交记录。可以用 <code>--grep</code> 选项。比如说我知道有个提交是有关使用 P4EDITOR 环境变量,又想回忆起那个改动是啥样子的 —— 我可以用 <code>--grep</code> 选项找到该提交。
你或许还想根据提交注释中的某个特定短语查找提交记录。可以用 <code>--grep</code> 选项。
比如说我知道有个提交是有关使用 P4EDITOR 环境变量,又想回忆起那个改动是啥样子的 —— 我可以用 <code>--grep</code> 选项找到该提交。
</p>
<pre>
@ -101,7 +115,10 @@ Date: Wed Mar 12 19:03:24 2008 -0500
</pre>
<p>
Git 会对所有的 <code>--grep</code><code>--author</code> 参数作逻辑或。如果你用 <code>--grep</code><code>--author</code> 时,想看的是某人写作的并且有某个特殊的注释内容的提交记录,你需要加上 <code>--all-match</code> 选项。在这些例子中,我会用上 <code>--format</code> 选项,这样我们就可以看到每个提交的作者是谁了。
Git 会对所有的 <code>--grep</code><code>--author</code> 参数作逻辑或。
如果你用 <code>--grep</code><code>--author</code> 时,想看的是某人写作的并且有某个特殊的注释内容的提交记录,
你需要加上 <code>--all-match</code> 选项。
在这些例子中,我会用上 <code>--format</code> 选项,这样我们就可以看到每个提交的作者是谁了。
</p>
<p>
@ -116,7 +133,8 @@ da4a660 Benjamin Sergeant git-p4 fails when cloning a p4 depo.
</pre>
<p>
如果我加上 <code>--author=Hausmann</code> 参数,与进一步过滤上述结果到 Simon 的唯一提交相反,它会告诉我所有 Simon 的提交或者注释中有“p4 demo”的提交
如果我加上 <code>--author=Hausmann</code> 参数,与进一步过滤上述结果到 Simon 的唯一提交相反,
它会告诉我所有 Simon 的提交或者注释中有“p4 demo”的提交
</p>
<pre>
@ -151,7 +169,10 @@ e96e400 Simon Hausmann git-p4: Fix submit user-interface.
</h4>
<p>
如果你写的提交注释都极度糟糕怎么办?或者,如果你要找某个函数是何时引入的,某些变量是在哪里开始被使用的?你可以告诉 Git 在每个提交之间的差值中查找特定字符串。例如如果我们想要找出哪个提交修改出了类似函数名“userformat_find_requirements”我们可以执行注意在“-S”与你要找的东东之间没有“=”):
如果你写的提交注释都极度糟糕怎么办?或者,如果你要找某个函数是何时引入的,某些变量是在哪里开始被使用的?
你可以告诉 Git 在每个提交之间的差值中查找特定字符串。
例如如果我们想要找出哪个提交修改出了类似函数名“userformat_find_requirements”
我们可以执行(注意在“-S”与你要找的东东之间没有“=”):
</p>
<pre>
@ -180,7 +201,10 @@ Date: Tue Apr 13 22:31:12 2010 +0200
</h4>
<p>
每个提交都是项目的一个快照。由于每个提交都记录它所基于的快照Git 能够经常对它们求差值,并以补丁形式向你展示。这意味着,对任意提交,你都可以获取该提交给项目引入补丁。你可以用 <code>git show [SHA]</code> 加上某个特定的提交 SHA 获取,或者执行 <code>git log -p</code>,它会告诉 Git 输出每个提交之后的补丁。这是个总结某一分支或者两个提交之间都发生了神马的好途径。
每个提交都是项目的一个快照。由于每个提交都记录它所基于的快照Git 能够经常对它们求差值,并以补丁形式向你展示。
这意味着,对任意提交,你都可以获取该提交给项目引入补丁。
你可以用 <code>git show [SHA]</code> 加上某个特定的提交 SHA 获取,或者执行 <code>git log -p</code>
它会告诉 Git 输出每个提交之后的补丁。这是个总结某一分支或者两个提交之间都发生了神马的好途径。
</p>
<pre>
@ -234,7 +258,8 @@ index d053cc8..9103e27 100644
</h4>
<p>
如果 <code>-p</code> 选项对你来说太详细了,你可以用 <code>--stat</code> 总结这些改动。这是不用 <code>-p</code>,而用 <code>--stat</code> 选项时,同一份日志的输出。
如果 <code>-p</code> 选项对你来说太详细了,你可以用 <code>--stat</code> 总结这些改动。
这是不用 <code>-p</code>,而用 <code>--stat</code> 选项时,同一份日志的输出。
</p>
<pre>
@ -278,11 +303,13 @@ Date: Fri Jun 4 12:58:53 2010 +0200
<div class="block">
<p>
最后,要查看两个提交快照的绝对改动,你可以用 <code>git diff</code> 命令。这在两个主要情况中广为使用 —— 查看两个分支彼此之间的差值,和查看自发布或者某个旧历史点之后都有啥变了。让我们看看这俩情况。
最后,要查看两个提交快照的绝对改动,你可以用 <code>git diff</code> 命令。
这在两个主要情况中广为使用 —— 查看两个分支彼此之间的差值,和查看自发布或者某个旧历史点之后都有啥变了。让我们看看这俩情况。
</p>
<p>
你仅需执行 <code>git diff [version]</code>(或者你给该发布打的任何标签)就可以查看自最近发布之后的改动。例如,如果我们想要看看自 v0.9 发布之后我们的项目改变了啥,我们可以执行 <code>git diff v0.9</code>
你仅需执行 <code>git diff [version]</code>(或者你给该发布打的任何标签)就可以查看自最近发布之后的改动。
例如,如果我们想要看看自 v0.9 发布之后我们的项目改变了啥,我们可以执行 <code>git diff v0.9</code>
</p>
<pre>
@ -325,7 +352,11 @@ index bb86f00..192151c 100644
</pre>
<p>
要比较两个不同的分支,你可以执行类似 <code>git diff branchA branchB</code> 的命令。不过它的问题在于它会完完全全按你说的作 —— 它会直接给你个补丁文件,该补丁能够将甲分支的最新快照变成乙分支的最新快照的样子。这意味着如果两个分支已经产生分歧 —— 奔往两个不同方向了 —— 它会移除甲分支中引入的所有工作,然后累加乙分支中的所有工作。这大概不是你要的吧 —— 你想要不在甲分支中的乙分支的改动。所以你真的需要的是两个分支叉开去时,和最新的乙分支的差别。所以,如果我们的历史记录看起来像这样:
要比较两个不同的分支,你可以执行类似 <code>git diff branchA branchB</code> 的命令。
不过它的问题在于它会完完全全按你说的作 —— 它会直接给你个补丁文件,该补丁能够将甲分支的最新快照变成乙分支的最新快照的样子。
这意味着如果两个分支已经产生分歧 —— 奔往两个不同方向了 —— 它会移除甲分支中引入的所有工作,然后累加乙分支中的所有工作。
这大概不是你要的吧 —— 你想要不在甲分支中的乙分支的改动。所以你真的需要的是两个分支叉开去时,和最新的乙分支的差别。
所以,如果我们的历史记录看起来像这样:
</p>
<pre>
@ -351,7 +382,9 @@ index bb86f00..192151c 100644
</pre>
<p>
你可以看到,它加上了 erlang 和 haskell 文件,这确实是我们在该分支中做的,但是它同时恢复了我们在主分支中改动的 ruby 文件。我们真心想要的只是“erlang”分支中的改动添加两个文件。我们可以通过求两个分支分歧时的共同提交与该分支的差值得到想要的结果
你可以看到,它加上了 erlang 和 haskell 文件,这确实是我们在该分支中做的,
但是它同时恢复了我们在主分支中改动的 ruby 文件。我们真心想要的只是“erlang”分支中的改动添加两个文件
我们可以通过求两个分支分歧时的共同提交与该分支的差值得到想要的结果:
</p>
<pre>
@ -362,7 +395,10 @@ index bb86f00..192151c 100644
</pre>
<p>
这才是我们在找的但是我们可不想要每次都要找出两个分支分歧时的那次提交。幸运的是Git 为此提供了一个快捷方式。如果你执行 <code>git diff master...erlang</code>在分支名之间有三个半角的点Git 就会自动找出两个分支的共同提交(也被成为合并基础),并求差值。
这才是我们在找的,但是我们可不想要每次都要找出两个分支分歧时的那次提交。
幸运的是Git 为此提供了一个快捷方式。
如果你执行 <code>git diff master...erlang</code>(在分支名之间有三个半角的点),
Git 就会自动找出两个分支的共同提交(也被成为合并基础),并求差值。
</p>
<pre>
@ -405,7 +441,8 @@ index bb86f00..192151c 100644
<p class="nutshell">
<b>一言以蔽之</b> 使用 <code>git diff</code> 查看某一分支自它偏离出来起与过去某一点之间项目的改动。总是使用 <code>git diff branchA...branchB</code> 来查看 branchB 与 branchA 的相对差值,这会让事情简单点。
<b>简而言之</b> 使用 <code>git diff</code> 查看某一分支自它偏离出来起与过去某一点之间项目的改动。
总是使用 <code>git diff branchA...branchB</code> 来查看 branchB 与 branchA 的相对差值,这会让事情简单点。
</p>
</div>

View File

@ -11,19 +11,26 @@ layout: zh_reference
</h2>
<div class="block">
<p>
Git 并不像 Subversion 那样有个中心服务器。目前为止所有的命令都是本地执行的,更新的知识本地的数据库。要通过 Git 与其他开发者合作你需要将数据放到一台其他开发者能够连接的服务器上。Git 实现此流程的方式是将你的数据与另一个仓库同步。在服务器与客户端之间并没有实质的区别 —— Git 仓库就是 Git 仓库,你可以很容易地在两者之间同步。
Git 并不像 Subversion 那样有个中心服务器。
目前为止所有的命令都是本地执行的,更新的知识本地的数据库。
要通过 Git 与其他开发者合作,你需要将数据放到一台其他开发者能够连接的服务器上。
Git 实现此流程的方式是将你的数据与另一个仓库同步。在服务器与客户端之间并没有实质的区别 ——
Git 仓库就是 Git 仓库,你可以很容易地在两者之间同步。
</p>
<p>
一旦你有了个 Git 仓库,不管它是在你自己的服务器上,或者是由 GitHub 之类的地方提供,你都可以告诉 Git 推送你拥有的远端仓库还没有的数据,或者叫 Git 从别的仓库把差别取过来。
一旦你有了个 Git 仓库,不管它是在你自己的服务器上,或者是由 GitHub 之类的地方提供,
你都可以告诉 Git 推送你拥有的远端仓库还没有的数据,或者叫 Git 从别的仓库把差别取过来。
</p>
<p>
联网的时候你可以随时做这个,它并不需要对应一个 <code>commit</code> 或者别的什么。一般你会本地提交几次,然后从你的项目克隆自的线上的共享仓库提取数据以保持最新,将新完成的合并到你完成的工作中去,然后推送你的改动会服务器。
联网的时候你可以随时做这个,它并不需要对应一个 <code>commit</code> 或者别的什么。
一般你会本地提交几次,然后从你的项目克隆自的线上的共享仓库提取数据以保持最新,将新完成的合并到你完成的工作中去,然后推送你的改动会服务器。
</p>
<p class="nutshell">
<b>一言以蔽之</b> 使用 <code>git fetch</code> 更新你的项目,使用 <code>git push</code> 分享你的改动。你可以用 <code>git remote</code> 管理你的远程仓库。
<b>简而言之</b> 使用 <code>git fetch</code> 更新你的项目,使用 <code>git push</code> 分享你的改动。
你可以用 <code>git remote</code> 管理你的远程仓库。
</p>
</div>
</div>
@ -31,7 +38,7 @@ layout: zh_reference
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-remote.html">文档</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-remote">文档</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-5.html#showing_your_remotes"></a>
</span>
<a name="remote">git remote</a>
@ -40,11 +47,13 @@ layout: zh_reference
<div class="block">
<p>不像中心化的版本控制系统客户端与服务端很不一样Git 仓库基本上都是一致的,并且并可以同步他们。这使得拥有多个远端仓库变得容易 —— 你可以可以拥有一些只读的仓库,另外的一些也可写的仓库。
<p>不像中心化的版本控制系统客户端与服务端很不一样Git 仓库基本上都是一致的,并且并可以同步他们。
这使得拥有多个远端仓库变得容易 —— 你可以可以拥有一些只读的仓库,另外的一些也可写的仓库。
</p>
<p>
当你需要与远端仓库同步的时候不需要使用它详细的链接。Git 储存了你感兴趣的远端仓库的链接的别名或者昵称。你可以使用 <code>git remote</code> 命令管理这个远端仓库列表。
当你需要与远端仓库同步的时候不需要使用它详细的链接。Git 储存了你感兴趣的远端仓库的链接的别名或者昵称。
你可以使用 <code>git remote</code> 命令管理这个远端仓库列表。
</p>
<h4>
@ -53,15 +62,17 @@ layout: zh_reference
</h4>
<p>
如果没有任何参数Git 会列出它存储的远端仓库别名了事。默认情况下如果你的项目是克隆的与本地创建一个新的相反Git 会自动将你的项目克隆自的仓库添加到列表中并取名“origin”。如果你执行时加上 <code>-v</code> 参数,你还可以看到每个别名的实际链接地址。
如果没有任何参数Git 会列出它存储的远端仓库别名了事。默认情况下,如果你的项目是克隆的(与本地创建一个新的相反),
Git 会自动将你的项目克隆自的仓库添加到列表中并取名“origin”。
如果你执行时加上 <code>-v</code> 参数,你还可以看到每个别名的实际链接地址。
</p>
<pre>
<b>$ git remote</b>
origin
<b>$ git remote -v</b>
origin git@github.com:schacon/git-reference.git (fetch)
origin git@github.com:schacon/git-reference.git (push)
origin git@github.com:github/git-reference.git (fetch)
origin git@github.com:github/git-reference.git (push)
</pre>
<p>在此你看到了该链接两次,是因为 Git 允许你为每个远端仓库添加不同的推送与获取的链接,以备你读写时希望使用不同的协议。
@ -73,11 +84,17 @@ origin git@github.com:schacon/git-reference.git (push)
</h4>
<p>
如果你希望分享一个本地创建的仓库,或者你想要获取别人的仓库中的贡献 —— 如果你想要以任何方式与一个新仓库沟通,最简单的方式通常就是把它添加为一个远端仓库。执行 <code>git remote add [alias] [url]</code> 就可以。此命令将 <code>[url]</code><code>[alias]</code> 的别名添加为本地的远端仓库。
如果你希望分享一个本地创建的仓库,或者你想要获取别人的仓库中的贡献 ——
如果你想要以任何方式与一个新仓库沟通,最简单的方式通常就是把它添加为一个远端仓库。
执行 <code>git remote add [alias] [url]</code> 就可以。
此命令将 <code>[url]</code><code>[alias]</code> 的别名添加为本地的远端仓库。
</p>
<p>
例如,假设我们想要与整个世界分享我们的 Hello World 程序。我们可以在一台服务器上创建一个新仓库(我以 GitHub 为例子。它应该会给你一个链接在这里就是“git@github.com:schacon/hw.git”。要把它添加到我们的项目以便我们推送以及获取更新我们可以这样
例如,假设我们想要与整个世界分享我们的 Hello World 程序。
我们可以在一台服务器上创建一个新仓库(我以 GitHub 为例子)。
它应该会给你一个链接在这里就是“git@github.com:schacon/hw.git”。
要把它添加到我们的项目以便我们推送以及获取更新,我们可以这样:
</p>
<pre>
@ -89,7 +106,9 @@ github git@github.com:schacon/hw.git (push)
</pre>
<p>
像分支的命名一样,远端仓库的别名是强制的 —— 就像“master”没有特别意义但它广为使用因为 <code>git init</code> 默认用它“origin”经常被用作远端仓库别名就因为 <code>git clone</code> 默认用它作为克隆自的链接的别名。此例中我决定给我的远端仓库取名“github”但我叫它随便什么都可以。
像分支的命名一样,远端仓库的别名是强制的 —— 就像“master”没有特别意义但它广为使用
因为 <code>git init</code> 默认用它“origin”经常被用作远端仓库别名就因为 <code>git clone</code>
默认用它作为克隆自的链接的别名。此例中我决定给我的远端仓库取名“github”但我叫它随便什么都可以。
</p>
<h4>
@ -118,7 +137,8 @@ github git@github.com:schacon/hw.git (push)
</pre>
<p class="nutshell">
<b>一言以蔽之</b> 你可以用 <code>git remote</code> 列出你的远端仓库和那些仓库的链接。你可以使用 <code>git remote add</code> 添加新的远端仓库,用 <code>git remote rm</code> 删掉已存在的那些。
<b>简而言之</b> 你可以用 <code>git remote</code> 列出你的远端仓库和那些仓库的链接。
你可以使用 <code>git remote add</code> 添加新的远端仓库,用 <code>git remote rm</code> 删掉已存在的那些。
</p>
</div>
@ -127,7 +147,7 @@ github git@github.com:schacon/hw.git (push)
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html">文档</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-fetch">文档</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-5.html#fetching_and_pulling_from_your_remotes"></a>
</span>
<a name="fetch">git fetch</a>
@ -138,7 +158,7 @@ github git@github.com:schacon/hw.git (push)
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-pull.html">文档</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-pull">文档</a> &nbsp;
<a target="new" href="http://progit.org/book/"></a>
</span>
<a name="pull">git pull</a>
@ -148,15 +168,25 @@ github git@github.com:schacon/hw.git (push)
<div class="block">
<p>
Git 有两个命令用来从某一远端仓库更新。<code>git fetch</code> 会使你与另一仓库同步,提取你本地所没有的数据,为你在同步时的该远端的每一分支提供书签。这些分支被叫做“远端分支”,除了 Git 不允许你检出(切换到该分支)之外,跟本地分支没区别 —— 你可以将它们合并到当前分支,与其他分支作比较差异,查看那些分支的历史日志,等等。同步之后你就可以在本地操作这些。
Git 有两个命令用来从某一远端仓库更新。
<code>git fetch</code> 会使你与另一仓库同步,提取你本地所没有的数据,为你在同步时的该远端的每一分支提供书签。
这些分支被叫做“远端分支”,除了 Git 不允许你检出(切换到该分支)之外,跟本地分支没区别 ——
你可以将它们合并到当前分支,与其他分支作比较差异,查看那些分支的历史日志,等等。同步之后你就可以在本地操作这些。
</p>
<p>
第二个会从远端服务器提取新数据的命令是 <code>git pull</code>。基本上,该命令就是在 <code>git fetch</code> 之后紧接着 <code>git merge</code> 远端分支到你所在的任意分支。我个人不太喜欢这命令 —— 我更喜欢 <code>fetch</code><code>merge</code> 分开来做。少点魔法,少点问题。不过,如果你喜欢这主意,你可以看一下 <code>git pull</code><a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-pull.html">官方文档</a>
第二个会从远端服务器提取新数据的命令是 <code>git pull</code>
基本上,该命令就是在 <code>git fetch</code> 之后紧接着 <code>git merge</code> 远端分支到你所在的任意分支。
我个人不太喜欢这命令 —— 我更喜欢 <code>fetch</code><code>merge</code> 分开来做。少点魔法,少点问题。
不过,如果你喜欢这主意,你可以看一下 <code>git pull</code>
<a target="new" href="http://git-scm.com/docs/git-pull">官方文档</a>
</p>
<p>
假设你配置好了一个远端,并且你想要提取更新,你可以首先执行 <code>git fetch [alias]</code> 告诉 Git 去获取它有你没有的数据,然后你可以执行 <code>git merge [alias]/[branch]</code> 以将服务器上的任何更新(假设有人这时候推送到服务器了)合并到你的当前分支。那么,如果我是与两三个其他人合作 Hello World 项目,并且想要将我最近连接之后的所有改动拿过来,我可以这么做:
假设你配置好了一个远端,并且你想要提取更新,你可以首先执行 <code>git fetch [alias]</code>
告诉 Git 去获取它有你没有的数据,然后你可以执行 <code>git merge [alias]/[branch]</code>
以将服务器上的任何更新(假设有人这时候推送到服务器了)合并到你的当前分支。
那么,如果我是与两三个其他人合作 Hello World 项目,并且想要将我最近连接之后的所有改动拿过来,我可以这么做:
</p>
<pre>
@ -175,18 +205,25 @@ From github.com:schacon/hw
</pre>
<p>
可以看到自从上一次与远端仓库同步以后又新赠或更新了五个分支。“ada”与“lisp”分支是新的而“master”、“clang”与“java”分支则被更新了。在此例中我的团队在合并入主分支之前将提议的更新推送到远端分支以审核。
</p>
<p>你可以看到 Git 做的映射。远端仓库的主分支成为了本地的一个叫做“github/master”的分支。这样我就可以执行 <code>git merge github/master</code> 将远端的主分支和并入我的本地主分支。或者,我可以 <code>git log github/master ^master</code> 看看该分支上的新提交。如果你的远端仓库叫做“origin”那远端主分支就会叫做 <code>origin/master</code>。几乎所有能在本地分支上执行的命令都可以在远端分支上用。
可以看到自从上一次与远端仓库同步以后,又新赠或更新了五个分支。
“ada”与“lisp”分支是新的而“master”、“clang”与“java”分支则被更新了。
在此例中,我的团队在合并入主分支之前,将提议的更新推送到远端分支以审核。
</p>
<p>
如果你有多个远端仓库,你可以执行 <code>git fetch [alias]</code> 提取特定的远端仓库,或者执行 <code>git fetch --all</code> 告诉 Git 同步所有的远端仓库。
你可以看到 Git 做的映射。远端仓库的主分支成为了本地的一个叫做“github/master”的分支。
这样我就可以执行 <code>git merge github/master</code> 将远端的主分支和并入我的本地主分支。
或者,我可以 <code>git log github/master ^master</code> 看看该分支上的新提交。
如果你的远端仓库叫做“origin”那远端主分支就会叫做 <code>origin/master</code>。几乎所有能在本地分支上执行的命令都可以在远端分支上用。
</p>
<p>
如果你有多个远端仓库,你可以执行 <code>git fetch [alias]</code> 提取特定的远端仓库,
或者执行 <code>git fetch --all</code> 告诉 Git 同步所有的远端仓库。
</p>
<p class="nutshell">
<b>一言以蔽之</b> 执行 <code>git fetch [alias]</code> 来将你的仓库与远端仓库同步,提取所有它独有的数据到本地分支以合并或者怎样。
<b>简而言</b> 执行 <code>git fetch [alias]</code> 来将你的仓库与远端仓库同步,提取所有它独有的数据到本地分支以合并或者怎样。
</p>
</div>
@ -196,7 +233,7 @@ From github.com:schacon/hw
<div class="box">
<h2>
<span class="docs">
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-push.html">文档</a> &nbsp;
<a target="new" href="http://git-scm.com/docs/git-push">文档</a> &nbsp;
<a target="new" href="http://progit.org/book/ch2-5.html#pushing_to_your_remotes"></a>
</span>
<a name="push">git push</a>
@ -205,7 +242,9 @@ From github.com:schacon/hw
<div class="block">
<p>
想要与他人分享你牛鼻的提交,你需要将改动推送到远端仓库。执行 <code>git push [alias] [branch]</code>,就会将你的 [branch] 分支推送成为 [alias] 远端上的 [branch] 分支。让我们试试推送我们的主分支到先前添加的“github”远端仓库上去。
想要与他人分享你牛鼻的提交,你需要将改动推送到远端仓库。
执行 <code>git push [alias] [branch]</code>,就会将你的 [branch] 分支推送成为 [alias] 远端上的 [branch] 分支。
让我们试试推送我们的主分支到先前添加的“github”远端仓库上去。
</p>
<pre>
@ -239,11 +278,17 @@ To git@github.com:schacon/hw.git
</pre>
<p>
现在当人们从该仓库克隆时他们就会得到一个“erlang”分支以查阅、合并。用这种方式你可以推送任何分支到任何你有写权限的仓库。如果你的分支已经在该仓库中了它会试着去更新如果它不再Git 会把它加上。
现在当人们从该仓库克隆时他们就会得到一个“erlang”分支以查阅、合并。
用这种方式,你可以推送任何分支到任何你有写权限的仓库。
如果你的分支已经在该仓库中了它会试着去更新如果它不再Git 会把它加上。
</p>
<p>
最后一个当你推送到远端分支时会碰到的主要问题是,其他人在此期间也推送了的情况。如果你和另一个开发者同时克隆了,又都有提交,那么当她推送后你也想推送时,默认情况下 Git 不会让你覆盖她的改动。相反的,它会在你试图推送的分支上执行 <code>git log</code>,确定它能够在你的推送分支的历史记录中看到服务器分支的当前进度。如果它在在你的历史记录中看不到,它就会下结论说你过时了,并打回你的推送。你需要正式提取、合并,然后再次推送 —— 以确定你把她的改动也考虑在内了。
最后一个当你推送到远端分支时会碰到的主要问题是,其他人在此期间也推送了的情况。
如果你和另一个开发者同时克隆了,又都有提交,那么当她推送后你也想推送时,默认情况下 Git 不会让你覆盖她的改动。
相反的,它会在你试图推送的分支上执行 <code>git log</code>,确定它能够在你的推送分支的历史记录中看到服务器分支的当前进度。
如果它在在你的历史记录中看不到,它就会下结论说你过时了,并打回你的推送。
你需要正式提取、合并,然后再次推送 —— 以确定你把她的改动也考虑在内了。
</p>
<p>
@ -265,7 +310,9 @@ fast-forwards' section of 'git push --help' for details.
</p>
<p class="nutshell">
<b>一言以蔽之</b> 执行 <code>git push [alias] [branch]</code> 将你的本地改动推送到远端仓库。如果可以的话,它会依据你的 [branch] 的样子,推送到远端的 [branch] 去。如果在你上次提取、合并之后另有人推送了Git 服务器会拒绝你的推送,知道你是最新的为止。
<b>简而言之</b> 执行 <code>git push [alias] [branch]</code> 将你的本地改动推送到远端仓库。
如果可以的话,它会依据你的 [branch] 的样子,推送到远端的 [branch] 去。
如果在你上次提取、合并之后另有人推送了Git 服务器会拒绝你的推送,知道你是最新的为止。
</p>
</div>