Git-1 git詳解及其使用

1.1 關(guān)于版本控制

開始之前先看一個(gè)沒有版本控制的例子

image

1.1.1 本地版本控制

本地版本控制系統(tǒng) 許多人習(xí)慣用復(fù)制整個(gè)項(xiàng)目目錄的方式來保存不同的版本锥腻,或許還會(huì)改名加上備份時(shí)間以示區(qū)別牺堰。這么做唯一的 好處就是簡單,但是特別容易犯錯(cuò)鲁僚。有時(shí)候會(huì)混淆所在的工作目錄,一不小心會(huì)寫錯(cuò)文件或者覆蓋意想外的文件。

image.png

1.1.2 集中化的版本控制系統(tǒng)

如何讓在不同系統(tǒng)上的開發(fā)者協(xié)同工作倦零?于是藐石,集中化的版本控制系統(tǒng)(Centralized Version Control Systems即供,簡稱 CVCS)應(yīng)運(yùn)而生。這類系統(tǒng)于微,諸如 CVS逗嫡、Subversion 以及Perforce 等,都有一個(gè)單一的集中管理的服務(wù)器株依,保存所有文件的修訂版本驱证,而協(xié)同工作的人們都通過客戶端連到這臺(tái)服務(wù)器,取出最新的文件或者提交更新恋腕。多年以來抹锄,這已成為版本控制系統(tǒng)的標(biāo)準(zhǔn)做法。

image.png

1.1.3 分布式版本控制系統(tǒng)

在這類系統(tǒng)中,像Git伙单、Mercurial呆万、Bazaar 以及 Darcs 等,客戶端并不只提取最新版本的文件快照车份,而是把代碼倉庫完整地鏡像下來谋减。這么一來,任何一處協(xié)同工作用的服務(wù)器發(fā)生故障扫沼,事后都可以用任何一個(gè)鏡像出來的本地倉庫恢復(fù)出爹。因?yàn)槊恳淮蔚目寺〔僮鳎瑢?shí)際上都是一次對(duì)代碼倉庫的完整備份缎除。

image.png

1.2 Git簡介

官網(wǎng):https://git-scm.com

? git是一個(gè)分布式版本控制軟件严就,最初由林納斯·托瓦茲(Linus Torvalds)創(chuàng)作,于2005年以GPL發(fā)布器罐。最初目的是為更好地管理Linux內(nèi)核開發(fā)而設(shè)計(jì)梢为。

Git 官方中文手冊(cè) https://git-scm.com/book/zh/v2

1.2.1 Git歷史

自2002年開始,林納斯·托瓦茲決定使用BitKeeper作為Linux內(nèi)核主要的版本控制系統(tǒng)用以維護(hù)代碼轰坊。因?yàn)锽itKeeper為專有軟件铸董,這個(gè)決定在社區(qū)中長期遭受質(zhì)疑。在Linux社區(qū)中肴沫,特別是理查德·斯托曼與自由軟件基金會(huì)的成員粟害,主張應(yīng)該使用開放源代碼的軟件來作為Linux核心的版本控制系統(tǒng)。林納斯·托瓦茲曾考慮過采用現(xiàn)成軟件作為版本控制系統(tǒng)(例如Monotone)颤芬,但這些軟件都存在一些問題悲幅,特別是性能不佳。現(xiàn)成的方案站蝠,如CVS的架構(gòu)汰具,受到林納斯·托瓦茲的批評(píng)。
2005年菱魔,安德魯·垂鳩寫了一個(gè)簡單程序留荔,可以連接BitKeeper的存儲(chǔ)庫,BitKeeper著作權(quán)擁有者拉里·麥沃伊認(rèn)為安德魯·垂鳩對(duì)BitKeeper內(nèi)部使用的協(xié)議進(jìn)行逆向工程豌习,決定收回?zé)o償使用BitKeeper的授權(quán)存谎。Linux內(nèi)核開發(fā)團(tuán)隊(duì)與BitMover公司進(jìn)行蹉商拔疚,但無法解決他們之間的歧見肥隆。林納斯·托瓦茲決定自行開發(fā)版本控制系統(tǒng)替代BitKeeper,以十天的時(shí)間稚失,編寫出第一個(gè)git版本

