Why should there be branches, there are branches so that many people can be more efficient development. View branches, branch list
$ git Branch
* Master
administrator@young-pc MINGW64 ~/helloworld (Master)
There is only one branch, and then there is a * number in front of master, which represents the current branch. Create branch, switch branch git checkout-b
#创建并切换分支 $ git checkout-b feature-a switched to A new branch ' feature-a ' administrator@young-pc MINGW64 ~/helloworld (FEA TURE-A) $ #或者执行下面的连续两条是同样的效果 administrator@young-pc MINGW64 ~/helloworld (feature-a) $ git branch feature-a fatal:a branc
H named ' Feature-a ' already exists. ADMINISTRATOR@YOUNG-PC MINGW64 ~/helloworld (feature-a) $ git checkout feature-a already on ' feature-a ' administrator@you NG-PC MINGW64 ~/helloworld (feature-a) $ git branch * feature-a master administrator@young-pc MINGW64 ~/helloworld (feat URE-A) $ #如果在分支 feature-a under operations such as the above master, then called the nurture branch, to actually operate under $ VI readm.md administrator@young-pc MINGW64 ~/helloworld (feat
URE-A) $ git add readm.md warning:lf'll be a replaced by CRLF in READM.MD.
The file would have their original line endings in your working directory. ADMINISTRATOR@YOUNG-PC MINGW64 ~/helloworld (feature-a) $ git commit-m "Add feature-a" [Feature-a WARNING:LF would be is re
Placed by CRLF in Readm.md. The file would have their original line endings in your Working directory.
1EFF5AA] Add feature-a warning:lf'll be replaced by CRLF in READM.MD.
The file would have their original line endings in your working directory. 1 file changed, 2 insertions (+) administrator@young-pc MINGW64 ~/helloworld (feature-a) $ #修改分支feature-a sort of finished, See if the Master branch is affected administrator@young-pc MINGW64 ~/helloworld (feature-a) $ git che checkout cherry cherry-pic K administrator@young-pc MINGW64 ~/helloworld (feature-a) $ git che checkout cherry cherry-pick administrator@ YOUNG-PC MINGW64 ~/helloworld (feature-a) $ git checkout master switched to branch ' master ' administrator@young-pc MINGW64
~/helloworld (Master) $ cat readm.md Hello World! #get some diff administrator@young-pc MINGW64 ~/helloworld (Master) #重新切换为feature-A $ git checkout feature-a switched to B
Ranch ' feature-a ' administrator@young-pc MINGW64 ~/helloworld (feature-a) $ cat readm.md Hello World! #get some diff-feature-a administrator@young-pc MINGW64 ~/helloworld (feature-A) $
Feature Branch
The concept of attribute branching is to centralize the implementation of a single feature, in addition to branching out of any job, and in everyday development, it is often possible to create several feature branches, while maintaining a stable branch that can release software at any time, typically master.
For a feature branch, generally in order to implement a function, in addition to do not do any work, even in the development process found a bug, you need to create a new branch, in the new branch to fix. Trunk Branch
General configuration in a formal environment, tag tags are required, and multiple releases are managed, so there are multiple trunk branches. git merge Merge branch
ADMINISTRATOR@YOUNG-PC MINGW64 ~/helloworld (feature-a)
$ #切换到主干分支
administrator@young-pc MINGW64 ~/ HelloWorld (feature-a)
$ git checkout master
switched to branch ' master '
administrator@young-pc MINGW64 ~/ HelloWorld (Master)
$ git checkout master
already on ' master '
administrator@young-pc MINGW64 ~/helloworld ( Master)
#多次切换会提示
$ git checkout master
already on ' master '
administrator@young-pc MINGW64 ~/ HelloWorld (Master)
#用这个命令进行合并, after execution will pop up a text to ask you to edit, if you do not need to save directly, after the save is complete pop up the following tips
$ git merge--no-ff Feature-a
Merge made by the ' recursive ' strategy.
readm.md | 2 + +
1 file changed, 2 insertions (+)
administrator@young-pc MINGW64 ~/helloworld (master)
$
view branches in a chart form
$ #以图表形式查看分支
administrator@young-pc MINGW64 ~/helloworld (master)
$ git log--graph
* Commit bc39e02e659481efad23e28cc893da33e4ad2283
|\ merge:478c9d6 1eff5aa
| | Author:thinker Young <x695@qq.com>
| | Date: Fri Mar 18:37:04 +0800
| | | | Merge branch ' feature-a '
| |
| * Commit 1eff5aac5583332f40846edfffaee45e86c18d18
|/ Author: Thinker Young <x695@qq.com>
| Date: Wed Mar 9 20:46:18 +0800
|
| Add feature-a
|
* Commit 478c9d6a50b3d44e3c57d534b899242e2dbc2a8a
| Author:thinker Young <x695@qq.com>
| Date: Wed Mar 9 20:29:28 +0800
|
| ADD Index
|
* Commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff
author:thinker young <x695@qq.com>
Date: Wed Mar 9 20:06:28 +0800
Frist commit
administrator@young-pc MINGW64 ~/helloworld (master)
$
Backtracking History version
#查看下版本信息 $ git log--graph * commit bc39e02e659481efad23e28cc893da33e4ad2283 |\ merge:478c9d6 1EFF5AA | | Author:thinker Young <x695@qq.com> | | Date:fri Mar 11 18:37:04 2016 +0800 | | | | Merge branch ' feature-a ' | | | * Commit 1eff5aac5583332f40846edfffaee45e86c18d18 |/author:thinker Young <x695@qq.com> | date:wed Mar 9 20:46:18 2016 +0800 | |
ADD Feature-a | * Commit 478C9D6A50B3D44E3C57D534B899242E2DBC2A8A | Author:thinker Young <x695@qq.com> | date:wed Mar 9 20:29:28 2016 +0800 | |
ADD Index | * Commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff Author:thinker young <x695@qq.com> date:wed Mar 9 20:06:28 +0800 Frist Commit administrator@young-pc MINGW64 ~/helloworld (Master) #回退到创建feature-A before version $ git reset--har D 478c9d6a50b3d44e3c57d534b899242e2dbc2a8a HEAD is now at 478c9d6 ADD index administrator@young-pc MINGW64 ~/helloworld (M Aster) #查看日志, fallback success $ git log--graph * commit 478c9d6a50b3d44e3c57d534b899242e2dbc2a8a | Author:thinker Young <x695@qq.com> | date:wed Mar 9 20:29:28 2016 +0800 | |
ADD Index | * Commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff Author:thinker young <x695@qq.com> date:wed Mar 9 20:06:28 +0800 Frist Commit administrator@young-pc MINGW64 ~/helloworld (master) #如果我后悔了, want to undo the operation, then you can look at the entire warehouse log, find the hash Value, fallback again $ git reflog 478c9d6 head@{0}: reset:moving to 478c9d6a50b3d44e3c57d534b899242e2dbc2a8a bc39e02 head@{1}: Merg
E feature-a: Merge made by the ' recursive ' strategy. 478c9d6 head@{2}: checkout:moving from master to master 478c9d6 head@{3}: checkout:moving from master to master 478c9d6 HEAD@{4}: Checkout:moving from feature-a to master 1EFF5AA head@{5}: checkout:moving from master to feature-a 478c9d6 HE AD@{6}: Checkout:moving from feature-a to master 1EFF5AA head@{7}: checkout:moving from master to feature-a 478c9d6 HEAD @{8}: Checkout:moving from feature-a to master 1EFF5AA head@{9}: Commit:add feature-a 478c9d6 head@{10}: Checkout:moving from feature-a to Feature-a 478c9d6 head@{11}: checkout:moving from master to feature-a 478c9d6 HEAD @{12}: Commit:add index 05791AA head@{13}: Commit (initial): Frist commit administrator@young-pc MINGW64 ~/helloworld (ma ster) $ git reset--hard bc39e02 HEAD is now at BC39E02 Merge Branch ' feature-a ' administrator@young-pc MINGW64 ~/hellowor
LD (Master) #回退成功, view version history $ git log--graph * commit bc39e02e659481efad23e28cc893da33e4ad2283 |\ merge:478c9d6 1EFF5AA | | Author:thinker Young <x695@qq.com> | | Date:fri Mar 11 18:37:04 2016 +0800 | | | | Merge branch ' feature-a ' | | | * Commit 1eff5aac5583332f40846edfffaee45e86c18d18 |/author:thinker Young <x695@qq.com> | date:wed Mar 9 20:46:18 2016 +0800 | |
ADD Feature-a | * Commit 478C9D6A50B3D44E3C57D534B899242E2DBC2A8A | Author:thinker Young <x695@qq.com> | date:wed Mar 9 20:29:28 2016 +0800 | |
ADD Index | * Commit 05791AAA9ACDCC8420AE8E61827EE1F41FBB45FF author:thinker Young <x695@qq.com> date:wed Mar 9 20:06:28 +0800 Frist commit administrator@young-pc MINGW64
~/helloworld (Master) $
version backtracking for complex pointsThe version is rolled back to the state before the branch A was created, then the branch feature-b is created, the Readme.md file is modified, the location of the feature-a is modified, and then the modifications are submitted directly. Merging the version back into the state after branch A and then committing B commits a conflict and resolves the conflict.
#创建分支B $ git Branch feature-b administrator@young-pc MINGW64 ~/helloworld (Master) $ git checkout feature-b switched to BR Anch ' feature-b ' administrator@young-pc MINGW64 ~/helloworld (feature-b) $ ls readm.md administrator@young-pc MINGW64 ~/H
Elloworld (feature-b) $ vi readm.md administrator@young-pc MINGW64 ~/helloworld (feature-b) $ cat readm.md Hello World! #get some diff-feature-b administrator@young-pc MINGW64 ~/helloworld (feature-b) $ #看下日志 administrator@young-pc M INGW64 ~/helloworld (feature-b) $ git log commit 478c9d6a50b3d44e3c57d534b899242e2dbc2a8a author:thinker young <x695@ Qq.com> date:wed Mar 9 20:29:28 +0800 ADD Index commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff Author:thi Nker Young <x695@qq.com> date:wed Mar 9 20:06:28 +0800 Frist commit administrator@young-pc MINGW64 ~/hel Loworld (feature-b) $ # Commit: First add, then commit, always look like this $ git add readm.md administrator@young-pc MINGW64 ~/helloworld (feature-b) $ git commit [Feature-b f6937F8] Fix B 1 file changed, 2 insertions (+) administrator@young-pc MINGW64 ~/helloworld (feature-b) $ git log commit f6937 f8dc33977d589a26d7a50c8c35d2eb0138f author:thinker Young <x695@qq.com> date:fri Mar 19:42:55 +0800 F IX B commit 478c9d6a50b3d44e3c57d534b899242e2dbc2a8a author:thinker young <x695@qq.com> date:wed Mar 9 20:29:28 +0800 ADD Index commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff author:thinker young <x695@qq.com> Date: Wed Mar 9 20:06:28 +0800 Frist commit administrator@young-pc MINGW64 ~/helloworld (feature-b) #看下仓库更改历史 $ git re Flog F6937f8 head@{0}: Commit:fix B 478c9d6 Head@{1}: checkout:moving from master to Feature-b 478c9d6 head@{2}: Reset: Moving to 478c9d6a50b3d44e3c57d534b899242e2dbc2a8a bc39e02 head@{3}: reset:moving to Bc39e02 478c9d6 HEAD@{4}: Reset:mov ing to 478c9d6a50b3d44e3c57d534b899242e2dbc2a8a bc39e02 head@{5}: reset:moving to Bc39e02 478c9d6 HEAD@{6}: reset:moving To 478c9d6a50b3d44e3c57d534b899242e2dbc2a8a bc39e02 head@{7}: Merge feature-a: Merge made by the ' recursive ' strategy. 478c9d6 head@{8}: checkout:moving from master to master 478c9d6 head@{9}: checkout:moving from master to master 478c9d6 HEAD@{10}: Checkout:moving from feature-a to master 1EFF5AA head@{11}: checkout:moving from master to feature-a 478c9d6 HEAD@{12}: Checkout:moving from feature-a to master 1EFF5AA head@{13}: checkout:moving from master to feature-a 478c9d6 HEAD@{14}: Checkout:moving from feature-a to master 1EFF5AA head@{15}: Commit:add feature-a 478c9d6 head@{16}: Checkout: Moving from feature-a to Feature-a 478c9d6 head@{17}: checkout:moving from master to Feature-a 478c9d6 head@{18}: Commit : Add index 05791AA head@{19}: Commit (initial): Frist commit administrator@young-pc MINGW64 ~/helloworld (feature-b) #切换到
Main Branch, rollback, here the operation only affects the master branch, the changes in branch B have no effect, branch B or branch B, will not affect the master branch $ git checkout-switched to branch ' master ' ADMINISTRATOR@YOUNG-PC MINGW64 ~/helloworld (Master) #master分The support rolls back to the state after merging a branch $ git reset--hard bc39e02 HEAD is now at BC39E02 Merge branch ' feature-a ' administrator@young-pc MINGW64 ~ /helloworld (Master) #看下日志 $ git log--graph * commit bc39e02e659481efad23e28cc893da33e4ad2283 |\ merge:478c9d6 1eff5a A | | Author:thinker Young <x695@qq.com> | | Date:fri Mar 11 18:37:04 2016 +0800 | | | | Merge branch ' feature-a ' | | | * Commit 1eff5aac5583332f40846edfffaee45e86c18d18 |/author:thinker Young <x695@qq.com> | date:wed Mar 9 20:46:18 2016 +0800 | |
ADD Feature-a | * Commit 478C9D6A50B3D44E3C57D534B899242E2DBC2A8A | Author:thinker Young <x695@qq.com> | date:wed Mar 9 20:29:28 2016 +0800 | |
ADD Index | * Commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff Author:thinker young <x695@qq.com> date:wed Mar 9 20:06:28 +0800 Frist Commit administrator@young-pc MINGW64 ~/helloworld (Master) #在尝试合并分支B前, take a look at the branching situation $ git branch feat Ure-a feature-b * Master administrator@young-pc MINGW64 ~/HelloWorld (Master) #目前git的回退只是针对某个版本绘图, the created branch does not lose administrator@young-pc MINGW64 ~/helloworld (master) #合并分支B, prompting for conflicts, Unable to automate merge git merge--no-ff feature-b auto-merging readm.md CONFLICT (content): Merge CONFLICT in readm.md Automatic Merg E failed;
Fix conflicts and then commits the result. ADMINISTRATOR@YOUNG-PC MINGW64 ~/helloworld (master|
Merging) $ cat readm.md Hello World! #get some diff <<<<<<< head-feature-a =======-feature-b >>>>>>> ; Feature-b administrator@young-pc MINGW64 ~/helloworld (master| Merging) $ #进行消除冲突, direct VI edit this file $ vi readm.md administrator@young-pc MINGW64 ~/helloworld (master|
Merging) $ cat readm.md Hello World! #get some diff-feature-a-feature-b administrator@young-pc MINGW64 ~/helloworld (master| Merging) $ #再次提交 administrator@young-pc MINGW64 ~/helloworld (master| Merging) $ git add readm.md administrator@young-pc MINGW64 ~/helloworld (master| Merging) $ git commit-m "fix confict" [MasteR 43b9aec] Fix confict administrator@young-pc MINGW64 ~/helloworld (master) #查看下日志 $ git log--graph * commit 43B9AECA12 2aaeac48565751af1d57a5c435ac77 |\ merge:bc39e02 F6937f8 | | Author:thinker Young <x695@qq.com> | | Date:fri Mar 11 20:01:46 2016 +0800 | | | | Fix Confict | | | * Commit f6937f8dc33977d589a26d7a50c8c35d2eb0138f | | Author:thinker Young <x695@qq.com> | | Date:fri Mar 11 19:42:55 2016 +0800 | | | |
Fix B | | * | Commit bc39e02e659481efad23e28cc893da33e4ad2283 |\ \ merge:478c9d6 1EFF5AA | |/author:thinker Young <X695@QQ.COM&G t; |/| Date:fri Mar 11 18:37:04 2016 +0800 | | | | Merge branch ' feature-a ' | | | * Commit 1eff5aac5583332f40846edfffaee45e86c18d18 |/author:thinker Young <x695@qq.com> | date:wed Mar 9 20:46:18 2016 +0800 | |
ADD Feature-a | * Commit 478C9D6A50B3D44E3C57D534B899242E2DBC2A8A | Author:thinker Young <x695@qq.com> | date:wed Mar 9 20:29:28 2016 +0800 | |
ADD Index | * Commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff Author:thinker Young <x695@qq.com> date:wed Mar 9 20:06:28
+0800 Frist Commit administrator@young-pc MINGW64 ~/helloworld (Master)
modifying commit information git commit–amend
Modify the comments above, modify the comments to fix conflict, is actually a fix-b merge, resolve the merge when the conflict occurs only one of the procedures, the flag is not correct, need to re-modify
$ git commit--amend [master 0158CDF] Merage branch feature-b date:fri Mar 20:01:46 +0800 administrator@young-p C MINGW64 ~/helloworld (master) $ git log--graph * commit 0158cdfa04a60005b146786017a0d95b985afa84 |\ merge:bc39e02 F 6937f8 | | Author:thinker Young <x695@qq.com> | | Date:fri Mar 11 20:01:46 2016 +0800 | | | | Merage Branch Feature-b | | | * Commit f6937f8dc33977d589a26d7a50c8c35d2eb0138f | | Author:thinker Young <x695@qq.com> | | Date:fri Mar 11 19:42:55 2016 +0800 | | | |
Fix B | | * | Commit bc39e02e659481efad23e28cc893da33e4ad2283 |\ \ merge:478c9d6 1EFF5AA | |/author:thinker Young <X695@QQ.COM&G t; |/| Date:fri Mar 11 18:37:04 2016 +0800 | | | | Merge branch ' feature-a ' | | | * Commit 1eff5aac5583332f40846edfffaee45e86c18d18 |/author:thinker Young <x695@qq.com> | date:wed Mar 9 20:46:18 2016 +0800 | |
ADD Feature-a | * Commit 478C9D6A50B3D44E3C57D534B899242E2DBC2A8A | Author:thinker YounG <x695@qq.com> | date:wed Mar 9 20:29:28 2016 +0800 | |
ADD Index | * Commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff Author:thinker young <x695@qq.com> date:wed Mar 9 20:06:28 2016 +0800:
git rebase-i compression history
Before merging attribute branches, if you find that the content you have submitted has been misspelled, commit a modification to apply the modification to the previous error commit and compress it into a history.
$ #创建一个分支C administrator@young-pc MINGW64 ~/helloworld (master) $ git checkout-b feature-c switched to a new branch ' feat Ure-c ' administrator@young-pc MINGW64 ~/helloworld (feature-c) $ vi readm.md administrator@young-pc MINGW64 ~/HelloWorld
(FEATURE-C) $ cat readm.md Hello World! #get some diff-feature-a-feature-b-frature-c administrator@young-pc MINGW64 ~/helloworld (featu RE-C) #多了两行, a blank line, a word Line $ git diff diff--git a/readm.md b/readm.md index d4c4875.
04a5e98 100644---a/readm.md + + + b/readm.md @@ -3,3 +3,5 @@ -3,3 World! -feature-a-feature-b +-frature-c + administrator@young-pc MINGW64 ~/helloworld (feature-c) $ # Direct Commit Admini STRATOR@YOUNG-PC MINGW64 ~/helloworld (feature-c) $ git commit-a [feature-c 20f95ff] Add feature-c 1 file changed, 2 ins Ertions (+) administrator@young-pc MINGW64 ~/helloworld (feature-c) #删除空行, submit again $ VI readm.md ADMINISTRATOR@YOUNG-PC MINGW64 ~/helloworld (feature-c) $ git commit-a [feature-c 8cb86a8]Delete null row on Feature-c 1 file changed, 1 deletion (-) administrator@young-pc MINGW64 ~/helloworld (feature-c) $ git
Diff administrator@young-pc MINGW64 ~/helloworld (feature-c) $ cat readm.md Hello World! #get some diff-feature-a-feature-b-frature-c administrator@young-pc MINGW64 ~/helloworld (featu RE-C) $ git diff administrator@young-pc MINGW64 ~/helloworld (feature-c) #再次修改, fix error Word $ VI readm.md administrator@young-pc MINGW64 ~/helloworld (feature-c) $ git diff diff--git A/readm.md b/readm.md index DC2DEF4:
8531AB0 100644---a/readm.md + + + b/readm.md @@ -3,4 +3,4 @@ -3,4 World! -feature-a-feature-b--frature-c +-feature-c administrator@young-pc MINGW64 ~/helloworld (feature-c ) #此类的修改叫做typp $ git commit-am "fix typo" [feature-c 9c73c7c] Fix typo 1 file changed, 1 insertion (+), 1 deletion (-) ADM INISTRATOR@YOUNG-PC MINGW64 ~/helloworld (feature-c) $ git diff administrator@young-pc MINGW64 ~/helloworld (feature-c) $ #现Modified three times (1. First created 2. Delete blank line 3, modify spelling errors), then we will make this three times history administrator@young-pc MINGW64 ~/helloworld (feature-c) $ git log Commit 9c73c7c92d58c4fb005239edec00fe4b7eba5e75 Author:thinker Young <x695@qq.com> Date:fri Mar 11 20:24:40 2016 +0800 Fix Typo Commit 8cb86a