高度なアプリケーションのGit(B)

高度なGitの(B)

================================================== =============================

概要:


================================================== =============================

Gitのブランチ

1.分岐命名法及び一般的なコマンド

マスター(メインブランチ)は最近提出の指定したブランチへのポインタです。

DEV devの枝は、最新の投稿を指しています。

どんなに多くの枝、枝の活動は一つだけ持つことはできません。

ヘッドは最後反映コミット現在の作業ディレクトリを示すマップを頭、枝を指している必要があります。つまり、常に頭の最後のコミット活動のブランチを指します。

枝命名法

  • あなたはなく、「/」最後に、「/」を使用することができます。

  • あなたはで始めることはできません - 「」;

  • 配置されるように、「/」のアセンブリの後ろに、で始めることはできません「」;

  • あなたは連続使用することはできません「...」;

  • あなたは、空白文字を「」使用することはできません。

  • あなたは、 "〜"、 "?"、 "*"、 "[" "^" を使用し、他の記号はできません

一意である必要があり、分岐先支店名は、常に最新の提出を指します。

Gitの支店:リスト、枝の作成と削除

  • gitのブランチBRANCH_NAME [START_COMMIT]

  • gitのブランチ-d BRANCH_NAME削除支店

のgit-支店ショー:提出ビューブランチとその関連

Gitチェックアウト 

  • gitのチェックアウト<枝>検出ブランチ

デモ1:Gitのブランチを作成します

[root@node1 test]# ls
first.sh  INSTALL  readmin  subdir
[root@node1 test]# git branch --list
* master   # 带"*"表示当前分支
[root@node1 test]# git log
commit 3c0b6864718ec8f8aebb5b66fbfd65b757504169 (HEAD -> master)
Author: watao <[email protected]>
Date:   Mon Aug 19 23:06:00 2019 +0800

    v0.0.2

commit b0e9cc432d3adb683963686a2eec197129ef48b8
Author: watao <[email protected]>
Date:   Tue Jul 16 23:26:38 2019 +0800

    v0.0.1
[root@node1 test]# git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	new file:   first.sh

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	readmin

[root@node1 test]# git commit -m 'v1.0'
[master 13051f2] v1.0
 1 file changed, 4 insertions(+)
 create mode 100644 first.sh

[root@node1 test]# git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

	readmin

nothing added to commit but untracked files present (use "git add" to track)

[root@node1 test]# git ls-files -s
100644 b6a56662e48ee60ef2d65fd2b00dd555e758b7fa 0	INSTALL
100644 1809e7ac283fd186a50d97b1462d2d27396f9b42 0	first.sh
100644 a4ec1ecd97368714ba8b5c8d002b1a24647bb7ec 0	subdir/1.txt

[root@node1 test]# git add readmin
[root@node1 test]# git ls-files -s
100644 b6a56662e48ee60ef2d65fd2b00dd555e758b7fa 0	INSTALL
100644 1809e7ac283fd186a50d97b1462d2d27396f9b42 0	first.sh
100644 8bf9463e75dfb20077fafb8358ee3cb471dd7900 0	readmin
100644 a4ec1ecd97368714ba8b5c8d002b1a24647bb7ec 0	subdir/1.txt

[root@node1 test]# git commit -m 'v1.1'
[master e522483] v1.1
 1 file changed, 1 insertion(+)
 create mode 100644 readmin

[root@node1 test]# git log
commit e522483313931f3dbc914ff6e132f5cd205f7d62 (HEAD -> master)
Author: watao <[email protected]>
Date:   Wed Aug 21 22:48:52 2019 +0800

    v1.1

commit 13051f2788b17981a72f641e6b30bc8bea0f2e38
Author: watao <[email protected]>
Date:   Wed Aug 21 22:46:23 2019 +0800

    v1.0

commit 3c0b6864718ec8f8aebb5b66fbfd65b757504169
Author: watao <[email protected]>
Date:   Mon Aug 19 23:06:00 2019 +0800

    v0.0.2

commit b0e9cc432d3adb683963686a2eec197129ef48b8
Author: watao <[email protected]>
Date:   Tue Jul 16 23:26:38 2019 +0800

    v0.0.1
[root@node1 test]# git branch
* master

# 指明1.0版本创建分支
[root@node1 test]# git branch dev 13051f
[root@node1 test]# git branch
  dev
* master

[root@node1 test]# git branch bug/first
[root@node1 test]# git branch
  bug/first
  dev
* master

演示2:git show-branch  查看分支

#  git show-branch 查看具体的分支信息
[root@node1 test]# git show-branch
! [bug/first] v1.1
 ! [dev] v1.0
  * [master] v1.1
---
+ * [bug/first] v1.1
++* [dev] v1.0


[root@node1 test]# git show-branch dev
[dev] v1.0
[root@node1 test]# 
[root@node1 test]# git show-branch bug/first
[bug/first] v1.1