1.3 安裝git

1.3.1 環(huán)境說明

[root@gitlab ~]# rpm -qa centos-release
centos-release-7-4.1708.el7.centos.x86_64
[root@gitlab ~]# uname -a
Linux gitlab 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@gitlab ~]# getenforce 
Disabled
[root@gitlab ~]# systemctl status firewalld.service 
● firewalld.service - firewalld - dynamic firewall daemon
 Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
 Active: inactive (dead)
 Docs: man:firewalld(1)

1.3.2 Yum安裝Git

centos 自帶git

[root@gitlab ~]# rpm -qa git
git-1.8.3.1-11.el7.x86_64</pre>

安裝方法

[root@gitlab ~]# yum install git -y

1.3.3 編譯安裝

編譯安裝可以安裝較新版本的git

Git下載地址: https://github.com/git/git/releases

# 安裝依賴關(guān)系
yum install curl-devel expat-devel gettext-devel  openssl-devel zlib-devel
# 編譯安裝
tar -zxf git-2.0.0.tar.gz
cd git-2.0.0
make configure
./configure --prefix=/usr
make  
make install

1.4 初次運(yùn)行 Git 前的配置

1.4.1 配置git

命令集

git config --global user.name "username"  #配置git使用用戶
git config --global user.email "email@mail.com"  #配置git使用郵箱
git config --global color.ui true  #語法高亮
git config --list # 查看全局配置

配置過程

[root@gitlab ~]# git config --global user.name "tigerfive"  #配置git使用用戶
[root@gitlab ~]# git config --global user.email "tigerfive@aliyun.com"  #配置git使用郵箱
[root@gitlab ~]# git config --global color.ui true  #語法高亮
[root@gitlab ~]# git config --list # 查看全局配置
user.name=tigerfive
user.mail=tigerfive@aliyun.com
color.ui=true

生成的配置文件

[root@gitlab ~]# cd
[root@gitlab ~]# cat .gitconfig 
[user]
 name = tigerfive
 email = tigerfive@aliyun.com
[color]
 ui = true

1.4.2 獲取幫助

使用Git時(shí)需要獲取幫助栋艳,有三種方法可以找到Git命令的使用手冊(cè):

git help <verb>
git <verb> --help
man git-<verb></pre>

1.5 獲取 Git 倉庫(初始化倉庫)

# 創(chuàng)建目錄
mkdir git_data
# 進(jìn)入目錄
cd git_data/
# 初始化
git init
# 查看工作區(qū)狀態(tài)
git status

操作過程

[root@gitlab ~]# mkdir -p /data/git_data
[root@gitlab ~]# cd /data/git_data
[root@gitlab git_data]# git init
初始化空的 Git 版本庫于 /data/git_data/.git/
Initialized empty Git repository in /data/git_data/.git/
[root@gitlab git_data]# git status
# 位于分支 master
#
# 初始提交
#
無文件要提交(創(chuàng)建/拷貝文件并使用 "git add" 建立跟蹤)
?
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

1.6 Git命令常規(guī)操作

常用命令說明

命令 命令說明
add 添加文件內(nèi)容至索引
bisect 通過二分查找定位引入 bug 的變更
branch 列出、創(chuàng)建或刪除分支
checkout 檢出一個(gè)分支或路徑到工作區(qū)
clone 克隆一個(gè)版本庫到一個(gè)新目錄
commit 記錄變更到版本庫
diff 顯示提交之間句各、提交和工作區(qū)之間等的差異
fetch 從另外一個(gè)版本庫下載對(duì)象和引用
grep 輸出和模式匹配的行
init 創(chuàng)建一個(gè)空的
Git 版本庫或重新初始化一個(gè)已存在的版本庫
log 顯示提交日志
merge 合并兩個(gè)或更多開發(fā)歷史
mv 移動(dòng)或重命名一個(gè)文件吸占、目錄或符號(hào)鏈接
pull 獲取并合并另外的版本庫或一個(gè)本地分支
push 更新遠(yuǎn)程引用和相關(guān)的對(duì)象
rebase 本地提交轉(zhuǎn)移至更新后的上游分支中
reset 重置當(dāng)前HEAD到指定狀態(tài)
rm 從工作區(qū)和索引中刪除文件
show 顯示各種類型的對(duì)象
status 顯示工作區(qū)狀態(tài)
tag 創(chuàng)建晴叨、列出、刪除或校驗(yàn)一個(gè)GPG簽名的 tag 對(duì)象

