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
gh-pages
dotnil 11 years ago
commit 0f4505c1e2

3
.gitignore vendored

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

@ -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/.

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

@ -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;

@ -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;

@ -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>

@ -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>

@ -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>

File diff suppressed because it is too large Load Diff

@ -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>

@ -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>

@ -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>

@ -7,19 +7,21 @@ 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>
这里有个重要的概念Git 有一个叫做“索引”的东东,有点像是你的快照的缓存区。这就使你能够从更改的文件中创建出一系列组织良好的快照,而不是一次提交所有的更改。
这里有个重要的概念Git 有一个叫做“索引”的东东,有点像是你的快照的缓存区。这就使你能够从更改的文件中创建出一系列组织良好的快照,而不是一次提交所有的更改。
</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>
@ -36,11 +38,14 @@ layout: zh_reference
</h2>
<div class="block">
<p>
在 Git 中,在提交你修改的文件之前,你需要把它们添加到缓存。如果该文件是新的,你可以执行 <code>git add</code> 将该文件添加到缓存,但是,即使该文件已经被追踪了 —— 也就是说,曾经提交过了 —— 你仍然需要执行 <cpde>git add</code> 将新更改的文件添加到缓存去。让我们看几个例子:
<p>
在 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,10 +69,14 @@ 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>
<p>好了,现在我们改个文件,再跑一下 <code>git status</code>,有点古怪。</p>
<pre>
<b>$ vim README</b>
<b>$ git status -s</b>
@ -75,17 +84,19 @@ 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>。任何你没有添加的改动都不会被包含在内 —— 这意味着你可以比绝大多数其他源代码版本控制系统更精确地归置你的快照。
<strong>一言以蔽之</strong>
当你要将你的修改包含在即将提交的快照里的时候,执行 <code>git add</code>
任何你没有添加的改动都不会被包含在内 —— 这意味着你可以比绝大多数其他源代码版本控制系统更精确地归置你的快照。
</p>
<p>请查看《Pro Git》中 <code>git add</code> 的 “-p” 参数,以了解更多关于提交文件的灵活性的例子。
</p>
<p>请查看《Pro Git》中 <code>git add</code> 的 “-p” 参数,以了解更多关于提交文件的灵活性的例子。
</p>
</div>
@ -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>
@ -354,7 +383,7 @@ index 2aabb6e..2ae9ba4 100644
<b>$ git config --global user.email you@somedomain.com</b>
</pre>
<p>让我们写入缓存,并提交对 <code>hello.rb</code> 的所有改动。在首个例子中,我们使用 <code>-m</code> 选项以在命令行中提供提交注释。
<p>让我们写入缓存,并提交对 <code>hello.rb</code> 的所有改动。在首个例子中,我们使用 <code>-m</code> 选项以在命令行中提供提交注释。
</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>
@ -393,10 +424,10 @@ nothing to commit (working directory clean)
".git/COMMIT_EDITMSG" 9L, 257C
</pre>
<p>在此,你在文件头部添加实际的提交信息。以“#”开头的行都会被无视 ——Git 将 <code> git status</code> 的输出结果放在那儿以提示你都改了、缓存了啥。
<p>在此,你在文件头部添加实际的提交信息。以“#”开头的行都会被无视 ——Git 将 <code> git status</code> 的输出结果放在那儿以提示你都改了、缓存了啥。
</p>
<p>通常,撰写良好的提交信息是很重要的。以开放源代码项目为例,多多少少以以下格式写你的提示消息是个不成文的规定:
<p>通常,撰写良好的提交信息是很重要的。以开放源代码项目为例,多多少少以以下格式写你的提示消息是个不成文的规定:
</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> 永久地保存快照。
</p>
<p>
现在你就完成了整个快照的流程 ——改些文件,然后用 <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>
@ -508,19 +554,24 @@ M hello.rb
<span class="red">M</span> hello.rb
</pre>
<p>
现在你执行 <code>git commit</code> 将只记录 <code>README</code> 文件的改动,并不含现在并不在缓存中的 <code>hello.rb</code>
<p>
现在你执行 <code>git commit</code> 将只记录 <code>README</code> 文件的改动,并不含现在并不在缓存中的 <code>hello.rb</code>
</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>
@ -553,12 +604,15 @@ M hello.rb
<div class="block">
<p>
<code>git rm</code> 会将条目从缓存区中移除。这与 <code>git reset HEAD</code> 将条目取消缓存是有区别的。“取消缓存”的意思就是将缓存区恢复为我们做出修改之前的样子。在另一方面,<code>git rm</code> 则将该文件彻底从缓存区踢出,因此它不再下一个提交快照之内,进而有效地删除它。
</p>
<p>
<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>
<p>
默认情况下,<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>