演示3:git checkout BRANCH_NAME  切换分支

[root@node1 taotao]# git checkout dev  #切换分支
Switched to branch 'dev'
[root@node1 taotao]# 
[root@node1 taotao]# git branch --list 
  bug/first
* dev
  master
[root@node1 taotao]# 
[root@node1 taotao]# git show-branch
! [bug/first] v1.1
 * [dev] v1.0
  ! [master] v1.1
---
+ + [bug/first] v1.1
+*+ [dev] v1.0
[root@node1 taotao]# 
[root@node1 taotao]# 
[root@node1 taotao]# git log
commit 5d4298d6fdcbb6276e69f002e7148210124e52d9 (HEAD -> dev)
Author: watao <[email protected]>
Date:   Wed Oct 9 22:04:34 2019 +0800

    v1.0

commit b9182448b3e9503ce5fd09edb5b378f612209d01
Author: watao <[email protected]>
Date:   Wed Oct 9 21:05:05 2019 +0800

    v0.0.2

commit 1b5d8e0fea57e85045c8d98f12e379fdc73138bc
Author: watao <[email protected]>
Date:   Tue Oct 8 21:24:06 2019 +0800

    v0.0.1
    
#############################
[root@node1 taotao]# cat first.sh
#!/bin/bash
echo "hello world"
echo "new date"
[root@node1 taotao]# 
[root@node1 taotao]# git status
On branch dev
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:   first.sh

no changes added to commit (use "git add" and/or "git commit -a")

[root@node1 taotao]# git add first.sh
[root@node1 taotao]# git commit -m "v1.1-dev"  
[dev 587719d] v1.1-dev
 1 file changed, 1 insertion(+)
 
[root@node1 taotao]# git log
commit 587719dd3920429904c2b2a24637f20ecd20c4e0 (HEAD -> dev)
Author: watao <[email protected]>
Date:   Fri Oct 11 22:34:41 2019 +0800

    v1.1-dev

commit 5d4298d6fdcbb6276e69f002e7148210124e52d9
Author: watao <[email protected]>
Date:   Wed Oct 9 22:04:34 2019 +0800

    v1.0

commit b9182448b3e9503ce5fd09edb5b378f612209d01
Author: watao <[email protected]>
Date:   Wed Oct 9 21:05:05 2019 +0800

    v0.0.2

commit 1b5d8e0fea57e85045c8d98f12e379fdc73138bc
Author: watao <[email protected]>
Date:   Tue Oct 8 21:24:06 2019 +0800

    v0.0.1
    
[root@node1 taotao]# cat first.sh
#!/bin/bash
echo "hello world"
echo "new date"

# 切回主分支,再次查看first.sh,发现还是原来的,因为master分支并没有提交新的操作
[root@node1 taotao]# git checkout master
Switched to branch 'master'
[root@node1 taotao]# 
[root@node1 taotao]# cat first.sh 
#!/bin/bash
echo "hello world"

# 不被追踪的文件在所有分支上都可以看见
[root@node1 taotao]# git checkout dev
Switched to branch 'dev'
[root@node1 taotao]# cat first.sh 
#!/bin/bash
echo "hello world"
echo "new date"
[root@node1 taotao]# 
[root@node1 taotao]# vim second.sh
[root@node1 taotao]# cat second.sh 
#!/bin/bash
echo "second.sh"
[root@node1 taotao]# ls
first.sh  INSTALL  second.sh  subdir
[root@node1 taotao]# 
[root@node1 taotao]# git checkout master
Switched to branch 'master'
[root@node1 taotao]# 
[root@node1 taotao]# ls
first.sh  INSTALL  readmin  second.sh  subdir
[root@node1 taotao]# cat second.sh 
#!/bin/bash
echo "second.sh"

# 添加到索引发现在所有分支上依然可以看见
[root@node1 taotao]# git add second.sh
[root@node1 taotao]# git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	new file:   second.sh

[root@node1 taotao]# git checkout dev
A	second.sh
Switched to branch 'dev'
[root@node1 taotao]# git status
On branch dev
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	new file:   second.sh
	
#在dev分支上提交
[root@node1 taotao]# git commit -m "v1.1.1-dev"
[dev 21a0411] v1.1.1-dev
 1 file changed, 2 insertions(+)
 create mode 100644 second.sh
[root@node1 taotao]# git status
On branch dev
nothing to commit, working tree clean

#再次切回master分支,发现second.sh 已经没有了
[root@node1 taotao]# git checkout master
Switched to branch 'master'
[root@node1 taotao]# ls
first.sh  INSTALL  readmin  subdir
[root@node1 taotao]# git status
On branch master
nothing to commit, working tree clean


おすすめ

転載: blog.51cto.com/1992tao/2446121