常用操作示意圖

image.png

文件的狀態(tài)變化周期

image.png

1.6.1 創(chuàng)建文件

[root@gitlab git_data]# touch README
[root@gitlab git_data]# git status
# 位于分支 master
#
# 初始提交
#
# 未跟蹤的文件:
#   (使用 "git add <file>..." 以包含要提交的內(nèi)容)
#
#    README
提交為空矾屯,但是存在尚未跟蹤的文件(使用 "git add" 建立跟蹤)
---
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       README
nothing added to commit but untracked files present (use "git add" to track)

添加文件跟蹤

[root@gitlab git_data]# git add ./*
[root@gitlab git_data]# git status
# 位于分支 master
#
# 初始提交
#
# 要提交的變更:
#   (使用 "git rm --cached <file>..." 撤出暫存區(qū))
#
#    新文件:    README
#
---
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   README
#

文件會(huì)添加到.git的隱藏目錄

[root@gitlab git_data]# tree  .git/
.git/
├── branches
├── config
├── description
├── HEAD
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── prepare-commit-msg.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   └── update.sample
├── index
├── info
│   └── exclude
├── objects
│   ├── e6
│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391
│   ├── info
│   └── pack
└── refs
 ├── heads
 └── tags

由工作區(qū)提交到本地倉庫

[root@gitlab git_data]# git commit  -m 'first commit'  
[master(根提交) bb963eb] first commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README

查看git的狀態(tài)

[root@gitlab git_data]# git status
# 位于分支 master
無文件要提交兼蕊,干凈的工作區(qū)
?
# On branch master
nothing to commit, working directory clean

提交后的git目錄狀態(tài)

[root@gitlab git_data]# tree  .git/
.git/
├── branches
├── COMMIT_EDITMSG
├── config
├── description
├── HEAD
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── prepare-commit-msg.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   └── update.sample
├── index
├── info
│   └── exclude
├── logs
│   ├── HEAD
│   └── refs
│       └── heads
│           └── master
├── objects
│   ├── 54
│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd
│   ├── bb
│   │   └── 963eb32ad93a72d9ce93e4bb55105087f1227d
│   ├── e6
│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391
│   ├── info
│   └── pack
└── refs
 ├── heads
 │   └── master
 └── tags

1.6.2 添加新文件

git add  * 添加到暫存區(qū)域
git commit  提交git倉庫 -m 后面接上注釋信息,內(nèi)容關(guān)于本次提交的說明件蚕,方便自己或他人查看

常規(guī)方法

git add  *
git commit

簡便方法

git commit -a  -m "注釋信息"

-a 表示直接提交

Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are
not affected.

1.6.3 刪除git內(nèi)的文件

命令說明:

? 沒有添加到暫存區(qū)的數(shù)據(jù)直接rm刪除即可孙技。

? 已經(jīng)添加到暫存區(qū)數(shù)據(jù):

git rm --cached database

將文件從git暫存區(qū)域的追蹤列表移除(并不會(huì)刪除當(dāng)前工作目錄內(nèi)的數(shù)據(jù)文件)

git rm -f database

將文件數(shù)據(jù)從git暫存區(qū)和工作目錄一起刪除

命令實(shí)踐:

# 創(chuàng)建新文件

[root@gitlab git_data]# touch 123
[root@gitlab git_data]# git status
# 位于分支 master
# 未跟蹤的文件:
#   (使用 "git add <file>..." 以包含要提交的內(nèi)容)
#
#    123
提交為空,但是存在尚未跟蹤的文件(使用 "git add" 建立跟蹤)
---
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       123
nothing added to commit but untracked files present (use "git add" to track)

將文件添加到暫存區(qū)域

[root@gitlab git_data]# git add 123
[root@gitlab git_data]# git status
# 位于分支 master
# 要提交的變更:
#   (使用 "git reset HEAD <file>..." 撤出暫存區(qū))
#
#    新文件:    123
---
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   123

刪除文件

