±à¼ÍƼö: |
±¾ÎÄÖ÷Òª½éÉÜÁËGitµÄ°²×°ÓëÀíÂÛ»ù´¡
¡¢°æ±¾¶Ô±È¡¢ÐÞ¸Ä×îºóÒ»´ÎÌá½»¡¢É¾³ýÎļþºÍÖØÃüÃûÎļþ ¡¢´´½¨ºÍÇл»·ÖÖ§¡¢ºÏ²¢ºÍɾ³ý·ÖÖ§¡¢ÄäÃû·ÖÖ§ºÍcheckoutÃüÁîµÈÏà¹ØÄÚÈÝ¡£
±¾ÎÄÀ´×ÔÓÚ¼òÊ飬ÓÉ»ðÁú¹ûÈí¼þAnna±à¼¡¢ÍƼö¡£ |
|
GitʹÓý̳Ì2---GitµÄ°²×°ÓëÀíÂÛ»ù´¡
Ò»¡¢Git°²×°
windows°²×°£º½øÈëÍøÕ¾https://git-scm.com/ÏÂÔØ°²×°£¬È»ºóÔÚcmdÃüÁîÐÐÅäÖÃ
> git config
--global user.name "FishC_Service"
> git config --global user.email "fishc_service@126.com"
#¼ì²éÐÅÏ¢ÊÇ·ñдÈë³É¹¦
git config --list |
ubuntuÅäÖãºapt-get install git
¶þ¡¢ÀíÂÛ»ù´¡
Git ¼Ç¼µÄÊÇʲô£¿
ÈçÉÏ£¬Èç¹ûÿ¸ö°æ±¾ÖÐÓÐÎļþ·¢Éú±ä¶¯£¬Git »á½«Õû¸öÎļþ¸´ÖƲ¢±£´æÆðÀ´¡£ÕâÖÖÉè¼Æ¿´ËÆ»á¶àÏûºÄ¸ü¶àµÄ¿Õ¼ä£¬µ«ÔÚ·ÖÖ§¹ÜÀíʱȴÊÇ´øÀ´Á˺ܶàµÄÒæ´¦ºÍ±ãÀû¡£
Èý¿ÃÊ÷
ÄãµÄ±¾µØ²Ö¿âÓÐ Git ά»¤µÄÈý¿Ã¡°Ê÷¡±×é³É£¬ÕâÊÇ Git µÄºËÐÄ¿ò¼Ü¡£ÕâÈý¿ÃÊ÷·Ö±ðÊÇ£º¹¤×÷ÇøÓò¡¢ÔÝ´æÇøÓòºÍ
Git ²Ö¿â
¹¤×÷ÇøÓò£¨Working Directory£©¾ÍÊÇÄãƽʱ´æ·ÅÏîÄ¿´úÂëµÄµØ·½¡£
ÔÝ´æÇøÓò£¨Stage£©ÓÃÓÚÁÙʱ´æ·ÅÄãµÄ¸Ä¶¯£¬ÊÂʵÉÏËüÖ»ÊÇÒ»¸öÎļþ£¬±£´æ¼´½«Ìá½»µÄÎļþÁбíÐÅÏ¢¡£
Git ²Ö¿â£¨Repository£©¾ÍÊÇ°²È«´æ·ÅÊý¾ÝµÄλÖã¬ÕâÀï±ßÓÐÄãÌá½»µÄËùÓа汾µÄÊý¾Ý¡£ÆäÖУ¬HEAD
Ö¸Ïò×îзÅÈë²Ö¿âµÄ°æ±¾£¨ÕâµÚÈý¿ÃÊ÷£¬È·ÇеÄ˵£¬Ó¦¸ÃÊÇ Git ²Ö¿âÖÐ HEAD Ö¸ÏòµÄ°æ±¾£©¡£
Git µÄ¹¤×÷Á÷³ÌÒ»°ãÊÇ£º
ÔÚ¹¤×÷Ŀ¼ÖÐÌí¼Ó¡¢ÐÞ¸ÄÎļþ£»
½«ÐèÒª½øÐа汾¹ÜÀíµÄÎļþ·ÅÈëÔÝ´æÇøÓò£»
½«ÔÝ´æÇøÓòµÄÎļþÌá½»µ½ Git ²Ö¿â¡£
Òò´Ë£¬Git ¹ÜÀíµÄÎļþÓÐÈýÖÖ״̬£ºÒÑÐ޸ģ¨modified£©¡¢ÒÑÔݴ棨staged£©ºÍÒÑÌá½»£¨committed£©£¬ÒÀ´Î¶ÔÓ¦ÉϱߵÄÿһ¸öÁ÷³Ì¡£
GitʹÓý̳Ì3---ʵս
Ò»¡¢³õʼ»¯Git
ÔÚ×Ô¼º·½±ãµÄÅÌÖÐн¨Ò»¸öÎļþ¼Ð£¬ÕâÀïÒÔMyProjectΪÀý£¬×¢Òâ·¾¶Öв»Òªº¬ÓÐÖÐÎÄ×Ö·û¡£´ò¿ªcmdÃüÁî´°¿Ú£¬²Ù×÷ÈçÏ£º
#³õʼ״̬ÔÚCÅÌÖУ¬¸ü¸Ä·¾¶
C:\Users\lenovo>F:
F:\>
F:\>cd MyProject
F:\MyProject>
#³õʼ»¯GitÏîÄ¿£¬³É¹¦ºó´´½¨ÓÐÒ»¸ö.gitÒþ²ØÎļþ
F:\MyProject>git init
Initialized empty Git repository in F:/MyProject/.git/
#ÔÚÎļþ¼ÐMyProjectÖÐÌí¼ÓÒ»¸öÎı¾ÎļþREADME£¬md¸ñʽָMarkdown¸ñʽ£¨½¨ÒéʹÓÃNotepad++±à¼£©
#È»ºóÊäÈëÒÔÏÂÃüÁÎļþ¼ÓÈëÔÝ´æÇø
F:\MyProject>git add README.md
#½«ÎļþÌá½»µ½git²Ö¿â£¨-m±íʾÌí¼Ó±¾´ÎÌá½»µÄ˵Ã÷£¬Ç¿ÖÆÒªÇóдµÄ£©
F:\MyProject>git commit -m "add a readme
file"
[master (root-commit) 9e08cf4] add a readme file
1 file changed, 1 insertion(+)
create mode 100644 README.md |
GitʹÓý̳Ì4---״̬
ÎÒÃÇÔõô֪µÀÄÄЩÎļþÊÇÐÂÌí¼ÓµÄ£¬ÄÄЩÎļþÒѾ¼ÓÈëÁËÔÝ´æÇøÓòÄØ£¿×ܲ»ÄÜÈÃÎÒÃÇ×Ô¼ºÄøö±¾±¾¼ÇÏÂÀ´°É£¿
µ±È»²»£¬×÷ΪÊÀ½çÉÏ×îΰ´óµÄ°æ±¾¿ØÖÆϵͳ£¬ÄãÄÜÓöµ½µÄ‡å¾³£¬Git ÔçÒÑÓÐÁËÏàÓ¦µÄ½â¾ö·½°¸¡£ËæʱËæµØ¶¼¿ÉÒÔʹÓÃgit
status²é¿´µ±Ç°×´Ì¬
F:\MyProject>git
status
On branch master
nothing to commit, working tree clean |
On branch master: ÎÒÃÇλÓÚÒ»¸ö½Ð×ö¡°master¡±µÄ·ÖÖ§ÀÕâÊÇĬÈϵķÖÖ§
nothing to commit, working directory clean : ˵Ã÷ÄãµÄ¹¤×÷Ŀ¼ĿǰÊÇ¡°¸É¾»µÄ¡±£¬Ã»ÓÐÐèÒªÌá½»µÄÎļþ£¨Òâ˼¾ÍÊÇ×ÔÉÏ´ÎÌá½»ºó£¬¹¤×÷Ŀ¼ÖеÄÄÚÈÝѹ¸ù¶ù¾Íû¸Ä¶¯¹ý£©¡£
ÔÚ¹¤×÷Ŀ¼ÖÐÌí¼ÓLICENSEÎļþ(È¥µôºó׺£¬ÓÃNotePad++´ò¿ª)£º
Copyright (C) <year> <copyright holders>
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to
deal in the Software without restriction, including
without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT
WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
С¼×ÓãÓÑÇéÌáʾ£ºMIT Ðí¿ÉÖ¤¼¸ºõÊÇ×î¿íËɵİæȨԼ¶¨£¬Ò»µ©ÄãµÄ³ÌÐò²ÉÓã¬Ò²¾ÍÒâζ×űðÈËÖ»ÒªÔÚÈí¼þ°üº¬ÉϱߵİæȨÉùÃ÷£¬¾Í¿ÉÒÔ¶ÔÄãµÄ³ÌÐòΪËùÓûΪÁË£¨°üÀ¨¡°Ê¹Óᢸ´ÖÆ¡¢Ð޸ġ¢ºÏ²¢¡¢³ö°æ·¢ÐС¢É¢²¼¡¢ÔÙÊÚȨºÍ/»ò··ÊÛÈí¼þ¼°Èí¼þµÄ¸±±¾¡±£©¡£
ÊäÈëgit statusÃüÁÌáʾÈçÏ£º
F:\MyProject>git
status
On branch master
Untracked files:
(use "git add <file>..." to include
in what will be committed)
LICENSE(ºìÉ«)
nothing added to commit but untracked files
present (use "git add" to track) |
Untracked files ˵Ã÷´æÔÚδ¸ú×ÙµÄÎļþ£¨Ï±ߺìÉ«µÄÄǸö£©
ËùνµÄ¡°Î´¸ú×Ù¡±Îļþ£¬ÊÇÖ¸ÄÇЩÐÂÌí¼ÓµÄ²¢ÇÒδ±»¼ÓÈëµ½ÔÝ´æÇøÓò»òÌá½»µÄÎļþ¡£ËüÃÇ´¦ÓÚÒ»¸öåÐÒ£·¨ÍâµÄ״̬£¬µ«ÄãÒ»µ©½«ËüÃǼÓÈëÔÝ´æÇøÓò»òÌá½»µ½
Git ²Ö¿â£¬ËüÃǾͿªÊ¼Êܵ½ Git µÄ¡°¸ú×Ù¡±¡£
ÕâÀïÔ²À¨ºÅÖеÄÓ¢ÎÄÊÇ git ¸øÎÒÃǵĽ¨Ò飺ʹÓà git add <file>
ÃüÁ´ýÌá½»µÄÎļþÌí¼Óµ½ÔÝ´æÇøÓò¡£
F:\MyProject>git
add LICENSE
F:\MyProject>git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..."
to unstage)
new file: LICENSE(ÂÌÉ«) |
use "git reset HEAD <file>..."
to unstage µÄÒâ˼ÊÇ¡°Èç¹ûÄã·´»ÚÁË£¬Äã¿ÉÒÔʹÓà git reset HEAD ÃüÁî»Ö¸´ÔÝ´æÇøÓò¡±¡£Èç¹ûºóÃæ½ÓÎļþÃû£¬±íʾ»Ö¸´¸ÃÎļþ£»Èç¹û²»½ÓÎļþÃû£¬Ôò±íʾÉÏÒ»´ÎÌí¼ÓµÄÎļþ¡£
F:\MyProject>git
reset HEAD
F:\MyProject>git status
On branch master
Untracked files:
(use "git add <file>..." to
include in what will be committed)
LICENSE(ºìÉ«)
nothing added to commit but untracked files
present (use "git add" to track) |
ÔÙ´ÎÌí¼Óµ½ÔÝ´æÇøÓò£¬È»ºóÖ´ÐÐ git commit -m "add
a license file" ÃüÁ
F:\MyProject>git
add LICENSE
F:\MyProject>git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..."
to unstage)
new file: LICENSE
F:\MyProject>git commit -m "add a license
file"
[master 9fdf9f4] add a license file
1 file changed, 7 insertions(+)
create mode 100644 LICENSE
F:\MyProject>git status
On branch master
nothing to commit, working tree clean |
¹ØÓÚÐÞ¸Ä
ͻȻ·¢ÏÖ°æȨÄÇ¿éÍüÁËдÉÏ×Ô¼ºµÄÃû×ÖÁË¡¡
´ò¿ª LICENSE Îļþ£¬½« Copyright (C) <year> <copyright
holders> ¸ÄΪ Copyright (C) 2016 FishC£¬±£´æ¡¡
Ö´ÐÐ git status ÃüÁ
F:\MyProject>git
status
On branch master
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: LICENSE(ºìÉ«)
no changes added to commit (use "git add"
and/or "git commit -a") |
ÓÉÓÚÄã¶Ô¹¤×÷Ŀ¼µÄÎļþ½øÐÐÁËÐ޸ģ¬µ¼ÖÂÕâ¸öÎļþºÍÔÝ´æÇøÓòµÄ¶ÔÓ¦Îļþ²»Æ¥ÅäÁË£¬ËùÒÔ Git ÓÖ¸øÄãÌá³öÁ½Ìõ½¨Ò飺
ʹÓà git add ÃüÁ¹¤×÷Ŀ¼µÄа汾¸²¸ÇÔÝ´æÇøÓòµÄ¾É°æ±¾£¬È»ºó×¼±¸Ìá½»
ʹÓà git checkout ÃüÁÔÝ´æÇøÓòµÄ¾É°æ±¾¸²¸Ç¹¤×÷Ŀ¼µÄа汾£¨Î£ÏÕ²Ù×÷£ºÏ൱ÓÚ¶ªÆú¹¤×÷Ŀ¼µÄÐ޸ģ©
»¹ÓÐÒ»ÖÖÇé¿öÎÒÃÇû·ÖÎö£¬´ó¼ÒÏÈ°Ñа汾µÄÎļþ¸²¸ÇµôÔÝ´æÇøÓòµÄ¾É°æ±¾£º
F:\MyProject>git
add LICENSE
F:\MyProject>git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..."
to unstage)
modified: LICENSE(ÂÌÉ«) |
È»ºóÎÒÃÇ´ò¿ª LICENSE Îļþ£¬½« FishC ¸ÄΪ FishC.com£¬±£´æ¡¡
F:\MyProject>git
status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..."
to unstage)
modified: LICENSE(ÂÌÉ«)
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: LICENSE(ºìÉ«) |
Õâ´ÎÇé¿öÊÇ£º±»ÂÌµÄ LICENSE ˵Ã÷Îļþ´æ·ÅÔÚÔÝ´æÇøÓò£¨´ýÌá½»£©£¬Í¬Ê±ºìÉ«µÄ LICENSE ˵Ã÷Îļþ»¹ÔÚ¹¤×÷Ŀ¼µÈ´ýÌí¼Óµ½ÔÝ´æÇøÓò¡£
ÕâÖÖÇé¿öÄãÓ¦¸ÃÒâʶµ½ÕâÀï´æÔÚÁ½¸ö²»Í¬°æ±¾µÄ LICENSE Îļþ£¬ÕâʱÈç¹ûÄãÖ±½ÓÖ´ÐÐ commit
ÃüÁÄÇôÌá½»µÄÊÇÔÝ´æÇøÓòµÄ°æ±¾£¨FishC£©£¬Èç¹ûÄãÏ£ÍûÌá½»¹¤×÷Ŀ¼µÄа汾£¨FishC.com£©£¬ÄÇôÄãÐèÒªÏÈÖ´ÐÐ
add ÃüÁ¸ÇÔÝ´æÇøÓò£¬È»ºóÔÙÌá½»¡¡
Ò»²½µ½Î»
´Ó¹¤×÷Ŀ¼һ²½Ìí¼Óµ½²Ö¿â£ºgit commit -am ¡°ËµÃ÷¡±
F:\MyProject>git
commit -am "change the license file"
|
-aµÄÒâ˼ÊÇadd¡£
git log ²é¿´ÀúÊ·²Ù×÷¼Ç¼
GitʹÓý̳Ì5---»Øµ½¹ýÈ¥
ÓйػØÍ˵ÄÃüÁîÓÐÁ½¸ö£ºreset ºÍ checkout
ÏÈÖ´ÐÐgit logÃüÁ½«´ËʱµÄGit²Ö¿â¿ÉÊÓ»¯
Èý¿ÃÊ÷µÄÇé¿ö£º
»Ø¹ö¿ìÕÕ
×¢£º¿ìÕÕ¼´Ìá½»µÄ°æ±¾£¬Ã¿¸ö°æ±¾ÎÒÃdzÆ֮Ϊһ¸ö¿ìÕÕ¡£
ÏÖÔÚÎÒÃÇÀûÓà reset ÃüÁî»Ø¹ö¿ìÕÕ£¬²¢¿´¿´ Git ²Ö¿âºÍÈý¿ÃÊ÷·Ö±ð·¢ÉúÁËʲô¡£
Ö´ÐÐ git reset HEAD~ ÃüÁ
×¢£ºHEAD ±íʾ×îÐÂÌá½»µÄ¿ìÕÕ£¬¶ø HEAD~ ±íʾ HEAD µÄÉÏÒ»¸ö¿ìÕÕ£¬HEAD~~±íʾÉÏÉϸö¿ìÕÕ£¬Èç¹û±íʾÉÏ10¸ö¿ìÕÕ£¬Ôò¿ÉÒÔÓÃHEAD
~10
´ËʱÎÒÃǵĿìÕһعöµ½Á˵ڶþ¿ÃÊý£¨ÔÝ´æÇøÓò£©
µÚÒ»´ÎÖ´ÐÐresetºóGit²Ö¿â
µÚÒ»´ÎÖ´ÐÐresetºóÈý¿ÃÊ÷
git reset HEAD~ ÃüÁîÆäʵÊÇ git reset --mixed HEAD~ µÄËõд£¬
--mixed Ñ¡ÏîÊÇĬÈϵġ£
ĬÈÏ
git reset HEAD~ ÃüÁîÆäʵӰÏìÁËÁ½¿ÃÊ÷£ºÊ×ÏÈÊÇÒƶ¯ HEAD µÄÖ¸Ïò£¬½«ÆäÖ¸ÏòÉÏÒ»¸ö¿ìÕÕ£¨HEAD~£©£»È»ºóÔÙ½«¸ÃλÖõĿìÕջعöµ½ÔÝ´æÇøÓò¡£
--softÑ¡Ïî
git reset --soft HEAD~ ÃüÁî¾ÍÏ൱ÓÚÖ»Òƶ¯ HEAD µÄÖ¸Ïò£¬µ«²¢²»»á½«¿ìÕջعöµ½ÔÝ´æÇøÓò¡£Ï൱ÓÚ³·ÏûÁËÉÏÒ»´ÎµÄÌá½»£¨commit£©¡£Ò»²»Ð¡ÐÄÌá½»ÁË£¬ºó»ÚÁË£¬ÄÇôÄã¾ÍÖ´ÐÐ
git reset --soft HEAD~ ÃüÁî¼´¿É£¨´ËʱִÐÐ git log ÃüÁҲ²»»áÔÙ¿´µ½ÒѾ³·ÏûÁ˵ÄÄǸöÌá½»£©¡£
--hardÑ¡Ïî
reset ²»½öÒƶ¯ HEAD µÄÖ¸Ïò£¬½«¿ìÕջعö¶¯µ½ÔÝ´æÇøÓò£¬Ëü»¹½«ÔÝ´æÇøÓòµÄÎļþ»¹Ôµ½¹¤×÷Ŀ¼¡£
»Ø¹öÖ¸¶¨¿ìÕÕ
reset ²»½ö¿ÉÒԻعöÖ¸¶¨¿ìÕÕ£¬»¹¿ÉÒԻعö¸ö±ðÎļþ¡£
ÃüÁî¸ñʽΪ£º git reset ¿ìÕÕ ÎļþÃû/·¾¶
ÕâÑù£¬Ëü¾Í»á½«ºöÂÔÒƶ¯ HEAD µÄÖ¸ÏòÕâÒ»²½£¨ÒòΪÄãÖ»Êǻعö¿ìÕյIJ¿·ÖÄÚÈÝ£¬²¢²»ÊÇÕû¸ö¿ìÕÕ£¬ËùÒÔ
HEAD µÄÖ¸Ïò²»Ó¦¸Ã·¢Éú¸Ä±ä£©£¬Ö±½Ó½«Ö¸¶¨¿ìÕÕµÄÖ¸¶¨Îļþ»Ø¹öµ½ÔÝ´æÇøÓò¡£
²»½ö¿ÉÒÔÍù»Ø¹ö£¬»¹¿ÉÒÔÍùÇ°¹ö£¡
ÕâÀïÐèҪǿµ÷µÄÊÇ£ºreset ²»½öÊÇÒ»¸ö¡°¸´¹Å¡±µÄÃüÁËü²»½ö¿ÉÒԻص½¹ýÈ¥£¬»¹¿ÉÒÔÈ¥µ½¡°Î´À´¡±¡£
ΨһµÄÒ»¸öÇ°ÌáÌõ¼þÊÇ£ºÄãÐèÒªÖªµÀÖ¸¶¨¿ìÕÕµÄ ID ºÅ¡£
ÄÇÈç¹û²»Ð¡ÐÄ°ÑÃüÁî´°¿Ú¹ØÁ˲»¼ÇµÃIDºÅÔõô°ì£¿
ÃüÁgit reflog
Git¼Ç¼µÄÿһ´Î²Ù×÷µÄ°æ±¾IDºÅ
GitʹÓý̳Ì6---°æ±¾¶Ô±È
Ä¿µÄ£º¶Ô±È°æ±¾Ö®¼äÓÐÄÄЩ²»Í¬
×¼±¸¹¤×÷
´´½¨Ò»¸ö½Ð×ö MyProject2 µÄÐÂÎļþ¼Ð×÷Ϊ±¾´ÎÑÝʾµÄÏîÄ¿£¬³õʼ»¯ Git
´´½¨Ò»¸ö game.py µÄÎı¾£¬½«Ï±ߴúÂ뿽±´½øÈ¥£º
import random
print('------------------ÎÒ°®ÓãC¹¤×÷ÊÒ------------------')
secret = random.randint(1,10)
temp = input("²»·Á²ÂÒ»ÏÂС¼×ÓãÏÖÔÚÐÄÀïÏëµÄÊÇÄĸöÊý×Ö£º")
guess = int(temp)
while guess != secret:
temp = input("°¥Ñ½£¬²Â´íÁË£¬ÇëÖØÐÂÊäÈë°É£º")
guess = int(temp)
if guess == secret:
print("ÎÔ²Û£¬ÄãÊÇС¼×ÓãÐÄÀïµÄ»×³æÂ𣿣¡")
print("ºß£¬²ÂÖÐÁËҲûÓн±Àø£¡")
else:
if guess > secret:
print("´óÁË£¬´óÁË~~~")
else:
print("СÁË£¬Ð¡ÁË~~~")
print("ÓÎÏ·½áÊø£¬²»ÍæÀ²^_^") |
ÔÙ´´½¨Ò»¸ö README.md Îļþ£¬Ð´Çå³þÕâÊÇÒ»¸ö¿Îºó×÷ÒµµÄÏîÄ¿£º
¿Îºó×÷Òµ£ºÎÄ×ÖÓÎÏ·
Ö´ÐÐ git add README.md game.py ÃüÁÎļþÌí¼Óµ½ÔÝ´æÇøÓò£¬½Ó×ÅÖ´ÐÐ git
commit -m "²ÂÊý×ÖÓÎÏ·" Ìá½»ÏîÄ¿µÄµÚÒ»¸ö¿ìÕÕ
¸ü¸Ä´úÂëÈçÏ£º
import random
print('------------------ÎÒ°®ÓãC¹¤×÷ÊÒ------------------')
times = 3
secret = random.randint(1,10)
guess = 0
print("²»·Á²ÂÒ»ÏÂС¼×ÓãÏÖÔÚÐÄÀïÏëµÄÊÇÄĸöÊý×Ö£º", end="
")
while (guess != secret) and (times > 0):
temp = input()
guess = int(temp)
times = times - 1 # Óû§Ã¿ÊäÈëÒ»´Î£¬¿ÉÓûú»á¾Í-1
if guess == secret:
print("ÍÛŶ£¬ÄãÊÇС¼×ÓãÐÄÀïµÄ»×³æÂ𣿣¡")
print("ºß£¬²ÂÖÐÁËҲûÓн±Àø£¡")
else:
if guess > secret:
print("¸ç£¬´óÁË´óÁË~~~")
else:
print("ºÙ£¬Ð¡ÁË£¬Ð¡ÁË~~~")
if times > 0:
print("ÔÙÊÔÒ»´Î°É£º", end=" ")
else:
print("»ú»áÓù⿩T_T")
print("ÓÎÏ·½áÊø£¬²»ÍæÀ²^_^") |
¸ü¸ÄREADMEÎļþ
¡¶Áã»ù´¡ÈëÃÅѧϰPython¡·µÚ004½²
¿Îºó×÷Òµ£ºÎÄ×ÖÓÎÏ·
±È½ÏÔÝ´æÇøÓòÓ빤×÷Ŀ¼
Ö±½ÓÖ´ÐÐ git diff ÃüÁîÊDZȽÏÔÝ´æÇøÓòÓ빤×÷Ŀ¼µÄÎļþÄÚÈÝ£º
ÕâÀï¿ÉÄܳöÏÖÒ»¸öÎÊÌ⣬ֱ½ÓÖ´ÐеĽá¹û³öÏÖÖÐÎÄÂÒÂë¡£ÔÚcmd½çÃæµÄðºÅ£ººóÃæÊäÈëqÍ˳ö£¬Ê¹ÓÃNotepad++´ò¿ªREADMEÎļþ£¬µã»÷±àÂë¡úתΪUTF-8±àÂë¡££¨¾É°æ±¾ÖÐÑ¡ÔñUTF-8£¨ÎÞBOM£©£¬Ð°æÖеÄUTF-8ĬÈÏΪÎÞBOM£©ÖØÐÂÖ´ÐÐgit
diff·¢ÏÖ»¹ÊDz»ÐУ¡Ôõô·ÊËÄ£¿£¿ÔÚ±¾²Ë²é±é¸÷ÍøÕ¾ÂÛ̳֮ºó£¬ÖÕÓÚÕÒµ½Á˽â¾ö·½·¨
Ö´ÐÐÒÔÏÂÈýÌõÃüÁî(±ðÎÊÎÒÃ÷Ã÷ÊÇËÄÌõΪɶ˵ÈýÌõ...)
git config
--global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding utf-8
export LESSCHARSET=utf-8 ## linux bashÅäÖû·¾³±äÁ¿
set LESSCHARSET=utf-8 #windowsÅäÖû·¾³±äÁ¿ |
¹þ¹þ¹þ£¬ÖÕÓڸ㶨ÁË£¡
ÏÖÔÚÀ´½âÊÍÒ»ÏÂÉÏÃæÿһÐеĺ¬Ò壺
µÚÒ»ÐУºdiff --git a/README.md b/README.md
±íʾ¶Ô±ÈµÄÊÇ´æ·ÅÔÚÔÝ´æÇøÓòµÄ README.md ºÍ¹¤×÷Ŀ¼µÄ README.md
µÚ¶þÐУºindex 7966837..472a180 100644
±íʾ¶ÔÓ¦ÎļþµÄ ID ·Ö±ðÊÇ 7966837 ºÍ 472a180£¬×ó±ßÔÝ´æÇøÓò£¬ºó±ßµ±Ç°Ä¿Â¼¡£×îºóµÄ
100644 ÊÇÖ¸¶¨ÎļþµÄÀàÐͺÍȨÏÞ
µÚÈýÐУº--- a/README.md
--- ±íʾ¸ÃÎļþÊǾÉÎļþ£¨´æ·ÅÔÚÔÝ´æÇøÓò£©
µÚËÄÐУº+++ b/README.md
+++ ±íʾ¸ÃÎļþÊÇÐÂÎļþ£¨´æ·ÅÔÚ¹¤×÷ÇøÓò£©
µÚÎåÐУº@@ -1 +1,2 @@
ÒÔ @@ ¿ªÍ·ºÍ½áÊø£¬ÖмäµÄ¡°-¡±±íʾ¾ÉÎļþ£¬¡°+¡±±íʾÐÂÎļþ£¬ºó±ßµÄÊý×Ö±íʾ¡°¿ªÊ¼Ðкţ¬ÏÔʾÐÐÊý¡±
µÚÁù¡¢ÆßÐУº
ÕâÊǽ«Á½¸öÎļþºÏ²¢ÏÔʾµÄ½á¹û£¬Ç°±ßÓиö + µÄÂÌÉ«µÄÄÇÒ»ÐÐ˵Ã÷ÊÇÐÂÎļþ¶ÀÓеģ¬Ç³»ÒÉ«µÄÔòÊÇÁ½¸öÎļþËù¹²ÓеÄÄÚÈÝ¡£ËùÒÔ£¬+1,2
±íʾÐÂÎļþÔںϲ¢ÏÔʾÖÐ´ÓµÚ 1 ÐпªÊ¼£¬ÏÔʾ 2 ÐС£ÄÇΪɶ -1 ºó±ßûÓÐÏÔʾµÄÐÐÊý£¿ÒòΪÔںϲ¢ÏÔʾµÄ½á¹ûÖУ¬¾ÉÎļþÒѾÍêÈ«°üº¬ÔÚÐÂÎļþÖÐÁË£¨Ò²¾ÍÊǾÉÎļþûÓÐ×Ô¼º¡°¶ÀÓеġ±ÄÚÈÝ£©¡£
µÚ°ËÐУº\ No newline at end of file
ÕâÊÇ Git ³öÓÚÉÆÒâµÄÌáÐÑ£ºÎļþ²»ÊÇÒÔ»»Ðзû½áÊø¡£ÎªÊ²Ã´»áÓÐÕâÑù¶à´ËÒ»¾ÙµÄÌáÐÑÄØ£¿×ÐϸÍÆÇÃÏÂÄã¾Í»áÃ÷°×ÁË£ºdiff
½«Á½¸öÎļþºÏ²¢´òÓ¡£¬µ½´ï×îºóÒ»¸ö×Ö·ûµÄʱºò£¬ÎÞÂÛÎļþÖÐÊÇ·ñ´æÔÚ»»Ðзû£¬diff ¶¼ÐèÒª´òÓ¡Ò»¸ö»»Ðзû£¡ÎªÉ¶£¿ÎªÁ˺ÿ´ß£¡£¡ËùÒÔÈç¹ûÄãµÄÎļþ×îºóÒ»¸ö×Ö·û²»ÊÇÒÔ»»Ðзû½á⣬µ«
diff ÓÖ×ÔÐÐÌí¼ÓÁËÒ»¸ö»»Ðзû£¬ËùÒÔËü¾õµÃÓÐÒåÎñÌáÐÑÄãËüÕâô×öÁË£¡
×îºóµÄ£¨:£©ÊÇʲô£¿
Òâ˼ÊÇ´°¿Ú̫С£¬Ã»°ì·¨ÏÔʾȫ²¿£¬ÕýÔڵȴýÃüÁVim±à³Ì֪ʶ£©
Òƶ¯ÃüÁî
j¡¢k£ºÏòÏÂÒƶ¯Ò»ÐÐ/ÏòÉÏÒƶ¯Ò»ÐÐ
f¡¢b£ºÏòÏ·ҳ/ÏòÉÏ·Ò³
d¡¢u£ºÏòÏ·°ëÒ³/ÏòÉÏ·°ëÒ³
ÌøתÃüÁî
g¡¢G£ºÌøתµ½µÚÒ»ÐÐ/Ìøתµ½×îºóÒ»ÐÐ
ÏÈÊäÈëÊý×Ö£¨Èç3£©£¬ÔÙÊäÈëg£¬±íʾÌøתµ½¸ÃÐУ¨ÈçµÚ3ÐУ©
ËÑË÷ÃüÁî
ÊäÈëб¸Ü£¨/£©»òÎʺţ¨?£©,ºóÃæ½ÓËÑË÷¹Ø¼ü×Ö
Çø±ð£ºÐ±¸Ü£¨/£©±íʾ´Óµ±Ç°Î»ÖÃÏòÏÂËÑË÷£¬Îʺţ¨?£©±íʾ´Óµ±Ç°Î»ÖÃÏòÉÏËÑË÷¡£
½Ó×ÅÊäÈë n ±íʾ˳×ŵ±Ç°µÄËÑË÷·½Ïò¿ìËÙÌøתµ½Ï¸öÆ¥ÅäµÄλÖ㬴óдµÄ N ÔòÊÇÓ뵱ǰËÑË÷·½ÏòÏà·´¡£
Í˳öºÍ°ïÖú
ÔÚµãµã£¨:£©ºó±ßÊäÈë q£¬±íʾÍ˳ö diff£»ÊäÈë h ±íʾ½øÈë°ïÖú½çÃ棬Äã»á¿´µ½ºÜ¶àÃüÁîºÍ¹¦ÄÜ£¬ÊäÈë
q ¿ÉÒÔÍ˳ö°ïÖú½çÃæ¡£
±È½ÏÁ½¸öÀúÊ·¿ìÕÕ
ÎÒÃÇÖ´ÐÐ git commit -am "Ìí¼Ó¹¦ÄÜ£ºÍæ¼ÒÖ»ÓÐÈý´Î»ú»á" ÃüÁÌí¼Ó²¢Ìá½»¹¤×÷Ŀ¼ÖеÄËùÓÐÎļþ¡£Ö´ÐÐ
git log ÃüÁ¿ÉÒÔ¿´µ½ÏÖÔÚ Git ²Ö¿âÖÐÒѾÓÐÁ½¸ö¿ìÕÕÁË£º
Ö´ÐÐ git diff 6e26975 ed3708c ÃüÁ¼´¿É±È½Ï
Git ²Ö¿âÖÐÁ½¸ö¿ìÕյIJîÒ죺
Git²Ö¿âÖÐÄ¿Ç°Á½¸ö¿ìÕյIJîÒì
±È½Ïµ±Ç°¹¤×÷Ŀ¼ºÍ Git ²Ö¿âÖеĿìÕÕ
ÎÒÃÇÉÔ΢¸Ä¶¯Ò»Ï README.md ÎļþµÄÄÚÈÝ£º
Ä¿Ç°ÎÒÃÇµÄ Git ²Ö¿âÓ¦¸ÃÊÇ£º
Èý¿ÃÊ÷ÊÇÕâÑù£º
±È½Ï֮ǰ°æ±¾µÄ¿ìÕÕÓ뵱ǰ¹¤×÷Ŀ¼ÄÚÈÝ
ÊäÈë git diff ed3708c ÃüÁî¼´¿É
±È½Ïµ±Ç°°æ±¾¿ìÕÕÓ뵱ǰ¹¤×÷Ŀ¼ÄÚÈÝ
ÊäÈë git diff HEAD ÃüÁî¼´¿É
±È½ÏGit²Ö¿âÓëÔÝ´æÇøÓò
Ö´ÐÐ git add README.md ÃüÁ½«µÚÈý°æµÄ README.md ÎļþÌí¼Óµ½ÔÝ´æÇøÓò¡£
È»ºóÈý¿ÃÊ÷¾ÍÊÇÕâÑùÁË£º
Èç¹ûÏ£Íû±È½Ï×îÐÂÌá½»µÄ¿ìÕÕºÍÔÝ´æÇøÓòµÄÎļþ£¬Ö»ÐèÒªÖ´ÐÐ git diff --cached ÃüÁµ±È»Ò²¿ÉÒÔÖ¸¶¨ÆäËû¿ìÕÕ£¬¾ÍÊÇÐèÒª¶àдÉÏÒ»¸ö
ID Öµ£¬¼´git diff --cached IDºÅ¡£
¹þ¹þ¹þ£¬ºÜÂÒÓÐľÓУ¬Æäʵ¾ÍÊÇÕâÈý¿ÃÊ÷Ö®¼äµÄÏ໥±È½Ï£¬×îºó·îÉÏÖÕ¼«°ÂÒåͼ£º
GitʹÓý̳Ì7---ÐÞ¸Ä×îºóÒ»´ÎÌá½»¡¢É¾³ýÎļþºÍÖØÃüÃûÎļþ
ÎÊÌâ³öÏÖ£º
Situation One£º°æ±¾¸ÕÒ»Ìá½»£¨commit£©µ½²Ö¿â£¬Í»È»ÏëÆð©µôÁ½¸öÎļþ»¹Ã»ÓÐÌí¼Ó£¨add£©
Situation Two£º°æ±¾¸ÕÒ»Ìá½»£¨commit£©µ½²Ö¿â£¬Í»È»ÏëÆð°æ±¾ËµÃ÷дµÃ²»¹»È«Ã棬ÎÞ·¨ÕÃÏÔÄã±¾´ÎÐ޸ĵÄÖØ´óÒâÒå¡¡
ÓÉÓÚʹÓÃresetÃüÁî¹ýÓÚ·±Ëö£¬ÐèÒªÌá½»Ò»¸öеİ汾£¬ÕâÀï¿ÉÒÔʹÓôø --amend Ñ¡ÏîµÄ commit
ÃüÁ£¨¼´git commit --amend£©Git »á¡°¸üÕý¡±×î½üµÄÒ»´ÎÌá½»¡£ÓÉÓÚÕâÀïûÓÐ-m˵Ã÷£¬»á½øÈëÒÔÏÂÒ³Ã棺
Õâ¸ö½çÃæÆäʵֻÊÇÈÃÄã±à¼Ìύ˵Ã÷¶øÒÑ¡£Èç¹û²»ÐèÒªÐ޸ģ¬¿ÉÒÔÁ¬Ðø°´ÏÂÁ½¸ö´óдZÀ´Í˳ö£¬»òÕß°´Ï£¨:£©ÔÙÊäÈëq!Í˳ö£¬Git»á±£Áô¾ÉµÄÌύ˵Ã÷¡£Èç¹ûÐèÒªÌύ˵Ã÷ÓÖ²»ÏëÓÃÕâô·±ËöµÄ·½Ê½£¬ÊäÈëgit
commit --ammend -m ¡°ÐµÄÌύ˵Ã÷¡± ¼´¿É¡£
ɾ³ýÎļþ
ÎÊÌâÒ»£º²»Ð¡ÐÄɾ³ýÎļþÔõô°ì£¿
ÏÖÔÚ´Ó¹¤×÷Ŀ¼ÖÐÊÖ¶¯É¾³ý README.md Îļþ£¬È»ºóÖ´ÐÐ git status ÃüÁ
ÌáÐÑʹÓà checkout ÃüÁî¿ÉÒÔ½«ÔÝ´æÇøÓòµÄÎļþ»Ö¸´µ½¹¤×÷Ŀ¼£º
Îļþ¾Í»áÖØзµ»Ø¡£
ÎÊÌâ¶þ£ºÄÇôÈçºÎ³¹µ×ɾ³ýÒ»¸öÎļþÄØ£¿
¼ÙÈçÄ㲻СÐÄ°ÑС»ÆͼÏÂÔص½Á˹¤×÷Ŀ¼£¬È»ºóÓÖ²»Ð¡ÐÄÌá½»µ½ÁË Git
²Ö¿â£º
Ö´ÐÐ git rm yellow.jpg ÃüÁ
´Ëʱ¹¤×÷Ŀ¼ÖеÄС»Æͼ£¨yellow.jpg£©ÒѾ±»É¾³ý¡¡
µ«Ö´ÐÐ git status ÃüÁÄãÈÔÈ»·¢ÏÖ Git »¹²»¿ÏËÉÊÖ£º
Òâ˼ÊÇ˵ËüÔÚ²Ö¿âµÄ¿ìÕÕÖз¢ÏÖÓиö½Ð yellow µÄ¶«Î÷£¬µ«ËƺõÔÚÔÝ´æÇøÓòºÍµ±Ç°Ä¿Â¼²»¼ûÁË£¡
´Ëʱ¿ÉÒÔÖ´ÐÐ git reset --soft HEAD~ ÃüÁ¿ìÕջعöµ½ÉÏÒ»¸öλÖã¬È»ºóÖØÐÂÌá½»£¬Git
¾Í²»»áÔÙÌáС»ÆͼµÄʶùÁË£º
×¢Ò⣺rm ÃüÁîɾ³ýµÄÖ»Êǹ¤×÷Ŀ¼ºÍÔÝ´æÇøÓòµÄÎļþ£¨¼´È¡Ïû¸ú×Ù£¬ÔÚÏ´ÎÌύʱ²»ÄÉÈë°æ±¾¹ÜÀí£©
ÎÊÌâÈý£ºÎÒÔÚ¹¤×÷Ŀ¼ÖÐÔö¼ÓÒ»¸ö test.py Îļþ£¬È»ºóÖ´ÐÐ git add test.py ÃüÁÆäÌí¼Óµ½ÔÝ´æÇøÓò£¬´ËʱÎÒÐÞ¸Ä
test.py ÎļþµÄÄÚÈÝ£¬ÄÇôÔÝ´æÇøÓòºÍ¹¤×÷Ŀ¼¾ÍÊÇÁ½¸ö²»Í¬µÄ test.py ÎļþÁË£¬´ËʱÈç¹ûÎÒÖ´ÐÐ
git rm test.py ÃüÁGit »áÏÂÒâʶµØ×èÖ¹ÎÒ£¬ÕâÊÇÔõô°ì£¿
ÒòΪÁ½¸ö²»Í¬ÄÚÈݵÄͬÃûÎļþ£¬ËÖªµÀÄãÊDz»ÊǸãÇå³þÁ˶¼ÒªÉ¾µô£¿»¹ÊÇÌáÐÑһϺ㬱ðµÈһϳö´íÁËÓÖÒªÀµ»úÆ÷¡¡
¸ù¾ÝÌáʾ£¬Ö´ÐÐ git rm -f test.py ÃüÁî¾Í¿ÉÒÔ°ÑÁ½¸ö¶¼É¾³ý¡£
ÎÊÌâËÄ£ºÎÒÖ»Ïëɾ³ýÔÝ´æÇøÓòµÄÎļþ£¬±£Áô¹¤×÷Ŀ¼µÄ£¬Ó¦¸ÃÔõô²Ù×÷£¿
Ö´ÐÐ git rm --cached ÎļþÃû ÃüÁî¡£
ÖØÃüÃûÎļþ
Ö±½ÓÔÚ¹¤×÷Ŀ¼ÖØÃüÃûÎļþ£¬Ö´ÐÐgit status³öÏÖ´íÎó£º
ÕýÈ·µÄ×ËÊÆÓ¦¸ÃÊÇ£º
git mv ¾ÉÎļþÃû ÐÂÎļþÃû
×¢£ºWindows ʹÓà ren ÃüÁîÐÞ¸ÄÎļþÃû£¬Linux ÊÇʹÓà mv ÃüÁî
½Ì³Ì6²Êµ°
ÈçºÎÈÃGit ʶ±ðijЩ¸ñʽµÄÎļþ£¬È»ºó×ÔÖ÷²»¸ú×ÙËüÃÇ£¿
±ÈÈ繤×÷Ŀ¼ÖÐÓÐÈý¸öÎļþ1.temp¡¢2.temp ºÍ 3.temp£¬ÎÒÃDz»Ï£Íûºó׺ÃûΪ temp
µÄÎļþ±»×·×Ù£¬¿ÉÊÇÿ´ÎÖ´ÐÐgit status¶¼»á³öÏÖ£º
½â¾ö°ì·¨£ºÔÚ¹¤×÷Ŀ¼´´½¨Ò»¸öÃûΪ .gitignore µÄÎļþ¡£
È»ºóÄã·¢ÏÖ Windows ѹ¸ù¶ù²»ÔÊÐíÄãÔÚÎļþ¹ÜÀíÆ÷Öд´½¨ÒԵ㣨.£©¿ªÍ·µÄÎļþ¡£windowsÐèÒªÔÚÃüÁîÐд°¿Ú´´½¨£¨.£©¿ªÍ·µÄÎļþ¡£Ö´ÐÐ
echo *.temp > .gitignore ÃüÁ´´½¨Ò»¸ö .gitignore Îļþ£¬²¢ÈÃ
Git ºöÂÔËùÓÐ .temp ºó׺µÄÎļþ£º
ºÃÁË£¬Git ÒѾºöÂÔÁËËùÓÐµÄ *.temp Îļþ£¨Ä㻹¿ÉÒÔ°Ñ .gitignore ÎļþÒ²Ò»²¢ºöÂÔ£©¡£
GitʹÓý̳Ì7---´´½¨ºÍÇл»·ÖÖ§
·ÖÖ§ÊÇʲô£¿
¼ÙÉèÄãµÄ´óÏîÄ¿ÒѾÉÏÏßÁË£¨ÓÐÉÏ°ÙÍòÈËÔÚʹÓã©£¬¹ýÁËÒ»¶Îʱ¼äÄãͻȻ¾õµÃÓ¦¸ÃÌí¼ÓһЩÐµĹ¦ÄÜ£¬µ«ÊÇΪÁ˱£ÏÕÆð¼û£¬Äã¿Ï¶¨²»ÄÜÔÚµ±Ç°ÏîÄ¿ÉÏÖ±½Ó½øÐпª·¢£¬ÕâʱºòÄã¾ÍÓд´½¨·ÖÖ§µÄÐèÒªÁË¡£
¶ÔÓÚÆäËü°æ±¾¿ØÖÆϵͳ¶øÑÔ£¬´´½¨·ÖÖ§³£³£ÐèÒªÍêÈ«´´½¨Ò»¸öÔ´´úÂëĿ¼µÄ¸±±¾£¬ÏîÄ¿Ô½´ó£¬ºÄ·ÑµÄʱ¼ä¾ÍÔ½¶à£»¶ø
Git ÓÉÓÚÿһ¸ö½áµã¶¼ÒѾÊÇÒ»¸öÍêÕûµÄÏîÄ¿£¬ËùÒÔÖ»ÐèÒª´´½¨¶àÒ»¸ö¡°Ö¸Õ롱£¨Ïñ master£©Ö¸Ïò·ÖÖ§¿ªÊ¼µÄλÖü´¿É¡£
´´½¨·ÖÖ§
À´µ½Ö®Ç°´´½¨µÄÏîÄ¿MyProject2£¬
Ä¿Ç°²Ö¿âµÄ״̬ÈçÏ£º
Ö´ÐÐgit status²é¿´×´Ì¬£º
¿ÉÒÔ¿´µ½ README.md Îļþ±»Ð޸IJ¢Ìí¼Óµ½ÔÝ´æÇøÓò£¨»¹Ã»ÓÐÌá½»£©£¬ËùÒÔµ±Ç°Èý¿ÃÊ÷Ó¦¸ÃÊÇÕâÑù£º
´´½¨·ÖÖ§£¬Ê¹Óà git branch ·ÖÖ§Ãû ÃüÁ
ûÓÐÈκÎÌáʾ˵Ã÷·ÖÖ§´´½¨³É¹¦£¨Ò»°ãÒ²²»»áʧ°ÜÀ²£¬³ý·Ç´´½¨ÁËͬÃûµÄ·ÖÖ§»áÌáÐÑÄãһϣ©£¬´Ëʱ¿ÉÒÔÖ´ÐÐ git
log --decorate ÃüÁî²é¿´£º
Èç¹ûÏ£ÍûÒÔ¡°¾«¼ò°æ¡±µÄ·½Ê½ÏÔʾ£¬¿ÉÒÔ¼ÓÉÏÒ»¸ö --oneline Ñ¡Ï¼´ git log --decorate
--oneline£©£¬ÕâÑù¾ÍÖ»ÓÃÒ»ÐÐÀ´ÏÔʾһ¸ö¿ìÕռǼ¡£
¿ÉÒÔ¿´µ½×îеĿìÕÕºó±ß¶àÁËÒ»¸ö (HEAD -> master, feature)
ËüµÄÒâ˼ÊÇ£ºÄ¿Ç°ÓÐÁ½¸ö·ÖÖ§£¬Ò»¸öÊÇÖ÷·ÖÖ§£¨master£©£¬Ò»¸öÊǸղÅÎÒÃÇ´´½¨µÄзÖÖ§£¨feature£©£¬È»ºó
HEAD Ö¸ÕëÈÔȻָÏòĬÈ쵀 master ·ÖÖ§¡£
ËùÒÔÄ¿Ç°²Ö¿âÖеĿìÕÕÓ¦¸ÃÊÇÕâÑù£º
Çл»·ÖÖ§
ÏÖÔÚÎÒÃÇÐèÒª½«¹¤×÷»·¾³Çл»µ½Ð´´½¨µÄ·ÖÖ§£¨feature£©ÉÏ£¬Ê¹ÓõľÍÊÇ֮ǰÎÒÃÇÓûÑÔÓÖÖ¹µÄ checkout
ÃüÁî¡£Ö´ÐÐ git checkout feature ÃüÁ
ÕâÑù HEAD Ö¸Õë¾ÍÖ¸Ïò feature ·ÖÖ§ÁË£º
ÏÖÔÚÎÒÃǽøÐÐÒ»´ÎÌá½»£¨ÔÝ´æÇøÓò»¹ÓÐÒ»¸ö¸ü¸ÄµÄÎļþûÓÐÌá½»ÄØ£©£º
ÏÖÔÚ²Ö¿âÖеĿìÕÕÓ¦¸ÃÊǽ´×Ï£¨Ìá½»µÄ¿ìÕÕÓɵ±Ç°HEADÖ¸ÕëÖ¸ÏòµÄ·ÖÖ§À´¹ÜÀí£©£º
È»ºóÎÒÃǽ« HEAD Ö¸ÕëÇÐ»Ø master ·ÖÖ§£º
ϸÐĵÄÅóÓѻᷢÏÖÉÏÒ»´Î¶Ô README.md ÎļþµÄÐÞ¸ÄÒѾµ´È»ÎÞ´æÁË£¬ÕâÊÇÒòΪÎÒÃǵŤ×÷Ŀ¼ÒѾ»Øµ½
master ·ÖÖ§µÄ״̬ÖУº
ÏÖÔÚ¶Ô README.md Îļþ½øÐÐÐ޸ģ¨Ëæ±ã¸Ä¸Ä£©£¬È»ºóÖ´ÐÐ git commit -m "ÔÙ´ÎÐÞ¸Ä˵Ã÷Îļþ"£º
Ä¿Ç°²Ö¿âÖеĿìÕÕÓ¦¸Ã±ä³ÉÁ˽´×Ï£º
Ö´ÐÐ git log --oneline --decorate --graph --all ÃüÁ
--graph Ñ¡Ïî±íʾÈà Git »æÖÆ·Ö֧ͼ£¬--all ±íʾÏÔʾËùÓзÖÖ§
GitʹÓý̳Ì9---ºÏ²¢ºÍɾ³ý·ÖÖ§
ºÏ²¢·ÖÖ§
µ±Ò»¸ö×Ó·ÖÖ§µÄʹÃüÍê½áÖ®ºó£¬Ëü¾ÍÓ¦¸Ã»Ø¹éµ½Ö÷·ÖÖ§ÖÐÈ¥¡£
ºÏ²¢·ÖÖ§ÎÒÃÇʹÓà merge ÃüÁִÐÐ git merge feature ÃüÁ½« feature
·ÖÖ§ºÏ²¢µ½ HEAD ËùÔڵķÖÖ§£¨master£©ÉÏ£º
´Ó Git ÌáʾµÄÄÚÈÝÀ´¿´£¬ÎÒÃÇÖªµÀÕâ´ÎµÄºÏ²¢²¢Ã»Óгɹ¦£¬Git ˵£º
ºÏ²¢ README.md ÎļþµÄʱºò³öÏÖ³åÍ»¡£
ËùÒÔ×Ô¶¯ºÏ²¢Ê§°Ü£»ÇëÐ޸ijåÍ»µÄÄÚÈݲ¢ÖØÐÂÌá½»¿ìÕÕ¡£
Òâ˼ÊÇ˵ÏÖÔÚÄãÐèÒªÏȽâ¾ö³åÍ»µÄÎÊÌ⣬Git ²ÅÄܽøÐкϲ¢²Ù×÷¡£Ëùν³åÍ»£¬Î޷ǾÍÊÇÏñÁ½¸ö·ÖÖ§ÖдæÔÚͬÃûµ«ÄÚÈÝÈ´²»Í¬µÄÎļþ£¬Git
²»ÖªµÀÄãÒªÉáÆúÄÄÒ»¸ö»ò±£ÁôÄÄÒ»¸ö£¬ËùÒÔÐèÒªÄã×Ô¼ºÀ´¾ö¶¨¡£
´ËʱִÐÐ git status ÃüÁîÒ²»áÏÔʾÐèÒªÄã½â¾öµÄ³åÍ»£º
È»ºó Git »áÔÚÓгåÍ»µÄÎļþÖмÓÈëһЩ±ê¼Ç£¬²»ÐÅÄã´ò¿ª README.md Îļþ¿´¿´£º
ÒÔ¡°=======¡±Îª½ç£¬Éϵ½¡°<<<<<<< HEAD¡±µÄÄÚÈݱíʾµ±Ç°·ÖÖ§£¬Ïµ½¡°>>>>>>>
feature¡±±íʾ´ýºÏ²¢µÄ feature ·ÖÖ§£¬Ö®¼äµÄÄÚÈݾÍÊdzåÍ»µÄµØ·½¡£
ÏÖÔÚÎÒÃǽ« README.md ͳһÐ޸ģ¨È¥µô <<<<<<<
HEAD µÈÄÚÈÝ£©
±£´æÎļþ£¬È»ºóÌá½»¿ìÕÕ£º
Ö´ÐÐ git log --decorate --all --graph --oneline ÃüÁ¿ÉÒÔ¿´µ½´ËʱµÄ·ÖÖ§ÒѾ×Ô¶¯ºÏ²¢ÁË:
µ±È»£¬Èç¹û²»´æÔÚ³åÍ»£¬¾Í²»ÓøãÕâô¶àÁË¡¡¾Ù¸öÀý×Ó£º
Ö´ÐÐ git checkout -b feature2 ÃüÁÏ൱ÓÚ git branch feature2
ºÍ git checkout feature2 Á½¸öÃüÁîµÄºÏÌ壩£º
ÔÚ¹¤×÷Ŀ¼Ëæ±ã´´½¨Ò»¸öÎı¾Îļþ£¨feature2.txt£©²¢Ìá½»¿ìÕÕ£º
Ö´ÐÐ git log --decorate --all --graph --oneline ÃüÁ
¿ÉÒÔ¿´µ½£¬feature2 ·ÖÖ§±È master ·ÖÖ§¿ìÁËÒ»²½¡£ÏÖÔÚÎÒÃÇÇл»»Ø master ·ÖÖ§£¬²¢½«
feature2 ·ÖÖ§ºÏ²¢½øÀ´£º
Õâ´Î Git Ö»ÏÔʾÁË Fast-forward£¨¿ì½ø£©Õâ´Ê¶ù£¬ÕâÊÇÒòΪ feature2 Õâ¸ö·ÖÖ§µÄ¸¸½áµãÊÇ
master ·ÖÖ§£¬ËùÒÔ Git Ö»ÐèÒª¼òµ¥Òƶ¯ master µÄÖ¸Ïò¼´¿É¡£
Ö´ÐÐ git log --decorate --all --graph --oneline ÃüÁ
ɾ³ý·ÖÖ§
ɾ³ý·ÖÖ§£¬Ê¹Óà git branch -d ·ÖÖ§Ãû ÃüÁ
Ö´ÐÐ git log --decorate --all --graph --oneline ÃüÁ
ÓÉÓÚ Git µÄ·ÖÖ§ÔÀíʵ¼ÊÉÏÖ»ÊÇͨ¹ýÒ»¸öÖ¸Õë¼ÇÔØ£¬ËùÒÔ´´½¨ºÍɾ³ý·ÖÖ§¶¼¼¸ºõÊÇ˲¼äÍê³É¡£
×¢Ò⣺Èç¹ûÊÔͼɾ³ýδºÏ²¢µÄ·ÖÖ§£¬Git »áÌáʾÄã¡°¸Ã·Ö֧δÍêÈ«ºÏ²¢£¬Èç¹ûÄãÈ·¶¨ÒªÉ¾³ý£¬ÇëʹÓà git
branch -D ·ÖÖ§Ãû ÃüÁî¡£
²Êµ°£ºGitµÄÁ½Öֺϲ¢·½Ê½ --- Fast-forward ºÍ Three-way merge
Fast-forward
ËùνµÄ Fast-forward ¾ÍÊǵ±´ýºÏ²¢µÄ·Ö֧λÓÚÄ¿±ê·ÖÖ§µÄÖ±½ÓÉÏÓÎʱ£¬Git Ö»Ðè°ÑÄ¿±ê·ÖÖ§µÄÖ¸ÕëÖ±½ÓÒƶ¯¼´¿ÉʵÏֺϲ¢¡£
±ÈÈçÏÂÃæͼƬÖÐ master ·ÖÖ§ÊÇλÓÚ feature2 ·ÖÖ§µÄÖ±½ÓÉÏÓΣº
½« feature2 ·ÖÖ§ºÏ²¢µ½ master ·ÖÖ§£¬Ö»ÐèÒªÒƶ¯ master µÄÖ¸Õë¼´¿É£º
Three-way merge
Èç¹û´ýºÏ²¢µÄÁ½¸ö·ÖÖ§²»ÔÚͬһÌõÏßÉÏ£¬ÄÇô½øÐкϲ¢¾ÍÐèÒª½â¾öÒ»¸ö¸ù±¾µÄÎÊÌâ ¡ª¡ª ³åÍ»£¡
ΪºÎÁ½¸ö·ÖÖ§ÔÚͬһÌõÏßÉϾͲ»»á³åÍ»ÄØ£¿
ÒòΪ Git µÄ¿ìÕÕÊÇ°´Ê±¼ä˳ÐòÌá½»µÄ£¬ËùÒÔÔÚͬһÌõÏßÉϵÄÁ½¸ö¿ìÕÕ£¬ËüÃÇÊÇÓÐÏȺó˳ÐòµÄ£¬¾¡¹ÜÁ½Õß¿ÉÄܳöÏÖͬÃûÎļþ²»Í¬ÄÚÈÝ£¬Git
»áÈÏΪÕâÊÇ¡°¸Ä±ä¡±¶ø²»ÊÇ¡°³åÍ»¡±¡£
¾Ù¸öÀý×Ó£º
ºÏ²¢ C3 ºÍ C4 µÃµ½ C5£¬µ« C5 Ó¦¸ÃÈçºÎ´¦Àí¡°³åÍ»¡±ÄØ£¿
SVN »á°ÑÎÊÌâÅ׸øÓû§£¬ÈÃÓû§×ÔÐнâ¾ö£»Git ÔòÏԵøüΪ¸ßÃ÷£¬Ëü»áÕÒµ½µÚÈý¸ö¿ìÕÕ£¬È»ºó×ÛºÏÈýÕßÌصã×Ô¶¯½â¾ö³åÍ»¡£
ÄǵÚÈý¸ö¿ìÕÕÓ¦¸ÃÈçºÎ¾ö¶¨ÄØ£¿
û´í£¬Ó¦¸ÃÕÒÁ½ÕߵĹ²Í¬¡°×æÏÈ¡±×÷Ϊ²ÎÕÕÎһ±È½Ï¾ÍÖªµÀÁ½¸ö·ÖÖ§¶¼¸ÉÁËЩʲô¡£
ͼƬÖÐ C3 ºÍ C4 µÄ¹²Í¬×æÏÈÊÇ C1£¬¿ÉÒÔ¿´µ½ C3 ºÍ C4 ·Ö±ðÔö¼ÓÁË test2.py
ºÍ test1.py Á½¸öÎļþ¡£ÒòΪ¶Ô±ÈÖ®ºó·¢ÏÖÈýÕß²¢Ã»ÓгåÍ»£¬ËùÒÔ C5 Ó¦¸ÃÊÇÈýÕߵĺÏÌ壬¼´Í¬Ê±ÓµÓÐ
common.py¡¢test1.py ºÍ test2.py Èý¸öÎļþ¡£
ÁíÍ⣬ֵµÃÒ»ÌáµÄÊÇ£¬Git ÕâÖֺϲ¢·½Ê½Ò²ÊÊÓÃÓÚͬÃûÎļþµÄ²»Í¬¸ü¸Ä¡£
¾Ù¸öÀý×Ó£º
ÕâÀï C3 ºÍ C4 ¶¼Ö»ÓÐÒ»¸öÎļþ£¨test.txt£©£¬µ«ÊÇÄÚÈÝÈ´²»Ò»Ñù¡£Èç¹ûÕâÑùºÏ²¢£¬Äã²Â Git
»á²»»á±¨¡°³åÍ»¡±£¿
´ð°¸ÊDz»»áµÄ£¡
ÒòΪ Git ÕÒµ½ËüÃǵĹ²Í¬×æÏÈ C1£¬¿ÉÒÔ¿´µ½ C3 ºÍ C4 ¶¼ÊÇÔÚ
C1 µÄ»ù´¡ÉϽøÐÐÌí¼Ó£¨C4 ÔÚµÚ 2 ÐÐÌí¼ÓÁË¡°I¡±£¬C3 ÔÚµÚ 4 ÐÐÔö¼ÓÁË¡°FishC¡±£¬C1
µÚ 3 Ðеġ°love¡±ÊÇËüÃǹ²Í¬ÓµÓеģ©£¬Í¬Ê±ÔÚÿһÐв¢Ã»ÓвúÉú³åÍ»µÄµØ·½£¬ËùÒÔ×Ô¶¯ºÏ²¢ºóµÄ C5
ÊÇÕâÑùµÄ£º
×¢Ò⣺Èç¹û Git ¼ì²âµ½Í¬Ò»ÐÐÓв»Í¬µÄÄÚÈÝ£¬»¹Êǻᱨ³åÍ»²¢ÈÃÄã×ÔÐоö¶¨ËÈ¥ËÁôµÄ£¡
GitʹÓý̳Ì10---ÄäÃû·ÖÖ§ºÍcheckoutÃüÁî
ÄäÃû·ÖÖ§
´´½¨Ò»¸öеÄÎļþ¼Ð£¨MyProject3£©£¬È»ºó³õʼ»¯ git¡£ÒÀ´Î´´½¨Èý¸öÎļþ²¢Ìá½»£¨Ã¿´´½¨Ò»¸öÎļþÌá½»Ò»´Î£©£º
ÉÏÒ»½Ú¿ÎÎÒÃǽ²µÄÊÇʹÓà branch ÃüÁî´´½¨Ò»¸ö·ÖÖ§£¬È»ºóʹÓà checkout ÃüÁîÇл»·ÖÖ§¡£
Èç¹ûÔÚû´´½¨·ÖÖ§µÄÇé¿öÏÂÖ´ÐÐ checkout ÃüÁ»áÓÐÔõÑùµÄÊÂÇé·¢ÉúÄØ£¿
ÎÒÃDz»·ÁÊÔÊÔ¿´£¬Ö´ÐÐ git checkout HEAD~ ÃüÁ
µ±Ç°µÄ HEAD Ö¸Õë´¦ÓÚ·ÖÀë״̬£¬Äã¿ÉÒÔ»·¹ËËÄÖÜ£¬×öһЩʵÑéÐÔÐ޸IJ¢Ìá½»ËüÃÇ£¬²¢ÇÒÄã¿ÉÒÔÔÚÕâ¸ö״̬ÖжªÆúÈκÎÄãËù×öµÄÌá½»£¬¶ø²»Ó°ÏìÈκηÖÖ§£¬×ö·¨ÊÇÖ´ÐÐ
checkout ÃüÁîÇл»»Ø±ðµÄ·ÖÖ§¡£
Èç¹ûÄãÏ£Íû´´½¨Ò»¸öзÖÖ§£¬²¢±£³ÖÄãËù×ö´´½¨µÄÌá½»£¬Äã¿ÉÒÔ£¨ÏÖÔÚ»òÉÔºó£©Í¨¹ýʹÓôøÓÐ -b Ñ¡ÏîµÄ
checkout ÃüÁîʵÏÖ¡£ÀýÈ磺
git checkout -b <new-branch-name>
HEAD Ö¸Õ뵱ǰָÏò 52861cf... 2.txt
ÄãʹÓÃÁË checkout ÃüÁûÓÐÖ¸¶¨·ÖÖ§Ãû£¬ËùÒÔ Git °ïÄã´´½¨ÁËÒ»¸öÄäÃû·ÖÖ§£¬OK£¬¼ÈÈ»ÊÇÄäÃû£¬ÄÇôµ±ÄãÇл»µ½±ðµÄ·Ö֧ʱ£¬Õâ¸öÄäÃû·ÖÖ§ÖеÄËùÓÐÌá½»¶¼»á±»¶ªÆúµô£¨ÒòΪÄ㶼û¸øÈ˼ÒÃüÃû£¬·´ÕýÒÔºó¶¼ÕÒ²»»ØÁË£¬²»¶ªÁ˸Éɶ£¿£©¡£Òò´Ë£¬Äã¿ÉÒÔÀûÓÃÄäÃû·ÖÖ§À´×ö×öʵÑéʲôµÄ£¬·´Õý²»»áÓиºÃæÓ°Ïì¡£
À´£¬ÎÒÃÇÊÔÊÔ£¬ÔÚ¹¤×÷Ŀ¼Öд´½¨Ò»¸ö 4.txt£¨Äã»á·¢ÏÖ 3.txt ²»¼ûÁË£¬ÕâÊÇÒòΪ checkout
½«»·¾³Çл»µ½ÉÏÒ»´ÎÌá½»ÁË£©£¬È»ºóÌá½»
Ö´ÐÐ git log --decorate --all --graph --oneline ÃüÁî
¿ÉÒÔ¿´µ½ÓÐÁ½¸ö·ÖÖ§£¬µ« HEAD ËùÔڵķÖÖ§²¢Ã»ÓÐÃû×Ö£¨ÄäÃû·ÖÖ§£©£¬ÄÇÏÖÔÚÎÒÃÇ°Ñ HEAD ÇÐ»Ø master
·ÖÖ§£º
¾¯¸æ£ºÄã²ÐÁôÒ»¸öûÓÐÁ¬½ÓÈκηÖÖ§µÄÌá½»£º
178d909 4.txt
Èç¹ûÄãÏëͨ¹ý´´½¨Ò»¸ö·ÖÖ§À´Á¬½ÓËü£¬Õ⽫ÊÇÒ»¸öºÃʱ»ú£¬ÇëÖ´ÐУº
git branch <new-branch-name> 178d909
ÒѾÇл»µ½ 'master' ·ÖÖ§
ÏÖÔÚÔÙÀ´²é¿´Ìá½»ÈÕÖ¾£¬¿ÉÒÔ¿´µ½ÄäÃû·ÖÖ§ÒѾµ´È»Î޴棺
ÔÙÂÛcheckout
ÊÂʵÉÏÄØ£¬checkout ÃüÁîÓÐÁ½ÖÖ¹¦ÄÜ£º
´ÓÀúÊ·¿ìÕÕ£¨»òÕßÔÝ´æÇøÓò£©Öп½±´Îļþµ½¹¤×÷Ŀ¼
Çл»·ÖÖ§
´ÓÀúÊ·¿ìÕÕ£¨»òÕßÔÝ´æÇøÓò£©Öп½±´Îļþµ½¹¤×÷Ŀ¼
µ±¸ø¶¨Ä³¸öÎļþÃûʱ£¬Git »á´ÓÖ¸¶¨µÄÌá½»Öп½±´Îļþµ½ÔÝ´æÇøÓòºÍ¹¤×÷Ŀ¼¡£±ÈÈçÖ´ÐÐ git checkout
HEAD~ README.md ÃüÁî»á½«ÉÏÒ»¸ö¿ìÕÕÖÐµÄ README.md Îļþ¸´ÖƵ½¹¤×÷Ŀ¼ºÍÔÝ´æÇøÓòÖУº
Èç¹ûÃüÁîÖÐûÓÐÖ¸¶¨¾ßÌåµÄ¿ìÕÕ ID£¬Ôò½«´ÓÔÝ´æÇøÓò»Ö¸´Ö¸¶¨Îļþµ½¹¤×÷Ŀ¼£¨git checkout
README.md£©£º
ÓÐЩÅóÓÑ¿ÉÄÜ»áÎÊ£º¡°Éϴο´ÄãÔÚÎļþÃûµÄÇ°±ßÓмÓÁ½¸öºá¸Ë£¨--£©£¬Õâ´ÎÔõô¾ÍûÓÐÁËÄØ£¿¡±
Îʵúã¬Git ÌáÐÑÄãд³É git checkout -- README.md µÄÐÎʽ£¬ÄÇÊÇΪÁËÔ¤·ÀÄãÇ¡ºÃÓÐÒ»¸ö·ÖÖ§½Ð×ö
README.md£¬ÄÇôËü¾Í¸ã²»¶®ÄãÒª»Ö¸´Îļþ»¹ÊÇÇл»·ÖÖ§ÁË£¬ËùÒÔÔ¼¶¨Á½¸öºá¸Ë£¨--£©ºó±ß¸úµÄÊÇÎļþÃû¡£
·´¹ýÀ´Ëµ£¬Èç¹ûÄãÈ·±£ÄãûÓÐÒ»¸ö½Ð×ö README.md µÄ·ÖÖ§£¬ÄãÖ±½Óд git checkout
README.md Ò²ÊÇÍ×Í×µÄûÎÊÌâÀ²
Çл»·ÖÖ§
Ê×ÏÈÎÒÃÇÖªµÀ Git µÄ·ÖÖ§Æäʵ¾ÍÊÇÌí¼ÓÒ»¸öÖ¸Ïò¿ìÕÕµÄÖ¸Õ룬Æä´ÎÎÒÃÇ»¹ÖªµÀÇл»·ÖÖ§³ýÁËÐÞ¸Ä HEAD
Ö¸ÕëµÄÖ¸Ïò£¬»¹»á¸Ä±äÔÝ´æÇøÓòºÍ¹¤×÷Ŀ¼µÄÄÚÈÝ¡£
ËùÒÔÖ´ÐÐ git checkout 373c0 ÃüÁGit Ö÷Òª¾ÍÊÇ×öÁËϱßÕâÁ½¼þÊ£¨µ±È»ÊÂʵÉÏ
Git »¹×öÁ˸ü¶à£©£º
ÄǻعýÍ·À´£¬Èç¹ûÎÒÃÇÖ»Ïë»Ö¸´Ö¸¶¨µÄÎļþ/·¾¶£¬ÄÇôÎÒÃÇÖ»ÐèÒªÖ¸¶¨¾ßÌåµÄÎļþ£¬Git ¾Í»áºöÂÔµÚÒ»²½ÐÞ¸Ä
HEAD Ö¸ÏòµÄ²Ù×÷£¬Õâ²»Õý¸ú֮ǰ½² reset ÃüÁîµÄʱºòÒ»ÑùÂð£¿
checkout ÃüÁîºÍ reset ÃüÁîµÄÇø±ð
»Ö¸´Îļþ
checkout ÃüÁîºÍ reset ÃüÁ¿ÉÒÔÓÃÓÚ»Ö¸´Ö¸¶¨¿ìÕÕµÄÖ¸¶¨Îļþ£¬²¢ÇÒËüÃǶ¼²»»á¸Ä±ä HEAD
Ö¸ÕëµÄÖ¸Ïò¡£
ÏÂÃ濪ʼ»®Öص㣺
ËüÃǵÄÇø±ðÊÇ reset ÃüÁîÖ»½«Ö¸¶¨Îļþ»Ö¸´µ½ÔÝ´æÇøÓò£¨--mixed£©£¬¶ø checkout
ÃüÁîÊÇͬʱ¸²¸ÇÔÝ´æÇøÓòºÍ¹¤×÷Ŀ¼¡£
×¢Ò⣺ҲÐíÄãÊÔͼʹÓà git reset --hard HEAD~ README.md ÃüÁîÈà reset
ͬʱ¸²¸Ç¹¤×÷Ŀ¼£¬µ« Git »á¸æËßÄãÕâÊÇͽÀÍ£¨´Ëʱ reset ²»ÔÊÐíʹÓà --soft »ò --hard
Ñ¡Ï¡£
ÕâÑù¿´À´£¬ÔÚ»Ö¸´Îļþ·½Ã棬reset ÃüÁîÒª±È checkout ÃüÁî¸ü°²È«Ò»Ð©¡£
»Ö¸´¿ìÕÕ
reset ÃüÁîÊÇÓÃÀ´¡°»Øµ½¹ýÈ¥¡±µÄ£¬¸ù¾ÝÑ¡ÏîµÄ²»Í¬£¬reset ÃüÁÒƶ¯ HEAD Ö¸Õ루--soft£©
-> ¸²¸ÇÔÝ´æÇøÓò£¨--mixed£¬Ä¬ÈÏ£©-> ¸²¸Ç¹¤×÷Ŀ¼£¨--hard£©¡£
checkout ÃüÁîËä˵ÊÇÓÃÓÚÇл»·ÖÖ§£¬µ«Ç°ÃæÄãÒ²¿´µ½ÁË£¬ËüÊÂʵÉÏÒ²ÊÇͨ¹ýÒƶ¯ HEAD Ö¸ÕëºÍ¸²¸ÇÔÝ´æÇøÓò¡¢¹¤×÷Ŀ¼À´ÊµÏֵġ£
ÄÇÎÊÌâÀ´ÁË£ºËüÃÇÓÐʲôÇø±ðÄØ£¿
ÏÂÃ濪ʼ»®Öص㣺
µÚÒ»¸öÇø±ðÊÇ£¬¶ÔÓÚ reset --hard ÃüÁîÀ´Ëµ£¬checkout ÃüÁî¸ü°²È«¡£ÒòΪ checkout
ÃüÁîÔÚÇл»·Ö֧ǰ»áÏȼì²éһϵ±Ç°µÄ¹¤×÷״̬£¬Èç¹û²»ÊÇ¡°clean¡±µÄ»°£¬Git ²»»áÔÊÐíÄãÕâÑù×ö£»¶ø
reset --hard ÃüÁîÔòÊÇÖ±½Ó¸²¸ÇËùÓÐÊý¾Ý¡£
ÁíÒ»¸öÇø±ðÊÇÈçºÎ¸üРHEAD Ö¸Ïò£¬reset ÃüÁî»áÒƶ¯ HEAD ËùÔÚ·ÖÖ§µÄÖ¸Ïò£¬¶ø checkout
ÃüÁîÖ»»áÒƶ¯ HEAD ×ÔÉíÀ´Ö¸ÏòÁíÒ»¸ö·ÖÖ§¡£
¿´ÎÄ×ÖÄã¿Ï¶¨ã£¬ÎÒÃǾÙÀý˵Ã÷¡£
À´£¬´ó¼ÒÏȰѸղŵÄÀý×ӸijÉϱßÕâÑù£º
Ö´ÐÐ git checkout feature ÃüÁ
¿ÉÒÔ¿´µ½Ö»ÊÇ HEAD Ö¸ÕëÅܵ½ feature ·ÖÖ§ÄǶùÈ¥ÁË¡£
ºÃ£¬ÎÒÃÇÖ´ÐÐ git checkout master ÃüÁÆäÇлء£
ÏÖÔÚÖ´ÐÐ git reset --hard feature ÃüÁ
²Êµ°
ͨ³£Çé¿öÏ£¬Git »á¾¡¿ÉÄܵس¢ÊÔʹÓà Fast-forward ·½Ê½À´ºÏ²¢·ÖÖ§£¬ÒòΪÕâÑùЧÂʷdz£¸ß£¬Ö»ÓÐÔÚÍò²»µÃÒѵÄʱºò²ÅʹÓÃÈý·½ºÏ²¢£¨Three-way
merge£©
µ«ÊÇ£¬ÓÐʱºò Fast-forward µÄ·½Ê½È´ºÜÈÝÒ×ÈÃÎÒÃǺöÂÔÁË·ÖÖ§µÄ´æÔÚ£¡
¾Ù¸öÀý×Ó£¬±ÈÈçÏÂÃæÕâÑù£º
Èç¹ûÎÒÃÇ°Ñ¡°feature¡±·Ö֧ɾ³ý£¬¾Í»áÖ±½Ó¶ªµô·ÖÖ§µÄÐÅÏ¢£º
¸ù±¾¾Í²»ÖªµÀÓиö·ÖÖ§´æÔÚ¹ý¡¡
¿ÉÓÐʱºòÎÒÃÇȷʵϣÍû±£Áô·ÖÖ§µÄÐÅÏ¢£¬Ó¦¸ÃÔõô°ìÄØ£¿
Ö»ÐèÒªÔÚ merge µÄʱºòʹÓà --no-ff Ñ¡Ïî¼´¿É¸æËß Git ²»ÒªÊ¹Óà Fast-forward
·½Ê½ºÏ²¢·ÖÖ§¡£
ÕâÑù Git ¾Í»á¹Ô¹ÔµØʹÓÃÈý·½ºÏ²¢£¨Three-way merge£©£º
OK£¬ÕâÑù¾ÍËãɾµôÁË¡°feature¡±·ÖÖ§£¬ÎÒÃÇÈÔÈ»¿ÉÒÔºÜÈÝÒ׿´³öÓиö·ÖÖ§Ôø¾´æÔÚ¹ý£º
GitʹÓý̵̳½ÕâÀï¾Í¸æÒ»¶ÎÂäÁË£¬Ëæºó»á¿ÉÄÜ»á¸üÐÂС¼×Óã·ÒëµÄGithub¹Ù·½½Ì³Ì°Â~~~
|