@ -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>
@ -66,7 +78,7 @@ $ git branch
<small>创建新分支</small>
</h4>
<p>我们动手创建一个分支,并切换过去。执行 <code>git branch (branchname)</code> 即可。
<p>我们动手创建一个分支,并切换过去。执行 <code>git branch (branchname)</code> 即可。
<pre>
$ git branch testing
@ -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>
@ -225,7 +254,7 @@ end
HelloWorld.hello
</pre>
<p>首先我们创建一个叫做“change_class”的分支切换过去从而将重命名类等操作独立出来。我们将类名从 “HelloWorld” 改为 “HiWorld”。
<p>首先我们创建一个叫做“change_class”的分支切换过去从而将重命名类等操作独立出来。我们将类名从 “HelloWorld” 改为 “HiWorld”。
</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,8 +299,10 @@ index 2aabb6e..bf64b17 100644
rename hello.rb => ruby.rb (65%)
</pre>
<p>现在这些改变已经记录到我的 “master” 分支了。请注意,这里类名还是 “HelloWorld”而不是 “HiWorld”。然后我想将类名的改变合并过来我把 “change_class” 分支合并过来就行了。但是我已经将文件名都改掉了Git 知道该怎么办么?
</p>
<p>现在这些改变已经记录到我的 “master” 分支了。请注意,这里类名还是 “HelloWorld”而不是 “HiWorld”。
然后我想将类名的改变合并过来,我把 “change_class” 分支合并过来就行了。
但是我已经将文件名都改掉了Git 知道该怎么办么?
</p>
<pre>
<b>$ git branch</b>
@ -297,7 +331,9 @@ HiWorld.hello
合并冲突
</h4>
<p>那么Git 合并很有魔力,我们再也不用处理合并冲突了,对吗?不太确切。不同分支中修改了相同区块的代码,电脑自己猜不透神马的情况下,冲突就摆在我们面前了。我们看看两个分支中改了同一行代码的例子。
<p>那么Git 合并很有魔力,我们再也不用处理合并冲突了,对吗?不太确切。
不同分支中修改了相同区块的代码,电脑自己猜不透神马的情况下,冲突就摆在我们面前了。
我们看看两个分支中改了同一行代码的例子。
<p>
<pre>
@ -311,7 +347,7 @@ Switched to a new branch 'fix_readme'
1 files changed, 1 insertions(+), 1 deletions(-)
</pre>
<p>我们在某分支中修改了 README 文件中的一行,并提交了。我们再在 “master” 分支中对同个文件的同一行内容作不同的修改。
<p>我们在某分支中修改了 README 文件中的一行,并提交了。我们再在 “master” 分支中对同个文件的同一行内容作不同的修改。
</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>
@ -438,7 +486,7 @@ Date: Fri Jun 4 12:37:05 2010 +0200
...
</pre>
<p>我们可以用 <code>--oneline</code> 选项来查看历史记录的紧凑简洁的版本。
<p>我们可以用 <code>--oneline</code> 选项来查看历史记录的紧凑简洁的版本。
</p>