[root@gitlab git_data]# rm 123 -f
[root@gitlab git_data]# ls
README
[root@gitlab git_data]# git status
# 位于分支 master
# 要提交的變更:
#   (使用 "git reset HEAD <file>..." 撤出暫存區(qū))
#
#    新文件:    123
#
# 尚未暫存以備提交的變更:
#   (使用 "git add/rm <file>..." 更新要提交的內(nèi)容)
#   (使用 "git checkout -- <file>..." 丟棄工作區(qū)的改動(dòng))
#
#    刪除:      123
# 
---
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   123
#
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    123
[root@gitlab git_data]# git reset HEAD  ./* 
[root@gitlab git_data]# git status
# 位于分支 master
無文件要提交排作,干凈的工作區(qū)
---
# On branch master
nothing to commit, working directory clean

1.6.4 重命名暫存區(qū)數(shù)據(jù)

沒有添加到暫存區(qū)的數(shù)據(jù)直接mv/rename改名即可牵啦。
已經(jīng)添加到暫存區(qū)數(shù)據(jù):

git mv README NOTICE
[root@gitlab git_data]# git mv README notice
[root@gitlab git_data]# git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       renamed:    README -> notice

1.6.5 查看歷史記錄

? git log #→查看提交歷史記錄
? git log -2 #→查看最近幾條記錄
? git log -p -1 #→-p顯示每次提交的內(nèi)容差異,例如僅查看最近一次差異
? git log --stat -2 #→--stat簡要顯示數(shù)據(jù)增改行數(shù),這樣能夠看到提交中修改過的內(nèi)容妄痪,對(duì)文件添加或移動(dòng)的行數(shù)哈雏,并在最后列出所有增減行的概要信息
? git log --pretty=oneline #→--pretty根據(jù)不同的格式展示提交的歷史信息
? git log --pretty=fuller -2 #→以更詳細(xì)的模式輸出提交的歷史記錄
? git log --pretty=fomat:"%h %cn" #→查看當(dāng)前所有提交記錄的簡短SHA-1哈希字串與提交著的姓名。

使用format參數(shù)來指定具體的輸出格式

格式 說明
%s 提交說明衫生。
%cd 提交日期裳瘪。
%an 作者的名字。
%cn 提交者的姓名罪针。
%ce 提交者的電子郵件盹愚。
%H 提交對(duì)象的完整SHA-1哈希字串。
%h 提交對(duì)象的簡短SHA-1哈希字串站故。
%T 樹對(duì)象的完整SHA-1哈希字串皆怕。
%t 樹對(duì)象的簡短SHA-1哈希字串。
%P 父對(duì)象的完整SHA-1哈希字串西篓。
%p 父對(duì)象的簡短SHA-1哈希字串愈腾。
%ad 作者的修訂時(shí)間。

命令實(shí)踐

[root@gitlab git_data]# git log
commit f5b79552635a7dc60afc35c99c1170366d8c5f6b
Author: tigerfive <tigerfive@aliyun.com>
Date:   Sat May 11 21:29:21 2019 -0700
?
 456
?
commit e9ed8b38a0052cdcd85ecee833ea8198b077f881
Author: tigerfive <root@vmdesk.localdomain>
Date:   Sat May 11 21:21:12 2019 -0700
?
 commit 123
?
commit 9d394114177b8da9e452d001ec610e9c45ceede3
Author: tigerfive <root@vmdesk.localdomain>
Date:   Sat May 11 20:19:23 2019 -0700
?
 first commit

1.6.6 還原歷史數(shù)據(jù)

Git服務(wù)程序中有一個(gè)叫做HEAD的版本指針岂津,當(dāng)用戶申請(qǐng)還原數(shù)據(jù)時(shí)虱黄,其實(shí)就是將HEAD指針指向到某個(gè)特定的提交版本,但是因?yàn)镚it是分布式版本控制系統(tǒng)吮成,為了避免歷史記錄沖突橱乱,故使用了SHA-1計(jì)算出十六進(jìn)制的哈希字串來區(qū)分每個(gè)提交版本,另外默認(rèn)的HEAD版本指針會(huì)指向到最近的一次提交版本記錄粱甫,而上一個(gè)提交版本會(huì)叫HEAD泳叠,上上一個(gè)版本則會(huì)叫做HEAD^,當(dāng)然一般會(huì)用HEAD~5來表示往上數(shù)第五個(gè)提交版本茶宵。

