1
0
mirror of https://github.com/k88hudson/git-flight-rules.git synced 2025-06-16 21:01:45 -03:00

80 Commits

Author SHA1 Message Date
a5d990376f Add the rest of the commands 2017-12-19 19:46:59 -05:00
60b1b583a9 Adding submodule section 2017-12-19 19:46:59 -05:00
da44b4d6c1 add the usage information for for git-branch --set-upstream-to (#176)
* add application for git-branch --set-upstream-to

* run doctoc - typo in one line for the TOC

* put note in bash comment
2017-12-18 09:03:33 -05:00
da6f0f8e66 Branches - list branches (#171) 2017-12-16 11:50:00 -05:00
d6d5c6f920 fix a typo (#170) 2017-12-13 10:12:23 -05:00
4a6f537157 Merge pull request #166 from k88hudson/feat/set-head
Add an example using `set-head`
2017-12-12 13:06:54 -03:00
8d74313257 Add reset-author and no-edit to author rewriting (#169) 2017-12-12 08:56:52 -05:00
418f0a0032 Added new topic: Finding (#168)
* New Topic for 'Finding'

Added command which can be used to find a string in any commit

* Added command that can be used to find for commits either by author or committer

* Fixed link
2017-12-10 14:08:44 -05:00
472f05caf0 Added section with links to every language (#167) 2017-12-10 14:07:30 -05:00
7a68447ac9 Add an example using set-head
This is just one of many possible examples using set-head, but which might be useful for others to discover the command.
2017-12-08 15:39:07 -05:00
12bc63375d A few cleanups (#163)
* Consolidate the name of the subsystem

The name of the subsytem is considered to be 'Git' and not 'git'.
There was inconsistency in the document by referring to the subsystem
using both 'git' and 'Git'.

Consolidate the usages to 'Git' which is generally considered to be
the name of the subsystem.

* Consolidate the name of GitHub

They website is generally called 'GitHub' and not 'github'.

* Quote the git commands correctly

* Avoid fullstops in section names

This is done for the sake of consistency. Most of the section names
don't have a fullstop at the end.

So, ...

* Update the ToC

The Table of Contents seems to have been out of date with the section
titles.

So, update the ToC with 'doctoc'.

* Clarify that the changes are removed only for the previous commit

* Showcase the flexibility of `git fetch -p`

The example for that exhibits the way to 'prune' remote branches that
were deleted upstream wasn't flexible as it relied on the command
defaulting to the upstream of the current branch. This might lead
the reader into overlooking the flexibility of the `git fetch`.

Show that the 'upstream' can be mentioned in the command thus show
casing the flexibility of `git fetch`.

* Exemplify the safer version of branch deletion

It's not good for newbies to start using 'force deletion' when they
want to delete a branch as it might lead them to them into
'accidentally' deleting their branches often without merging them
into other branches or pushing them to an upstream.

So, exemplify the safer version of branch deletion (branch -d) and
warn them about what `git branch -D` does.

* Improve readability of a few phrases

It's not required to use 'git' a lot as this a document about Git,
after all.

* Use HTTPS links for sites that serve using HTTPS

* Clarify that rebasing just re-writes history

Rebasing fast-forwards when the tip of the branch is a descendent of
the tip of the upstream. In other cases it re-writes the history. This
re-write is what actually leads the user to 'force' update the remote.

So, clarify that a user has to force update only when the history is
re-written regardless of whether the branch was fast-forwarded.

* Attribute both the authors of the second edition of Pro Git

* Try a different form of emphasizing text

Capitalizing words seems to be over emphasizing words. Italicize
the words, instead to see if works.

* Mention what 'upstream' means for the sake of clarity

* Simplify the way to create a remote branch from the local one

The commands were needlessly complex by not considering the fact
that the command defaults to HEAD when no branch is specified and
changing configuration when it wasn't required.

Simplify the commands to make readers more happy!

* Remove a character cruft left over while editing

This is an instance of a carelessly edited document getting into
version control. ;)

* Improve a sentence

... by,

- expanding acronyms
- quoting a command line parameter
2017-12-08 11:47:41 -05:00
565b8259da Update Russian translations up to English source (#165) 2017-12-07 15:18:06 -05:00
0e478ad4cc Show how a newly added file can be removed (#164)
This shows how the user can remove a newly added file from the
previous commit.
2017-12-04 15:57:20 -05:00
231b474600 Discarding staged changes vs unstaged changes - commands corrected (#159)
* Discarding staged changes vs unstaged changes - commands corrected

* added space between word and parenthesis

* Added <a> tag and TOC for content

* adding missing backticks

* Updated links in staging section
2017-12-03 11:57:20 -05:00
02e357c5b4 Added russian translations (#161) 2017-12-02 15:09:14 -05:00
c128fff050 Iss-150: Fixed section about discarding local uncommitted changes (#160)
Iss-150: minor fix
2017-11-30 16:28:13 -05:00
5eaca03df3 Merge pull request #158 from juanca87/git-merge-abort
Added command to abort the merge
2017-11-28 11:14:27 -03:00
045015f66d Update README.md
Added a link to the description to abort the merge
2017-11-28 10:52:16 -03:00
5fc6b2289d Added command to abort the merge 2017-11-28 00:02:58 -03:00
f4c0fac6ef Add safety note for git reset --hard (#157)
resolves #155
2017-11-27 15:44:52 -05:00
7440fa32b5 Discard local uncommitted changes (#156) 2017-11-27 13:30:38 -05:00
02043187a7 Add githug (#152)
* Add githug

Githug is a great interactive game for leaning git

* Update README.md
2017-11-26 19:01:08 -05:00
7cdaca391f Added some common Git screwups and solutions (#148)
* Added some common Git screwups and solutions

* Added required changes

* Added another way to create new remote branch

* Added required changes

* Added required changes

* Added  required changes

* Added required changes
2017-11-26 19:00:03 -05:00
8426f177dd Fix #149 @RichardLitt comment
Fix #149 PR merged
2017-11-23 21:41:39 -03:00
71f2ab2917 Merge pull request #149 from flexdinesh/master
flight-rule to stash multiple files at once
2017-11-23 12:05:22 -03:00
4bf16453c6 flight-rule to stash multiple files at once 2017-11-23 01:11:14 +05:30
7412b89d42 Merge pull request #147 from benyanke/patch-1
Added gitk
2017-11-21 16:33:36 -05:00
11c11ecc21 Update README.md 2017-11-21 13:23:03 -06:00
5088d30821 Add sample of -u option of git stash (#146) 2017-11-21 13:13:31 -05:00
adb5a2d250 added command to create a branch from a commit (#145)
Using this command one can create a branch from a specific commit from current branch.
2017-11-20 13:51:04 -05:00
4cb52c015c fix typo (#142) 2017-11-19 12:56:54 -05:00
9dafe52a63 fix typo (#141) 2017-11-19 12:56:42 -05:00
2e5498cd5c New Topic for 'Stashing' and curated frequent stash workflow (#140) 2017-11-19 03:34:21 -05:00
5599a75b7f added another command to see staged diff (#139)
This command is an alternative to view all the changes in the staged files.
2017-11-18 13:56:47 -05:00
b7d9be9af9 stash content with a custom message (#138)
Added command which can be used to stash code marked with a custom message
2017-11-18 10:03:11 -05:00
2637bf010f Add fork and gmaster (#137)
* add fork

* add fork
2017-11-16 15:34:47 -05:00
f506073152 change [aliases] to [alias] (#136)
* change [aliases] to [alias]

Titling the section `aliases` did not work for me. Changing to `[alias]` worked immediately.

Reference: https://git-scm.com/docs/git-config#git-config-alias

* Update README_zh-cn.md
2017-11-15 10:57:11 -05:00
e51ba1db7d fix formatting 2017-11-15 09:08:38 -05:00
b838720631 Be more specific about HEAD^ vs HEAD~ (#122)
* Be more specific about HEAD^ vs HEAD~

* add more

* revise again
2017-11-15 09:08:04 -05:00
b244c00a4e Add Note About --ours and --theirs (#133)
* add note about --ours and --theirs

* correct error message, add more detail on ours/theirs
2017-11-14 14:36:22 -05:00
fc459528ea Revert a file to a specific revision (#131) 2017-11-13 09:09:15 -05:00
a38b385b03 Merge branch 'toptal-more-specific-removal-of-a-file-from-commit' 2017-11-12 10:31:53 -05:00
186ed0a1e4 docs: small grammar fix 2017-11-12 10:31:50 -05:00
f60cd9d835 Change command to avoid editing commit message 2017-11-12 18:16:13 +03:00
103e920531 Add fetching a GitHub PR ref directly (#129) 2017-11-12 08:10:33 -05:00
e2ddb7fe55 Added how to rename a local branch (#128) 2017-11-11 09:11:26 -05:00
4547f3ea98 Add git extensions to GUI Clients 2017-11-10 16:50:28 -05:00
17bf6d7cbd Add Magit (#126) 2017-11-10 16:30:45 -05:00
76361c407f Fix minor typo (#124) 2017-11-10 16:04:58 -05:00
545a53e808 Change the command to minimize side effects 2017-11-10 19:18:27 +03:00
88e905a4c2 Add Chinese translation (#121) 2017-11-09 08:18:10 -05:00
9f0a1d2ae3 Recommend --force-with-lease instead of --force (#117) 2017-11-07 09:19:44 -05:00
4a654bd90a Add Tig to the list of clients (#116)
* Update README.md

* Update README.md
2017-11-07 07:58:24 -05:00
cf82e4d95e Merge pull request #115 from k88hudson/license
fix #112: Add cc-by-sa-4.0 license
2017-11-06 21:07:24 -05:00
1e80224456 Merge pull request #114 from arnavb/update-text
Minor Text Update
2017-11-06 20:16:13 -05:00
4bc70b6aab fix #112: Add cc-by-sa-4.0 license 2017-11-06 20:13:25 -05:00
7f2a4bfd03 Minor text update 2017-11-06 20:09:42 -05:00
7ebe86b76e Merge pull request #113 from Shayac/master
add learngitbranching tutorial
2017-11-06 19:42:30 -05:00
1883097a8b add learngitbranching tutorial 2017-11-06 19:22:35 -05:00
bfb67fc369 Merge pull request #111 from Shayac/master
Add Scott Chacon's other git book
2017-11-06 19:06:43 -05:00
20bb62b971 Add another git book 2017-11-06 18:25:54 -05:00
868005ed17 Merge pull request #109 from e-larrambebere/master
Fixes minor style issues
2017-11-06 08:42:43 -05:00
688ab59c2c Merge pull request #108 from thomasyimgit/checkout-remote-branch
add checkout to remote branch
2017-11-06 08:42:19 -05:00
051e40b042 Fixes minor style issues
Adds some missing closure tags to the section anchors. This was causing some issues rendering the README
2017-11-06 09:12:56 +00:00
485bcf6691 add checkout to remote branch 2017-11-05 21:02:03 -05:00
2a86ef478e Merge branch 'pr/106' 2017-06-05 12:08:59 +01:00
51d78e43c5 Adding stashes back in 2017-06-05 12:08:56 +01:00
998dd0c7fb Add git-town, alphabetize 2017-05-24 14:50:55 +01:00
542884da13 Improve "discard specific unstaged changes" steps 2017-04-09 16:20:44 +08:00
f3428ed7af Merge pull request #105 from Plsr/master
Use 'branch' instead of 'checkout -b'
2017-03-29 16:13:45 -04:00
5af92eed17 Use 'branch' instead of 'checkout -b' 2017-03-29 11:55:42 +02:00
a5d7eea0d5 Merge pull request #104 from camilortte/patch-1
Add Git Gui Client (GitKraken)
2017-01-16 14:40:08 -03:00
36c28e5ec2 Add Git Gui Cloent GitKraken 2017-01-11 16:46:43 -05:00
1cb8a5798f Merge pull request #102 from gaetan-petit/patch-1
ADD undo rebase/merge
2017-01-09 21:10:44 +01:00
5bad85aeba Update README.md 2017-01-08 00:32:15 +01:00
c89b20a3fe Merge pull request #101 from k88hudson/feat/staging-the-unstaged
Added section on staging and unstaging
2017-01-06 23:49:40 +01:00
bad1b36f56 Merge pull request #103 from codeofcarson/master
Add a new rule, how to discard specific unstaged changes
2016-12-29 15:39:13 -05:00
eb48bfc8ba add a new rule, how to discard specific unstaged changes 2016-12-29 15:34:11 -05:00
9478da7964 Update README.md 2016-12-21 17:43:59 +01:00
2b34d20485 ADD undo rebase/merge
Please correct my broken english :)
2016-12-21 17:42:00 +01:00
4 changed files with 3306 additions and 74 deletions

427
LICENSE Normal file
View File

@ -0,0 +1,427 @@
Attribution-ShareAlike 4.0 International
=======================================================================
Creative Commons Corporation ("Creative Commons") is not a law firm and
does not provide legal services or legal advice. Distribution of
Creative Commons public licenses does not create a lawyer-client or
other relationship. Creative Commons makes its licenses and related
information available on an "as-is" basis. Creative Commons gives no
warranties regarding its licenses, any material licensed under their
terms and conditions, or any related information. Creative Commons
disclaims all liability for damages resulting from their use to the
fullest extent possible.
Using Creative Commons Public Licenses
Creative Commons public licenses provide a standard set of terms and
conditions that creators and other rights holders may use to share
original works of authorship and other material subject to copyright
and certain other rights specified in the public license below. The
following considerations are for informational purposes only, are not
exhaustive, and do not form part of our licenses.
Considerations for licensors: Our public licenses are
intended for use by those authorized to give the public
permission to use material in ways otherwise restricted by
copyright and certain other rights. Our licenses are
irrevocable. Licensors should read and understand the terms
and conditions of the license they choose before applying it.
Licensors should also secure all rights necessary before
applying our licenses so that the public can reuse the
material as expected. Licensors should clearly mark any
material not subject to the license. This includes other CC-
licensed material, or material used under an exception or
limitation to copyright. More considerations for licensors:
wiki.creativecommons.org/Considerations_for_licensors
Considerations for the public: By using one of our public
licenses, a licensor grants the public permission to use the
licensed material under specified terms and conditions. If
the licensor's permission is not necessary for any reason--for
example, because of any applicable exception or limitation to
copyright--then that use is not regulated by the license. Our
licenses grant only permissions under copyright and certain
other rights that a licensor has authority to grant. Use of
the licensed material may still be restricted for other
reasons, including because others have copyright or other
rights in the material. A licensor may make special requests,
such as asking that all changes be marked or described.
Although not required by our licenses, you are encouraged to
respect those requests where reasonable. More_considerations
for the public:
wiki.creativecommons.org/Considerations_for_licensees
=======================================================================
Creative Commons Attribution-ShareAlike 4.0 International Public
License
By exercising the Licensed Rights (defined below), You accept and agree
to be bound by the terms and conditions of this Creative Commons
Attribution-ShareAlike 4.0 International Public License ("Public
License"). To the extent this Public License may be interpreted as a
contract, You are granted the Licensed Rights in consideration of Your
acceptance of these terms and conditions, and the Licensor grants You
such rights in consideration of benefits the Licensor receives from
making the Licensed Material available under these terms and
conditions.
Section 1 -- Definitions.
a. Adapted Material means material subject to Copyright and Similar
Rights that is derived from or based upon the Licensed Material
and in which the Licensed Material is translated, altered,
arranged, transformed, or otherwise modified in a manner requiring
permission under the Copyright and Similar Rights held by the
Licensor. For purposes of this Public License, where the Licensed
Material is a musical work, performance, or sound recording,
Adapted Material is always produced where the Licensed Material is
synched in timed relation with a moving image.
b. Adapter's License means the license You apply to Your Copyright
and Similar Rights in Your contributions to Adapted Material in
accordance with the terms and conditions of this Public License.
c. BY-SA Compatible License means a license listed at
creativecommons.org/compatiblelicenses, approved by Creative
Commons as essentially the equivalent of this Public License.
d. Copyright and Similar Rights means copyright and/or similar rights
closely related to copyright including, without limitation,
performance, broadcast, sound recording, and Sui Generis Database
Rights, without regard to how the rights are labeled or
categorized. For purposes of this Public License, the rights
specified in Section 2(b)(1)-(2) are not Copyright and Similar
Rights.
e. Effective Technological Measures means those measures that, in the
absence of proper authority, may not be circumvented under laws
fulfilling obligations under Article 11 of the WIPO Copyright
Treaty adopted on December 20, 1996, and/or similar international
agreements.
f. Exceptions and Limitations means fair use, fair dealing, and/or
any other exception or limitation to Copyright and Similar Rights
that applies to Your use of the Licensed Material.
g. License Elements means the license attributes listed in the name
of a Creative Commons Public License. The License Elements of this
Public License are Attribution and ShareAlike.
h. Licensed Material means the artistic or literary work, database,
or other material to which the Licensor applied this Public
License.
i. Licensed Rights means the rights granted to You subject to the
terms and conditions of this Public License, which are limited to
all Copyright and Similar Rights that apply to Your use of the
Licensed Material and that the Licensor has authority to license.
j. Licensor means the individual(s) or entity(ies) granting rights
under this Public License.
k. Share means to provide material to the public by any means or
process that requires permission under the Licensed Rights, such
as reproduction, public display, public performance, distribution,
dissemination, communication, or importation, and to make material
available to the public including in ways that members of the
public may access the material from a place and at a time
individually chosen by them.
l. Sui Generis Database Rights means rights other than copyright
resulting from Directive 96/9/EC of the European Parliament and of
the Council of 11 March 1996 on the legal protection of databases,
as amended and/or succeeded, as well as other essentially
equivalent rights anywhere in the world.
m. You means the individual or entity exercising the Licensed Rights
under this Public License. Your has a corresponding meaning.
Section 2 -- Scope.
a. License grant.
1. Subject to the terms and conditions of this Public License,
the Licensor hereby grants You a worldwide, royalty-free,
non-sublicensable, non-exclusive, irrevocable license to
exercise the Licensed Rights in the Licensed Material to:
a. reproduce and Share the Licensed Material, in whole or
in part; and
b. produce, reproduce, and Share Adapted Material.
2. Exceptions and Limitations. For the avoidance of doubt, where
Exceptions and Limitations apply to Your use, this Public
License does not apply, and You do not need to comply with
its terms and conditions.
3. Term. The term of this Public License is specified in Section
6(a).
4. Media and formats; technical modifications allowed. The
Licensor authorizes You to exercise the Licensed Rights in
all media and formats whether now known or hereafter created,
and to make technical modifications necessary to do so. The
Licensor waives and/or agrees not to assert any right or
authority to forbid You from making technical modifications
necessary to exercise the Licensed Rights, including
technical modifications necessary to circumvent Effective
Technological Measures. For purposes of this Public License,
simply making modifications authorized by this Section 2(a)
(4) never produces Adapted Material.
5. Downstream recipients.
a. Offer from the Licensor -- Licensed Material. Every
recipient of the Licensed Material automatically
receives an offer from the Licensor to exercise the
Licensed Rights under the terms and conditions of this
Public License.
b. Additional offer from the Licensor -- Adapted Material.
Every recipient of Adapted Material from You
automatically receives an offer from the Licensor to
exercise the Licensed Rights in the Adapted Material
under the conditions of the Adapter's License You apply.
c. No downstream restrictions. You may not offer or impose
any additional or different terms or conditions on, or
apply any Effective Technological Measures to, the
Licensed Material if doing so restricts exercise of the
Licensed Rights by any recipient of the Licensed
Material.
6. No endorsement. Nothing in this Public License constitutes or
may be construed as permission to assert or imply that You
are, or that Your use of the Licensed Material is, connected
with, or sponsored, endorsed, or granted official status by,
the Licensor or others designated to receive attribution as
provided in Section 3(a)(1)(A)(i).
b. Other rights.
1. Moral rights, such as the right of integrity, are not
licensed under this Public License, nor are publicity,
privacy, and/or other similar personality rights; however, to
the extent possible, the Licensor waives and/or agrees not to
assert any such rights held by the Licensor to the limited
extent necessary to allow You to exercise the Licensed
Rights, but not otherwise.
2. Patent and trademark rights are not licensed under this
Public License.
3. To the extent possible, the Licensor waives any right to
collect royalties from You for the exercise of the Licensed
Rights, whether directly or through a collecting society
under any voluntary or waivable statutory or compulsory
licensing scheme. In all other cases the Licensor expressly
reserves any right to collect such royalties.
Section 3 -- License Conditions.
Your exercise of the Licensed Rights is expressly made subject to the
following conditions.
a. Attribution.
1. If You Share the Licensed Material (including in modified
form), You must:
a. retain the following if it is supplied by the Licensor
with the Licensed Material:
i. identification of the creator(s) of the Licensed
Material and any others designated to receive
attribution, in any reasonable manner requested by
the Licensor (including by pseudonym if
designated);
ii. a copyright notice;
iii. a notice that refers to this Public License;
iv. a notice that refers to the disclaimer of
warranties;
v. a URI or hyperlink to the Licensed Material to the
extent reasonably practicable;
b. indicate if You modified the Licensed Material and
retain an indication of any previous modifications; and
c. indicate the Licensed Material is licensed under this
Public License, and include the text of, or the URI or
hyperlink to, this Public License.
2. You may satisfy the conditions in Section 3(a)(1) in any
reasonable manner based on the medium, means, and context in
which You Share the Licensed Material. For example, it may be
reasonable to satisfy the conditions by providing a URI or
hyperlink to a resource that includes the required
information.
3. If requested by the Licensor, You must remove any of the
information required by Section 3(a)(1)(A) to the extent
reasonably practicable.
b. ShareAlike.
In addition to the conditions in Section 3(a), if You Share
Adapted Material You produce, the following conditions also apply.
1. The Adapter's License You apply must be a Creative Commons
license with the same License Elements, this version or
later, or a BY-SA Compatible License.
2. You must include the text of, or the URI or hyperlink to, the
Adapter's License You apply. You may satisfy this condition
in any reasonable manner based on the medium, means, and
context in which You Share Adapted Material.
3. You may not offer or impose any additional or different terms
or conditions on, or apply any Effective Technological
Measures to, Adapted Material that restrict exercise of the
rights granted under the Adapter's License You apply.
Section 4 -- Sui Generis Database Rights.
Where the Licensed Rights include Sui Generis Database Rights that
apply to Your use of the Licensed Material:
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
to extract, reuse, reproduce, and Share all or a substantial
portion of the contents of the database;
b. if You include all or a substantial portion of the database
contents in a database in which You have Sui Generis Database
Rights, then the database in which You have Sui Generis Database
Rights (but not its individual contents) is Adapted Material,
including for purposes of Section 3(b); and
c. You must comply with the conditions in Section 3(a) if You Share
all or a substantial portion of the contents of the database.
For the avoidance of doubt, this Section 4 supplements and does not
replace Your obligations under this Public License where the Licensed
Rights include other Copyright and Similar Rights.
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
c. The disclaimer of warranties and limitation of liability provided
above shall be interpreted in a manner that, to the extent
possible, most closely approximates an absolute disclaimer and
waiver of all liability.
Section 6 -- Term and Termination.
a. This Public License applies for the term of the Copyright and
Similar Rights licensed here. However, if You fail to comply with
this Public License, then Your rights under this Public License
terminate automatically.
b. Where Your right to use the Licensed Material has terminated under
Section 6(a), it reinstates:
1. automatically as of the date the violation is cured, provided
it is cured within 30 days of Your discovery of the
violation; or
2. upon express reinstatement by the Licensor.
For the avoidance of doubt, this Section 6(b) does not affect any
right the Licensor may have to seek remedies for Your violations
of this Public License.
c. For the avoidance of doubt, the Licensor may also offer the
Licensed Material under separate terms or conditions or stop
distributing the Licensed Material at any time; however, doing so
will not terminate this Public License.
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
License.
Section 7 -- Other Terms and Conditions.
a. The Licensor shall not be bound by any additional or different
terms or conditions communicated by You unless expressly agreed.
b. Any arrangements, understandings, or agreements regarding the
Licensed Material not stated herein are separate from and
independent of the terms and conditions of this Public License.
Section 8 -- Interpretation.
a. For the avoidance of doubt, this Public License does not, and
shall not be interpreted to, reduce, limit, restrict, or impose
conditions on any use of the Licensed Material that could lawfully
be made without permission under this Public License.
b. To the extent possible, if any provision of this Public License is
deemed unenforceable, it shall be automatically reformed to the
minimum extent necessary to make it enforceable. If the provision
cannot be reformed, it shall be severed from this Public License
without affecting the enforceability of the remaining terms and
conditions.
c. No term or condition of this Public License will be waived and no
failure to comply consented to unless expressly agreed to by the
Licensor.
d. Nothing in this Public License constitutes or may be interpreted
as a limitation upon, or waiver of, any privileges and immunities
that apply to the Licensor or You, including from the legal
processes of any jurisdiction or authority.
=======================================================================
Creative Commons is not a party to its public
licenses. Notwithstanding, Creative Commons may elect to apply one of
its public licenses to material it publishes and in those instances
will be considered the “Licensor.” The text of the Creative Commons
public licenses is dedicated to the public domain under the CC0 Public
Domain Dedication. Except for the limited purpose of indicating that
material is shared under a Creative Commons public license or as
otherwise permitted by the Creative Commons policies published at
creativecommons.org/policies, Creative Commons does not authorize the
use of the trademark "Creative Commons" or any other trademark or logo
of Creative Commons without its prior written consent including,
without limitation, in connection with any unauthorized modifications
to any of its public licenses or any other arrangements,
understandings, or agreements concerning use of licensed material. For
the avoidance of doubt, this paragraph does not form part of the
public licenses.
Creative Commons may be contacted at creativecommons.org.

634
README.md
View File

@ -1,8 +1,11 @@
# Flight rules for git
# Flight rules for Git
🌍
*[English](README.md) ∙ [Русский](README_ru.md) ∙ [简体中文](README_zh-cn.md)*
#### What are "flight rules"?
A [guide for astronauts](http://www.jsc.nasa.gov/news/columbia/fr_generic.pdf) (now, programmers using git) about what to do when things go wrong.
A [guide for astronauts](https://www.jsc.nasa.gov/news/columbia/fr_generic.pdf) (now, programmers using Git) about what to do when things go wrong.
> *Flight Rules* are the hard-earned body of knowledge recorded in manuals that list, step-by-step, what to do if X occurs, and why. Essentially, they are extremely detailed, scenario-specific standard operating procedures. [...]
@ -23,7 +26,7 @@ For clarity's sake all examples in this document use a customized bash prompt in
- [What did I just commit?](#what-did-i-just-commit)
- [I wrote the wrong thing in a commit message](#i-wrote-the-wrong-thing-in-a-commit-message)
- [I committed with the wrong name and email configured](#i-committed-with-the-wrong-name-and-email-configured)
- [I want to remove a file from a commit](#i-want-to-remove-a-file-from-a-commit)
- [I want to remove a file from the previous commit](#i-want-to-remove-a-file-from-the-previous-commit)
- [I want to delete or remove my last commit](#i-want-to-delete-or-remove-my-last-commit)
- [Delete/remove arbitrary commit](#deleteremove-arbitrary-commit)
- [I tried to push my amended commit to a remote, but I got an error message](#i-tried-to-push-my-amended-commit-to-a-remote-but-i-got-an-error-message)
@ -36,8 +39,14 @@ For clarity's sake all examples in this document use a customized bash prompt in
- [Unstaged Edits](#unstaged-edits)
- [I want to move my unstaged edits to a new branch](#i-want-to-move-my-unstaged-edits-to-a-new-branch)
- [I want to move my unstaged edits to a different, existing branch](#i-want-to-move-my-unstaged-edits-to-a-different-existing-branch)
- [I want to discard my local, uncommitted changes](#i-want-to-discard-my-local-uncommitted-changes)
- [I want to discard my local uncommitted changes (staged and unstaged)](#i-want-to-discard-my-local-uncommitted-changes-staged-and-unstaged)
- [I want to discard specific unstaged changes](#i-want-to-discard-specific-unstaged-changes)
- [I want to discard specific unstaged files](#i-want-to-discard-specific-unstaged-files)
- [I want to discard only my unstaged local changes](#i-want-to-discard-only-my-unstaged-local-changes)
- [I want to discard all of my untracked files](#i-want-to-discard-all-of-my-untracked-files)
- [Branches](#branches)
- [I want to list all branches](#i-want-to-list-all-branches)
- [Create a branch from a commit](#create-a-branch-from-a-commit)
- [I pulled from/into the wrong branch](#i-pulled-frominto-the-wrong-branch)
- [I want to discard local commits so my branch is the same as one on the server](#i-want-to-discard-local-commits-so-my-branch-is-the-same-as-one-on-the-server)
- [I committed to master instead of a new branch](#i-committed-to-master-instead-of-a-new-branch)
@ -46,27 +55,50 @@ For clarity's sake all examples in this document use a customized bash prompt in
- [I want to delete local branches that were deleted upstream](#i-want-to-delete-local-branches-that-were-deleted-upstream)
- [I accidentally deleted my branch](#i-accidentally-deleted-my-branch)
- [I want to delete a branch](#i-want-to-delete-a-branch)
- [I want to rename a branch](#i-want-to-rename-a-branch)
- [I want to checkout to a remote branch that someone else is working on](#i-want-to-checkout-to-a-remote-branch-that-someone-else-is-working-on)
- [I want to create a new remote branch from current local one](#i-want-to-create-a-new-remote-branch-from-current-local-one)
- [I want to set a remote branch as the upstream for a local branch](#i-want-to-set-a-remote-branch-as-the-upstream-for-a-local-branch)
- [I want to set my HEAD to track the default remote branch](#i-want-to-set-my-head-to-track-the-default-remote-branch)
- [Rebasing and Merging](#rebasing-and-merging)
- [I rebased, but I don't want to force push.](#i-rebased-but-i-dont-want-to-force-push)
- [I want to undo rebase/merge](#i-want-to-undo-rebasemerge)
- [I rebased, but I don't want to force push](#i-rebased-but-i-dont-want-to-force-push)
- [I need to combine commits](#i-need-to-combine-commits)
- [Safe merging strategy](#safe-merging-strategy)
- [I need to merge a branch into a single commit](#i-need-to-merge-a-branch-into-a-single-commit)
- [I want to combine only unpushed commits](#i-want-to-combine-only-unpushed-commits)
- [I need to abort the merge](#i-need-to-abort-the-merge)
- [Check if all commits on a branch are merged](#check-if-all-commits-on-a-branch-are-merged)
- [Possible issues with interactive rebases](#possible-issues-with-interactive-rebases)
- [The rebase editing screen says 'noop'](#the-rebase-editing-screen-says-noop)
- [There were conflicts](#there-were-conflicts)
- [Miscellaneous Objects](#miscellaneous-objects)
- [Stash](#stash)
- [Stash all edits](#stash-all-edits)
- [Stash specific files](#stash-specific-files)
- [Stash with message](#stash-with-message)
- [Apply a specific stash from list](#apply-a-specific-stash-from-list)
- [Finding](#finding)
- [I want to find a string in any commit](#i-want-to-find-a-string-in-any-commit)
- [I want to find by author/committer](#i-want-to-find-by-authorcommitter)
- [Submodules](#submodules)
- [Clone all submodules](#clone-all-submodules)
- [Remove a submodule](#remove-a-submodule)
- [Miscellaneous Objects](#miscellaneous-objects)
- [Restore a deleted file](#restore-a-deleted-file)
- [Delete tag](#delete-tag)
- [Recover a deleted tag](#recover-a-deleted-tag)
- [Deleted Patch](#deleted-patch)
- [Exporting a repository as a Zip file](#exporting-a-repository-as-a-zip-file)
- [Tracking Files](#tracking-files)
- [I want to change a file name's capitalization, without changing the contents of the file.](#i-want-to-change-a-file-names-capitalization-without-changing-the-contents-of-the-file)
- [I want to remove a file from git but keep the file](#i-want-to-remove-a-file-from-git-but-keep-the-file)
- [I want to change a file name's capitalization, without changing the contents of the file](#i-want-to-change-a-file-names-capitalization-without-changing-the-contents-of-the-file)
- [I want to overwrite local files when doing a git pull](#i-want-to-overwrite-local-files-when-doing-a-git-pull)
- [I want to remove a file from Git but keep the file](#i-want-to-remove-a-file-from-git-but-keep-the-file)
- [I want to revert a file to a specific revision](#i-want-to-revert-a-file-to-a-specific-revision)
- [Configuration](#configuration)
- [I want to add aliases for some git commands](#i-want-to-add-aliases-for-some-git-commands)
- [I want to add aliases for some Git commands](#i-want-to-add-aliases-for-some-git-commands)
- [I want to add an empty directory to my repository](#i-want-to-add-an-empty-directory-to-my-repository)
- [I want to cache a username and password for a repository](#i-want-to-cache-a-username-and-password-for-a-repository)
- [I want to make Git ignore permissions and filemode changes](#i-want-to-make-git-ignore-permissions-and-filemode-changes)
- [I've no idea what I did wrong](#ive-no-idea-what-i-did-wrong)
- [Other Resources](#other-resources)
- [Books](#books)
@ -88,12 +120,18 @@ Let's say that you just blindly committed changes with `git commit -a` and you'r
(master)$ git show
```
or
Or
```sh
$ git log -n1 -p
```
If you want to see a file at a specific commit, you can also do this (where `<commitid>` is the commit you're interested in):
```sh
$ git show <commitid>:filename
```
<a name="#i-wrote-the-wrong-thing-in-a-commit-message"></a>
### I wrote the wrong thing in a commit message
@ -102,8 +140,7 @@ If you wrote the wrong thing and the commit has not yet been pushed, you can do
```sh
$ git commit --amend
```
You can specify the commit message inline if you want:
This will open your default text editor, where you can edit the message. On the other hand, you can do this all in one command:
```sh
$ git commit --amend -m 'xxxxxxx'
@ -117,24 +154,37 @@ If you have already pushed the message, you can amend the commit and force push,
If it's a single commit, amend it
```sh
$ git commit --amend --author "New Authorname <authoremail@mydomain.com>"
$ git commit --amend --no-edit --author "New Authorname <authoremail@mydomain.com>"
```
If you need to change all of history, see the man page for 'git filter-branch'.
An alternative is to correctly configure your author settings in `git config --global author.(name|email)` and then use
```sh
$ git commit --amend --reset-author --no-edit
```
If you need to change all of history, see the man page for `git filter-branch`.
<a href="#i-want-to-remove-a-file-from-a-commit"></a>
### I want to remove a file from a commit
<a href="#i-want-to-remove-a-file-from-the-previous-commit"></a>
### I want to remove a file from the previous commit
In order to remove a file from a commit, do the following:
In order to remove changes for a file from the previous commit, do the following:
```sh
$ git checkout HEAD^ myfile
$ git add -A
$ git commit --amend
$ git add myfile
$ git commit --amend --no-edit
```
This is particularly useful when you have an open patch and you have committed an unnecessary file, and need to force push to update the patch on a remote.
In case the file was newly added to the commit and you want to remove it (from Git alone), do:
```sh
$ git rm --cached myfile
$ git commit --amend --no-edit
```
This is particularly useful when you have an open patch and you have committed an unnecessary file, and need to force push to update the patch on a remote. The `--no-edit` option is used to keep the existing commit message.
<a name="delete-pushed-commit"></a>
### I want to delete or remove my last commit
@ -143,7 +193,7 @@ If you need to delete pushed commits, you can use the following. However, it wil
```sh
$ git reset HEAD^ --hard
$ git push -f [remote] [branch]
$ git push --force-with-lease [remote] [branch]
```
If you haven't pushed, to reset Git to the state it was in before you made your last commit (while keeping your staged changes):
@ -153,7 +203,7 @@ If you haven't pushed, to reset Git to the state it was in before you made your
```
This only works if you haven't pushed. If you have pushed, the only truly safe thing to do is `git revert SHAofBadCommit`. That will create a new commit that undoes all the previous commit's changes. Or, if the branched you pushed to is rebase-safe (ie. other devs aren't expected to pull from it), you can just use `git push -f`. For more, see [the above section](#deleteremove-last-pushed-commit).
This only works if you haven't pushed. If you have pushed, the only truly safe thing to do is `git revert SHAofBadCommit`. That will create a new commit that undoes all the previous commit's changes. Or, if the branch you pushed to is rebase-safe (ie. other devs aren't expected to pull from it), you can just use `git push --force-with-lease`. For more, see [the above section](#deleteremove-last-pushed-commit).
<a name="delete-any-commit"></a>
### Delete/remove arbitrary commit
@ -162,7 +212,7 @@ The same warning applies as above. Never do this if possible.
```sh
$ git rebase --onto SHA1_OF_BAD_COMMIT^ SHA1_OF_BAD_COMMIT
$ git push -f [remote] [branch]
$ git push --force-with-lease [remote] [branch]
```
Or do an [interactive rebase](#interactive-rebase) and remove the line(s) corresponding to commit(s) you want to see removed.
@ -180,20 +230,23 @@ hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
```
Note that, as with rebasing (see below), amending **replaces the old commit with a new one**, so you must force push (`-f`) your changes if you have already pushed the pre-amended commit to your remote. Be careful when you do this &ndash; *always* make sure you specify a branch!
Note that, as with rebasing (see below), amending **replaces the old commit with a new one**, so you must force push (`--force-with-lease`) your changes if you have already pushed the pre-amended commit to your remote. Be careful when you do this &ndash; *always* make sure you specify a branch!
```sh
(my-branch)$ git push origin mybranch -f
(my-branch)$ git push origin mybranch --force-with-lease
```
In general, **avoid force pushing**. It is best to create and push a new commit rather than force-pushing the amended commit as it has will cause conflicts in the source history for any other developer who has interacted with the branch in question or any child branches.
In general, **avoid force pushing**. It is best to create and push a new commit rather than force-pushing the amended commit as it will cause conflicts in the source history for any other developer who has interacted with the branch in question or any child branches. `--force-with-lease` will still fail, if someone else was also working on the same branch as you, and your push would overwrite those changes.
If you are *absolutely* sure that nobody is working on the same branch or you want to update the tip of the branch *unconditionally*, you can use `--force` (`-f`), but this should be avoided in general.
<a href="undo-git-reset-hard"></a>
### I accidentally did a hard reset, and I want my changes back
If you accidentally do `git reset --hard`, you can normally still get your commit back, as git keeps a log of everything for a few days.
Note: This is only valid if your work is backed up, i.e., either committed or stashed. `git reset --hard` _will remove_ uncommitted modifications, so use it with caution. (A safer option is `git reset --keep`.)
```sh
(master)$ git reflog
```
@ -231,7 +284,8 @@ $ git add --patch filename.x
$ git add -N filename.x
```
Then, you will need to use the `e` option to manually choose which lines to add. Running `git diff --cached` will show you which lines you have staged compared to which are still saved locally.
Then, you will need to use the `e` option to manually choose which lines to add. Running `git diff --cached` or
`git diff --staged` will show you which lines you have staged compared to which are still saved locally.
<a href="stage-in-two-commits"></a>
@ -271,28 +325,137 @@ $ git stash pop
```
<a href="i-want-to-discard-my-local-uncommitted-changes"></a>
### I want to discard my local, uncommitted changes
### I want to discard my local uncommitted changes (staged and unstaged)
If you want to only reset to some commit between origin and your local, you can do this:
If you want to discard all your local staged and unstaged changes, you can do this:
```sh
# one commit
(my-branch)$ git reset --hard HEAD^
# two commits
(my-branch)$ git reset --hard HEAD^^
# four commits
(my-branch)$ git reset --hard HEAD~4
(my-branch)$ git reset --hard
# or
(master)$ git checkout -f
```
To reset only a specific file, you can use that the filename as the argument:
This will unstage all files you might have staged with `git add`:
```sh
$ git reset filename
$ git reset
```
This will revert all local uncommitted changes (should be executed in repo root):
```sh
$ git checkout .
```
You can also revert uncommitted changes to a particular file or directory:
```sh
$ git checkout [some_dir|file.txt]
```
Yet another way to revert all uncommitted changes (longer to type, but works from any subdirectory):
```sh
$ git reset --hard HEAD
```
This will remove all local untracked files, so only files tracked by Git remain:
```sh
$ git clean -fdx
```
WARNING: -x will also remove all ignored files!
<a href="i-want-to-discard-specific-unstaged-changes"></a>
### I want to discard specific unstaged changes
When you want to get rid of some, but not all changes in your working copy.
Checkout undesired changes, keep good changes.
```sh
$ git checkout -p
# Answer y to all of the snippets you want to drop
```
Another strategy involves using `stash`. Stash all the good changes, reset working copy, and reapply good changes.
```sh
$ git stash -p
# Select all of the snippets you want to save
$ git reset --hard
$ git stash pop
```
Alternatively, stash your undesired changes, and then drop stash.
```sh
$ git stash -p
# Select all of the snippets you don't want to save
$ git stash drop
```
<a href="i-want-to-discard-specific-unstaged-files"></a>
### I want to discard specific unstaged files
When you want to get rid of one specific file in your working copy.
```sh
$ git checkout myFile
```
Alternatively, to discard multiple files in your working copy, list them all.
```sh
$ git checkout myFirstFile mySecondFile
```
<a href="i-want-to-discard-only-my-unstaged-local-changes"></a>
### I want to discard only my unstaged local changes
When you want to get rid of all of your unstaged local uncommitted changes
```sh
$ git checkout .
```
<a href="i-want-to-discard-all-my-untracked-files"></a>
### I want to discard all of my untracked files
When you want to get rid of all of your untracked files
```sh
$ git clean -f
```
## Branches
<a name="i-want-to-list-all-branches"></a>
### I want to list all branches
List local branches
```sh
$ git branch
```
List remote branches
```sh
$ git branch -r
```
List all branches (both local and remote)
```sh
$ git branch -a
```
<a name="create-branch-from-commit"></a>
### Create a branch from a commit
```sh
$ git checkout -b <branch> <SHA1_OF_COMMIT>
```
<a name="pull-wrong-branch"></a>
### I pulled from/into the wrong branch
@ -340,9 +503,7 @@ One way of resetting to match origin (to have the same as what is on the remote)
Create the new branch while remaining on master:
```sh
(master)$ git checkout -b my-branch
(my-branch)$ git checkout master
(master)$
(master)$ git branch my-branch
```
Reset the branch master to the previous commit:
@ -351,7 +512,9 @@ Reset the branch master to the previous commit:
(master)$ git reset --hard HEAD^
```
`HEAD^` is short for `HEAD^1`. You can reset further through the generations by specifying which `HEAD` to set to.
`HEAD^` is short for `HEAD^1`. This stands for the first parent of `HEAD`, similarly `HEAD^2` stands for the second parent of the commit (merges can have 2 parents).
Note that `HEAD^2` is **not** the same as `HEAD~2` (see [this link](http://www.paulboxley.com/blog/2011/06/git-caret-and-tilde) for more information).
Alternatively, if you don't want to use `HEAD^`, find out what the commit hash you want to set your master branch to (`git log` should do the trick). Then reset to that hash. `git push` will make sure that this change is reflected on your remote.
@ -472,15 +635,17 @@ And finally, let's cherry-pick the commit for bug #14:
```
<a name="delete-stale-local-branches">
<a name="delete-stale-local-branches"></a>
### I want to delete local branches that were deleted upstream
Once you merge a pull request on github, it gives you the option to delete the merged branch in your fork. If you aren't planning to keep working on the branch, it's cleaner to delete the local copies of the branch so you don't end up cluttering up your working checkout with a lot of stale branches.
Once you merge a pull request on GitHub, it gives you the option to delete the merged branch in your fork. If you aren't planning to keep working on the branch, it's cleaner to delete the local copies of the branch so you don't end up cluttering up your working checkout with a lot of stale branches.
```sh
$ git fetch -p
$ git fetch -p upstream
```
<a name='restore-a-deleted-branch'>
where, `upstream` is the remote you want to fetch from.
<a name='restore-a-deleted-branch'></a>
### I accidentally deleted my branch
If you're regularly pushing to remote, you should be safe most of the time. But still sometimes you may end up deleting your branches. Let's say we create a branch and create a new file:
@ -548,7 +713,7 @@ HEAD is now at 4e3cd85 foo.txt added
README.md foo.txt
```
Voila! We got our removed file back. Git reflog is also useful when rebasing goes terribly wrong.
Voila! We got our removed file back. `git reflog` is also useful when rebasing goes terribly wrong.
<a name="i-want-to-delete-a-branch"></a>
### I want to delete a branch
@ -567,17 +732,123 @@ You can also do:
To delete a local branch:
```sh
(master)$ git branch -d my-branch
```
To delete a local branch that *has not* been merged to the current branch or an upstream:
```sh
(master)$ git branch -D my-branch
```
<a name="i-want-to-rename-a-branch"></a>
### I want to rename a branch
To rename the current (local) branch:
```sh
(master)$ git branch -m new-name
```
To rename a different (local) branch:
```sh
(master)$ git branch -m old-name new-name
```
<a name="i-want-to-checkout-to-a-remote-branch-that-someone-else-is-working-on"></a>
### I want to checkout to a remote branch that someone else is working on
First, fetch all branches from remote:
```sh
(master)$ git fetch --all
```
Say you want to checkout to `daves` from the remote.
```sh
(master)$ git checkout --track origin/daves
Branch daves set up to track remote branch daves from origin.
Switched to a new branch 'daves'
```
(`--track` is shorthand for `git checkout -b [branch] [remotename]/[branch]`)
This will give you a local copy of the branch `daves`, and any update that has been pushed will also show up remotely.
<a name="i-want-to-create-a-new-remote-branch-from-current-local-one"></a>
### I want to create a new remote branch from current local one
```sh
$ git push <remote>
```
If you would also like to set that remote branch as upstream for the current one, use the following instead:
```sh
$ git push -u <remote>
```
With the `upstream` mode and the `simple` (default in Git 2.0) mode of the `push.default` config, the following command will push the current branch with regards to the remote branch that has been registered previously with `-u`:
```sh
$ git push
```
The behavior of the other modes of ```git push``` is described in the doc of push.default.
<a name="i-want-to-set-a-remote-branch-as-the-upstream-for-a-local-branch"></a>
### I want to set a remote branch as the upstream for a local branch
You can set a remote branch as the upstream for the current local branch using:
```sh
$ git branch --set-upstream-to [remotename]/[branch]
# or, using the shorthand:
$ git branch -u [remotename]/[branch]
```
To set the upstream remote branch for another local branch:
```sh
$ git branch -u [remotename]/[branch] [local-branch]
```
<a name="i-want-to-set-my-HEAD-to-track-the-default-remote-branch"></a>
### I want to set my HEAD to track the default remote branch
By checking your remote branches, you can see which remote branch your HEAD is tracking. In some cases, this is not the desired branch.
```sh
$ git branch -rr
origin/HEAD -> origin/gh-pages
origin/master
```
To change `origin/HEAD` to track `origin/master`, you can run this command:
```sh
$ git remote set-head origin --auto
origin/HEAD set to master
```
## Rebasing and Merging
<a name="force-push-rebase"></a>
### I rebased, but I don't want to force push.
<a name="undo-rebase"></a>
### I want to undo rebase/merge
Unfortunately, you have to force push, if you want those changes to be reflected on the remote branch. This is because you have fast forwarded your commit, and changed git history. The remote branch won't accept changes unless you force push. This is one of the main reasons many people use a merge workflow, instead of a rebasing workflow - large teams can get into trouble with developers force pushing. Use this with caution. A safer way to use rebase is not to reflect your changes on the remote branch at all, and instead to do the following:
You may have merged or rebased your current branch with a wrong branch, or you can't figure it out or finish the rebase/merge process. Git saves the original HEAD pointer in a variable called ORIG_HEAD before doing dangerous operations, so it is simple to recover your branch at the state before the rebase/merge.
```sh
(my-branch)$ git reset --hard ORIG_HEAD
```
<a name="force-push-rebase"></a>
### I rebased, but I don't want to force push
Unfortunately, you have to force push, if you want those changes to be reflected on the remote branch. This is because you have changed the history. The remote branch won't accept changes unless you force push. This is one of the main reasons many people use a merge workflow, instead of a rebasing workflow - large teams can get into trouble with developers force pushing. Use this with caution. A safer way to use rebase is not to reflect your changes on the remote branch at all, and instead to do the following:
```sh
(master)$ git checkout my-branch
@ -586,7 +857,7 @@ Unfortunately, you have to force push, if you want those changes to be reflected
(master)$ git merge --ff-only my-branch
```
For more, see [this SO thread](http://stackoverflow.com/questions/11058312/how-can-i-use-git-rebase-without-requiring-a-forced-push).
For more, see [this SO thread](https://stackoverflow.com/questions/11058312/how-can-i-use-git-rebase-without-requiring-a-forced-push).
<a name="interactive-rebase"></a>
### I need to combine commits
@ -670,7 +941,7 @@ Newer, awesomer features
# You are currently editing a commit while rebasing branch 'master' on '8074d12'.
#
# Changes to be committed:
# modified: README.md
# modified: README.md
#
```
@ -705,6 +976,17 @@ Sometimes you have several work in progress commits that you want to combine bef
This will do an interactive rebase that lists only the commits that you haven't already pushed, so it will be safe to reorder/fix/squash anything in the list.
<a name="i-need-to-abort-the-merge"></a>
#### I need to abort the merge
Sometimes the merge can produce problems in certain files, in those cases we can use the option `abort` to abort the current conflict resolution process, and try to reconstruct the pre-merge state.
```sh
(my-branch)$ git merge --abort
```
This command is available since Git version >= 1.7.4
<a name="check-if-all-commits-on-a-branch-are-merged"></a>
### Check if all commits on a branch are merged
@ -749,7 +1031,7 @@ Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: README.md
both modified: README.md
```
In this example, `README.md` has conflicts. Open that file and look for the following:
@ -764,7 +1046,16 @@ In this example, `README.md` has conflicts. Open that file and look for the foll
You will need to resolve the differences between the code that was added in your new commit (in the example, everything from the middle line to `new-commit`) and your `HEAD`.
Sometimes these merges are complicated and you should use a visual diff editor:
If you want to keep one branch's version of the code, you can use `--ours` or `--theirs`:
```sh
(master*)$ git checkout --ours README.md
```
- When *merging*, use `--ours` to keep changes from the local branch, or `--theirs` to keep changes from the other branch.
- When *rebasing*, use `--theirs` to keep changes from the local branch, or `--ours` to keep changes from the other branch. For an explanation of this swap, see [this note in the Git documentation](https://git-scm.com/docs/git-rebase#git-rebase---merge).
If the merges are more complicated, you can use a visual diff editor:
```sh
(master*)$ git mergetool -t opendiff
@ -785,8 +1076,96 @@ If at any time you want to stop the entire rebase and go back to the original st
(my-branch)$ git rebase --abort
```
<a name="miscellaneous-objects"></a>
## Miscellaneous Objects
<a name="stashing"></a>
## Stash
<a name="stash-all-edits"></a>
### Stash all edits
To stash all the edits in your working directory
```sh
$ git stash
```
If you also want to stash untracked files, use `-u` option.
```sh
$ git stash -u
```
<a name="stash-specific-files"></a>
### Stash specific files
To stash only one file from your working directory
```sh
$ git stash push working-directory-path/filename.ext
```
To stash multiple files from your working directory
```sh
$ git stash push working-directory-path/filename1.ext working-directory-path/filename2.ext
```
<a name="stash-msg"></a>
### Stash with message
```sh
$ git stash save <message>
```
<a name="stash-apply-specific"></a>
### Apply a specific stash from list
First check your list of stashes with message using
```sh
$ git stash list
```
Then apply a specific stash from the list using
```sh
$ git stash apply "stash@{n}"
```
Here, 'n' indicates the position of the stash in the stack. The topmost stash will be position 0.
<a name="finding"></a>
## Finding
<a name="i-want-to-find-a-string-in-any-commit"></a>
### I want to find a string in any commit
To find a certain string which was introduced in any commit, you can use the following structure:
```sh
$ git log -S "string to find"
```
Commons parameters:
* `--source` means to show the ref name given on the command line by which each commit was reached.
* `--all` means to start from every branch.
* `--reverse` prints in reverse order, it means that will show the first commit that made the change.
<a name="i-want-to-find-by-author-committer"></a>
### I want to find by author/committer
To find all commits by author/committer you can use:
```sh
$ git log --author=<name or email>
$ git log --committer=<name or email>
```
Keep in mind that author and committer are not the same. The `--author` is the person who originally wrote the code; on the other hand, the `--committer`, is the person who committed the code on behalf of the original author.
## Submodules
<a name="clone-submodules"></a>
### Clone all submodules
@ -801,6 +1180,35 @@ If already cloned:
$ git submodule update --init --recursive
```
<a name="delete-submodule"></a>
### Remove a submodule
Creating a submodule is pretty straight-forward, but deleting them less so. The commands you need are:
```sh
$ git submodule deinit submodulename
$ git rm submodulename
$ git rm --cached submodulename
$ rm -rf .git/modules/submodulename
```
<a name="miscellaneous-objects"></a>
## Miscellaneous Objects
### Restore a deleted file
First find the commit when the file last existed:
```sh
$ git rev-list -n 1 HEAD -- filename
```
Then checkout that file:
```
git checkout deletingcommitid^ -- filename
```
<a name="delete-tag"></a>
### Delete tag
@ -818,7 +1226,7 @@ If you want to recover a tag that was already deleted, you can do so by followin
$ git fsck --unreachable | grep tag
```
Make a note of the tag's hash. Then, restore the deleted tag with following, making use of git's [update-ref](http://git-scm.com/docs/git-update-ref):
Make a note of the tag's hash. Then, restore the deleted tag with following, making use of [`git update-ref`](https://git-scm.com/docs/git-update-ref):
```sh
$ git update-ref refs/tags/<tag_name> <hash>
@ -829,35 +1237,68 @@ Your tag should now have been restored.
<a name="deleted-patch"></a>
### Deleted Patch
If someone has sent you a pull request on GitHub, but then deleted their original fork, you will be unable to clone their commits or to use `git am`. In such cases, it is best to manually look at their commits and copy them into a new branch on your local. Then, commit.
If someone has sent you a pull request on GitHub, but then deleted their original fork, you will be unable to clone their repository or to use `git am` as the [.diff, .patch](https://github.com/blog/967-github-secrets) urls become unavailable. But you can checkout the PR itself using [GitHub's special refs](https://gist.github.com/piscisaureus/3342247). To fetch the content of PR#1 into a new branch called pr_1:
After committing, change the author of the previous commit. To do this, see how to [change author](#commit-wrong-author). Then, apply whatever changes needed on to, and make a new pull request.
```sh
$ git fetch origin refs/pull/1/head:pr_1
From github.com:foo/bar
* [new ref] refs/pull/1/head -> pr_1
```
### Exporting a repository as a Zip file
```sh
$ git archive --format zip --output /full/path/to/zipfile.zip master
```
## Tracking Files
<a href="i-want-to-change-a-file-names-capitalization-without-changing-the-contents-of-the-file"></a>
### I want to change a file name's capitalization, without changing the contents of the file.
### I want to change a file name's capitalization, without changing the contents of the file
```sh
(master)$ git mv --force myfile MyFile
```
<a href="i-want-to-overwrite-local-files-when-doing-a-git-pull"></a>
### I want to overwrite local files when doing a git pull
```sh
(master)$ git fetch --all
(master)$ git reset --hard origin/master
```
<a href="remove-from-git"></a>
### I want to remove a file from git but keep the file
### I want to remove a file from Git but keep the file
```sh
(master)$ git rm --cached log.txt
```
<a href="i-want-to-revert-a-file-to-a-specific-revision"></a>
### I want to revert a file to a specific revision
Assuming the hash of the commit you want is c5f567:
```sh
(master)$ git checkout c5f567 -- file1/to/restore file2/to/restore
```
If you want to revert to changes made just 1 commit before c5f567, pass the commit hash as c5f567~1:
```sh
(master)$ git checkout c5f567~1 -- file1/to/restore file2/to/restore
```
## Configuration
<a name="adding-command-aliases"></a>
### I want to add aliases for some git commands
### I want to add aliases for some Git commands
On OS X and Linux, your git configuration file is stored in ```~/.gitconfig```. I've added some example aliases I use as shortcuts (and some of my common typos) in the ```[aliases]``` section as shown below:
On OS X and Linux, your git configuration file is stored in ```~/.gitconfig```. I've added some example aliases I use as shortcuts (and some of my common typos) in the ```[alias]``` section as shown below:
```vim
[aliases]
[alias]
a = add
amend = commit --amend
c = commit
@ -879,6 +1320,27 @@ On OS X and Linux, your git configuration file is stored in ```~/.gitconfig```.
zap = fetch -p
```
<a name="adding-empty-repository"></a>
### I want to add an empty directory to my repository
You cant! Git doesnt support this, but theres a hack. You can create a .gitignore file in the directory with the following contents:
```
# Ignore everything in this directory
*
# Except this file
!.gitignore
```
Another common convention is to make an empty file in the folder, titled .gitkeep.
```sh
$ mkdir mydir
$ touch mydir/.gitkeep
```
You can also name the file as just .keep , in which case the second line above would be ```touch mydir/.keep```
<a name="credential-helper"></a>
### I want to cache a username and password for a repository
@ -894,6 +1356,19 @@ $ git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after 1 hour (setting is in seconds)
```
<a name="i-want-to-make-git-ignore-permissions-and-filemode-changes"></a>
### I want to make Git ignore permissions and filemode changes
```sh
$ git config core.fileMode false
```
If you want to make this the default behaviour for logged-in users, then use:
```sh
$ git config --global core.fileMode false
```
<a href="#ive-no-idea-what-i-did-wrong"></a>
## I've no idea what I did wrong
@ -916,7 +1391,7 @@ If it turns out that you accidentally moved back, the reflog will contain the co
$ git reset --hard 0254ea7
```
Using git reset it is then possible to change master back to the commit it was before. This provides a safety net in case history was accidentally changed.
Using `git reset` it is then possible to change master back to the commit it was before. This provides a safety net in case history was accidentally changed.
(copied and edited from [Source](https://www.atlassian.com/git/tutorials/rewriting-history/git-reflog)).
@ -925,25 +1400,36 @@ Using git reset it is then possible to change master back to the commit it was b
## Books
* [Pro Git](https://git-scm.com/book/en/v2) - Scott Chacon's excellent git book
* [Pro Git](https://git-scm.com/book/en/v2) - Scott Chacon and Ben Straub's excellent book about Git
* [Git Internals](https://github.com/pluralsight/git-internals-pdf) - Scott Chacon's other excellent book about Git
## Tutorials
* [Learn Git branching](https://learngitbranching.js.org/) An interactive web based branching/merging/rebasing tutorial
* [Getting solid at Git rebase vs. merge](https://medium.com/@porteneuve/getting-solid-at-git-rebase-vs-merge-4fa1a48c53aa)
* [git-workflow](https://github.com/asmeurer/git-workflow) - [Aaron Meurer](https://github.com/asmeurer)'s howto on using git to contribute to open source repositories
* [GitHub as a workflow](http://hugogiraudel.com/2015/08/13/github-as-a-workflow/) - An interesting take on using GitHub as a workflow, particularly with empty PRs
* [git-workflow](https://github.com/asmeurer/git-workflow) - [Aaron Meurer](https://github.com/asmeurer)'s howto on using Git to contribute to open source repositories
* [GitHub as a workflow](https://hugogiraudel.com/2015/08/13/github-as-a-workflow/) - An interesting take on using GitHub as a workflow, particularly with empty PRs
* [Githug](https://github.com/Gazler/githug) - A game to learn more common Git workflows
## Scripts and Tools
* [firstaidgit.io](http://firstaidgit.io/) A searchable selection of the most frequently asked Git questions
* [git-extra-commands](https://github.com/unixorn/git-extra-commands) - a collection of useful extra git scripts
* [git-extra-commands](https://github.com/unixorn/git-extra-commands) - a collection of useful extra Git scripts
* [git-extras](https://github.com/tj/git-extras) - GIT utilities -- repo summary, repl, changelog population, author commit percentages and more
* [git-tips](https://github.com/git-tips/tips) - Small git tips
* [git-fire](https://github.com/qw3rtman/git-fire) - git-fire is a Git plugin that helps in the event of an emergency by adding all current files, committing, and pushing to a new branch (to prevent merge conflicts).
* [git-tips](https://github.com/git-tips/tips) - Small Git tips
* [git-town](https://github.com/Originate/git-town) - Generic, high-level Git workflow support! http://www.git-town.com
## GUI Clients
* [git-cola](https://git-cola.github.io/) - another git client for Windows and OS X
* [GitUp](https://github.com/git-up/GitUp) - A newish GUI that has some very opinionated ways of dealing with git's complications
* [gitx-dev](https://rowanj.github.io/gitx/) - another graphical git client for OS X
* [Source Tree](https://www.sourcetreeapp.com/) - a free graphical git client for Windows and OS X
* [Tower](http://www.git-tower.com/) - graphical git client for OS X (paid)
* [GitKraken](https://www.gitkraken.com/) - The downright luxurious Git client,for Windows, Mac & Linux
* [git-cola](https://git-cola.github.io/) - another Git client for Windows and OS X
* [GitUp](https://github.com/git-up/GitUp) - A newish GUI that has some very opinionated ways of dealing with Git's complications
* [gitx-dev](https://rowanj.github.io/gitx/) - another graphical Git client for OS X
* [Source Tree](https://www.sourcetreeapp.com/) - a free graphical Git client for Windows and OS X
* [Tower](https://www.git-tower.com/) - graphical Git client for OS X (paid)
* [tig](https://jonas.github.io/tig/) - terminal text-mode interface for Git
* [Magit](https://magit.vc/) - Interface to Git implemented as an Emacs package.
* [GitExtensions](https://github.com/gitextensions/gitextensions) - a shell extension, a Visual Studio 2010-2015 plugin and a standalone Git repository tool.
* [Fork](https://git-fork.com/) - a fast and friendly Git client for Mac (beta)
* [gmaster](https://gmaster.io/) - a Git client for Windows that has 3-way merge, analyze refactors, semantic diff and merge (beta)
* [gitk](https://git-scm.com/docs/gitk) - a Git client for linux to allow simple view of repo state.

1301
README_ru.md Normal file

File diff suppressed because it is too large Load Diff

1018
README_zh-cn.md Normal file

File diff suppressed because it is too large Load Diff