git reset --hard hash

git reset --hard HEAD^ #→還原歷史提交版本上一次

git reset --hard 3de15d4 #→找到歷史還原點(diǎn)的SHA-1值后危纫,就可以還原(值不寫全,系統(tǒng)會(huì)自動(dòng)匹配)

測試命令

[root@gitlab git_data]# git log
commit f5b79552635a7dc60afc35c99c1170366d8c5f6b
Author: tigerfive <tigerfive@aliyun.com>
Date:   Sat May 11 21:29:21 2019 -0700
?
 456
?
commit e9ed8b38a0052cdcd85ecee833ea8198b077f881
Author: tigerfive <root@vmdesk.localdomain>
Date:   Sat May 11 21:21:12 2019 -0700
?
 commit 123
?
commit 9d394114177b8da9e452d001ec610e9c45ceede3
Author: tigerfive <root@vmdesk.localdomain>
Date:   Sat May 11 20:19:23 2019 -0700
?
 first commit

? 還原數(shù)據(jù)

[root@gitlab git_data]# git reset --hard e9ed8b38a
HEAD is now at e9ed8b3 commit 123
HEAD 現(xiàn)在位于 e9ed8b3 commit 123
# 查看數(shù)據(jù)
[root@gitlab git_data]# ls
123 README

1.6.7 還原未來數(shù)據(jù)

什么是未來數(shù)據(jù)?就是你還原到歷史數(shù)據(jù)了,但是你后悔了种蝶,想撤銷更改契耿,但是git log已經(jīng)找不到這個(gè)版本了。

git reflog #→查看未來歷史更新點(diǎn)

測試命令

[root@gitlab git_data]#  git reflog
e9ed8b3 HEAD@{0}: reset: moving to e9ed8b38a
f5b7955 HEAD@{1}: commit: 456
e9ed8b3 HEAD@{2}: commit: commit 123
9d39411 HEAD@{3}: commit (initial): first commit

1.6.8 標(biāo)簽使用

前面回滾使用的是一串字符串螃征,又長又難記搪桂。
git tag v1.0 #→當(dāng)前提交內(nèi)容打一個(gè)標(biāo)簽(方便快速回滾),每次提交都可以打個(gè)tag盯滚。
git tag#→查看當(dāng)前所有的標(biāo)簽
git show v1.0 #→查看當(dāng)前1.0版本的詳細(xì)信息
git tag v1.2 -m "version 1.2 release is test" #→創(chuàng)建帶有說明的標(biāo)簽,-a指定標(biāo)簽名字锅棕,-m指定說明文字
git tag -d v1.0#→我們?yōu)橥粋€(gè)提交版本設(shè)置了兩次標(biāo)簽,刪除之前的v1.0

測試命令

[root@gitlab git_data]# git reset --hard e9ed8b38a
HEAD is now at e9ed8b3 commit 123
[root@gitlab git_data]# git reset --hard V1.0
HEAD is now at e9ed8b3 add test dir

[root@gitlab git_data]# git tag  v20171129
[root@gitlab git_data]# git tag 
v20171129

1.6.9 對(duì)比數(shù)據(jù)

?git diff可以對(duì)比當(dāng)前文件與倉庫已保存文件的區(qū)別,知道了對(duì)README作了什么修改后淌山,再把它提交到倉庫就放?多了裸燎。

git diff README
git diff --name-only HEAD HEAD^
git diff --name-only head_id head_id2

1.7 分支結(jié)構(gòu)

在實(shí)際的項(xiàng)目開發(fā)中,盡量保證master分支穩(wěn)定泼疑,僅用于發(fā)布新版本德绿,平時(shí)不要隨便直接修改里面的數(shù)據(jù)文件。

那在哪干活呢退渗?干活都在dev分支上移稳。每個(gè)人從dev分支創(chuàng)建自己個(gè)人分支,開發(fā)完合并到dev分支会油,最后dev分支合并到master分支个粱。所以團(tuán)隊(duì)的合作分支看起來會(huì)像下圖那樣。

image.png

1.7.1 分支切換

[root@gitlab git_data]# git branch tiger  #創(chuàng)建分支
[root@gitlab git_data]# git branch 
* master
 tiger
[root@gitlab git_data]# git checkout tiger 
切換到分支 'tiger'
Switched to branch 'tiger'
[root@gitlab git_data]# git branch 
 master
* tiger

在tiger 分支進(jìn)行修改

This is git_data readme
[root@gitlab git_data]#  echo '1901' >> README 
[root@gitlab git_data]# git add .
[root@gitlab git_data]# git commit -m '1901'
[tiger 4310e7e] 1901
 1 file changed, 1 insertion(+)
[root@gitlab git_data]# git status
# On branch tiger
nothing to commit, working directory clean
---
# 位于分支 tiger
無文件要提交翻翩,干凈的工作區(qū)

回到master****分支

[root@gitlab git_data]# git checkout master
Switched to branch 'master'
切換到分支 'master'
[root@gitlab git_data]# cat README 
This is git_data readme
[root@gitlab git_data]# git log  -1
commit f5b79552635a7dc60afc35c99c1170366d8c5f6b
Author: tigerfive <tigerfive@aliyun.com>
Date:   Sat May 11 21:29:21 2019 -0700
?
 456

合并代碼

[root@gitlab git_data]#  git merge tiger
Updating f5b7955..4310e7e
Fast-forward
 README | 1 +
 1 file changed, 1 insertion(+)
[root@gitlab git_data]# git status
# On branch master
nothing to commit, working directory clean
# 位于分支 master
無文件要提交都许,干凈的工作區(qū)
[root@gitlab git_data]# cat README 
This is git_data readme
1901

1.7.2 合并失敗解決

模擬沖突,在文件的同一行做不同修改

在master 分支進(jìn)行修改

[root@gitlab git_data]# cat README 
This is git_data readme
1901
[root@gitlab git_data]#  echo '1901-git' > README 
[root@gitlab git_data]#  git commit -m 'tiger 1901-git'
[master 4e6c548] tiger 1901-git
 1 file changed, 1 insertion(+), 2 deletions(-)

切換到tiger****分支

[root@gitlab git_data]# git checkout tiger
Switched to branch 'tiger'
[root@gitlab git_data]# cat README 
This is git_data readme
1901
[root@gitlab git_data]# echo 'tiger' >> README 
[root@gitlab git_data]# git commit -m '1901-git-check'
# On branch tiger
# 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
#
no changes added to commit (use "git add" and/or "git commit -a")

回到master****分區(qū)嫂冻,進(jìn)行合并胶征,出現(xiàn)沖突

[root@gitlab git_data]# git checkout master 
切換到分支 'master'
[root@gitlab git_data]# git merge linux
自動(dòng)合并 README
沖突(內(nèi)容):合并沖突于 README
自動(dòng)合并失敗,修正沖突然后提交修正的結(jié)果桨仿。

解決沖突

[root@gitlab git_data]# vim README 
This is git_data readme
1901
tiger
meger test ti
meger test master

手工解決沖突

[root@gitlab git_data]# git commit -a -m "merge-ti-test"
[master 2594b2380] merge-ti-test

1.7.3 刪除分支

因?yàn)橹耙呀?jīng)合并了tiger分支睛低,所以現(xiàn)在看到它在列表中。 在這個(gè)列表中分支名字前沒有 * 號(hào)的分支通撤可以使用 git branch -d 刪除掉钱雷;你已經(jīng)將它們的工作整合到了另一個(gè)分支,所以并不會(huì)失去任何東西吹零。

查看所有包含未合并工作的分支罩抗,可以運(yùn)行 git branch --no-merged

這里顯示了其他分支。 因?yàn)樗诉€未合并的工作瘪校,嘗試使用 git branch -d命令刪除它時(shí)會(huì)失敵文骸:

git branch -d testing
error: The branch 'testing' is not fully merged.
If you are sure you want to delete it, run 'git branch -D testing'. 

如果真的想要?jiǎng)h除分支并丟掉那些工作名段,如同幫助信息里所指出的阱扬,可以使用 -D 選項(xiàng)強(qiáng)制刪除它泣懊。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市麻惶,隨后出現(xiàn)的幾起案子馍刮,更是在濱河造成了極大的恐慌,老刑警劉巖窃蹋,帶你破解...
    沈念sama閱讀 219,039評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件卡啰,死亡現(xiàn)場離奇詭異,居然都是意外死亡警没,警方通過查閱死者的電腦和手機(jī)匈辱,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,426評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來杀迹,“玉大人亡脸,你說我怎么就攤上這事∈骼遥” “怎么了浅碾?”我有些...
    開封第一講書人閱讀 165,417評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長续语。 經(jīng)常有香客問我垂谢,道長,這世上最難降的妖魔是什么疮茄? 我笑而不...
    開封第一講書人閱讀 58,868評(píng)論 1 295
  • 正文 為了忘掉前任滥朱,我火速辦了婚禮,結(jié)果婚禮上力试,老公的妹妹穿的比我還像新娘焚虱。我一直安慰自己,他們只是感情好懂版,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,892評(píng)論 6 392
  • 文/花漫 我一把揭開白布鹃栽。 她就那樣靜靜地躺著,像睡著了一般躯畴。 火紅的嫁衣襯著肌膚如雪民鼓。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,692評(píng)論 1 305
  • 那天蓬抄,我揣著相機(jī)與錄音丰嘉,去河邊找鬼。 笑死嚷缭,一個(gè)胖子當(dāng)著我的面吹牛饮亏,可吹牛的內(nèi)容都是我干的耍贾。 我是一名探鬼主播,決...
    沈念sama閱讀 40,416評(píng)論 3 419
  • 文/蒼蘭香墨 我猛地睜開眼路幸,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼荐开!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起简肴,我...
    開封第一講書人閱讀 39,326評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤晃听,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后砰识,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體能扒,經(jīng)...
    沈念sama閱讀 45,782評(píng)論 1 316
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,957評(píng)論 3 337
  • 正文 我和宋清朗相戀三年辫狼,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了初斑。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,102評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡膨处,死狀恐怖见秤,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情灵迫,我是刑警寧澤秦叛,帶...
    沈念sama閱讀 35,790評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站瀑粥,受9級(jí)特大地震影響挣跋,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜狞换,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,442評(píng)論 3 331
  • 文/蒙蒙 一避咆、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧修噪,春花似錦查库、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,996評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至脏款,卻和暖如春围苫,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背撤师。 一陣腳步聲響...
    開封第一講書人閱讀 33,113評(píng)論 1 272
  • 我被黑心中介騙來泰國打工剂府, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人剃盾。 一個(gè)月前我還...
    沈念sama閱讀 48,332評(píng)論 3 373
  • 正文 我出身青樓腺占,卻偏偏與公主長得像淤袜,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子衰伯,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,044評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • 前言: 一铡羡、git是什么? 事情是這樣的嚎研,自2002年開始蓖墅,林納斯·托瓦茲決定使用BitKeeper作為Linux...
    王魔王閱讀 1,071評(píng)論 0 7
  • 朋友整理的库倘,放這里偶爾過來看看 一临扮、基本介紹 首先,Git作為版本控制系統(tǒng)教翩,他的原理與SVN為首的集中式版本控制系...
    allenzhan閱讀 1,002評(píng)論 0 3
  • GIT分布式版本控制系統(tǒng)最佳實(shí)踐 這篇文章來自于老男孩教育高級(jí)架構(gòu)師班12期的徐亮偉同學(xué)杆勇。 首先感謝老男孩架構(gòu)師班...
    meng_philip123閱讀 3,413評(píng)論 4 36
  • 引子 如果要寫一篇論文,會(huì)經(jīng)歷初稿饱亿、修改版蚜退、再次修改版……如果要設(shè)計(jì)一張海報(bào),海報(bào)初版0510彪笼、修改版0511钻注、修...
    牧?xí)砸蒿L(fēng)閱讀 1,382評(píng)論 0 1
  • 久違的晴天,家長會(huì)配猫。 家長大會(huì)開好到教室時(shí)幅恋,離放學(xué)已經(jīng)沒多少時(shí)間了。班主任說已經(jīng)安排了三個(gè)家長分享經(jīng)驗(yàn)泵肄。 放學(xué)鈴聲...
    飄雪兒5閱讀 7,523評(píng)論 16 22