Git - 02 Devops describes the installation and deployment git

Introduction 1. Devops

01. operation and maintenance Introduction

In general, operation and maintenance engineers belong to single digits jobs in a business, or even only one. NNN face production servers, NN a staff, the workload is very large.

MTBF, MTTR, MTTF Detailed

MTBF (Mean Time Between Failures) = MTBF MTTF

MTTF (Mean Time To Failure) = mean time to failure 

MTTR (Mean Time To Repair) = mean time to repair

3个9:(1-99.9%)*365*24=8.76小时,表示该软件系统在连续运行1年时间里最多可能的业务中断时间是8.76小时。
4个9:(1-99.99%)*365*24=0.876小时=52.6分钟,表示该软件系统在连续运行1年时间里最多可能的业务中断时间是52.6分钟。
5个9:(1-99.999%)*365*24*60=5.26分钟,表示该软件系统在连续运行1年时间里最多可能的业务中断时间是5.26分钟。
6个9:(1-99.9999%)*365*24*60*60=31秒

Flowchart code on line

Operation and maintenance engineers of the three core functions

What is 02. Devops

Development development
operation and maintenance operations

03. Devops Why can

improve product quality

1 automated continuous integration testing 2 3 4 programmers code quality management tool to encourage division

How to implement 04. Devops

Since so good? Why do some companies do not design architecture planning - code stored - build - test, pre-production, deployment, monitoring,

2. Git version control system

01. Version Control System Introduction

vcs version control system

Version control system is a recording of one or several file content changes, for future reference content specific version of the system case
history of all changes in log files
at any time to restore any historical state
multiplayer collaborative development

02. Why need a version control system

03. common version management tool

Centralized version control system SVN, there is only one central data warehouse, if the central data warehouse hung up or inaccessible, all users can not use SVN, you can not be submitted or backup files.

04. Niubi people do not need to explain

These words have been most vividly demonstrated Linux

3. Git installation

01. Preparation System Environment

[root@git ~]# cat /etc/redhat-release    
#查看系统版本
CentOS Linux release 7.6.1810 (Core)

[root@git ~]# uname -r    
#查看内核版本
3.10.0-957.el7.x86_64
[root@git ~]# getenforce    
#确认Selinux关闭状态Disabled
[root@git ~]# systemctl status firewalld     
#关闭防火墙
firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)Active: inactive (dead)Docs: man:firewalld(1)

02. Git installation and deployment

[root@git ~]# yum install git -y    #安装Git
[root@git ~]# git config
--global use global config file        #使用全局配置文件
--system use system config file        #使用系统级配置文件
--local use repository config file    #使用版本库级配置文件

 #配置git使用用户
[root@git ~]# git config --global user.name "gjy"
#配置git使用邮箱
[root@git ~]# git config --global user.email "[email protected]"
#语法高亮
[root@git ~]# git config --global color.ui true
#检查结果
[root@git ~]# git config --list
user.name=gjy
[email protected]
color.ui=true

#查看隐藏文件
[root@git ~]# ll -a
total 40
dr-xr-x---.  2 root root  187 Nov 26  2019 .
dr-xr-xr-x. 17 root root  224 Aug  2 04:55 ..
-rw-------.  1 root root 1430 Aug  2 04:57 anaconda-ks.cfg
-rw-------.  1 root root 2561 Nov 25  2019 .bash_history
-rw-r--r--.  1 root root   18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root  176 Dec 29  2013 .bash_profile
-rw-r--r--.  1 root root  176 Dec 29  2013 .bashrc
-rw-r--r--.  1 root root  100 Dec 29  2013 .cshrc
-rw-r--r--   1 root root   64 Nov 26  2019 .gitconfig
-rwxr-xr-x.  1 root root  473 Aug  1 20:44 host_ip.sh
-rw-r--r--.  1 root root  129 Dec 29  2013 .tcshrc
-rw-------   1 root root 1394 Nov 26  2019 .viminfo

[root@git ~]# cat .gitconfig 
[user]
    name = gjy
    email = [email protected]
[color]
    ui = true

03. Git initialization

#初始化工作目录、对已存在的目录或者对已存在的目录都可进行初始化
#创建一个仓库目录
[root@git ~]# mkdir git_data
[root@git ~]# cd git_data/
#初始化
[root@git ~/git_data]# git init
Initialized empty Git repository in /root/git_data/.git/

#查看工作区状态
[root@git git_data]# git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

[root@git git_data]# ll .git/
total 12
drwxr-xr-x 2 root root   6 Nov 25 16:50 branches
-rw-r--r-- 1 root root  92 Nov 25 16:50 config
-rw-r--r-- 1 root root  73 Nov 25 16:50 description
-rw-r--r-- 1 root root  23 Nov 25 16:50 HEAD
drwxr-xr-x 2 root root 242 Nov 25 16:50 hooks
drwxr-xr-x 2 root root  21 Nov 25 16:50 info
drwxr-xr-x 4 root root  30 Nov 25 16:50 objects
drwxr-xr-x 4 root root  31 Nov 25 16:50 refs

#隐藏文件介绍:
branches         #分支目录
config           #定义项目特有的配置选项
description      #仅供git web程序使用
HEAD             #指示当前的分支
hooks            #包含git钩子文件
info             #包含一个全局排除文件(exclude文件)
objects          #存放所有数据内容,有info和pack两个子文件夹
refs             #存放指向数据(分支)的提交对象的指针
index             #保存暂存区信息,在执行git init的时候,这个文件还没有

4. Git conventionally used

01. Create a data - submit data

02. Git four states

Untracked, unmodified, modified, staging area

03. Git base command

git 改名
git mv a a.txt
git commit  -m "rename a a.txt"

git比对内容
git diff 比对工作目录和暂存区的不同
git diff --cached 比对暂存区和本地仓库的不同

git 查看历史操作信息
git  log 查看历史提交记录
git log --oneline 一条显示提交的历史记录
git log --oneline --decorate 查看当时的指针
git reset --hard e723hh5 回滚代码至某个版本
git reflog 查看所有的历史提交记录

1) Test

#查看状态
[root@git git_data]# git status
# On branch master     #位于分支 master
#
# Initial commit     #初始提交
#
nothing to commit (create/copy files and use "git add" to track)    #无文件要提交(创建/拷贝文件并使用 "git add" 建立跟踪)

#创建测试文件
root@git git_data]# touch a b c
[root@git git_data]# ll
total 0
-rw-r--r-- 1 root root 0 Nov 25 17:00 a
-rw-r--r-- 1 root root 0 Nov 25 17:00 b
-rw-r--r-- 1 root root 0 Nov 25 17:00 c

[root@git git_data]# git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   a
#   b
#   c
nothing added to commit but untracked files present (use "git add" to track)

#git add a 把文件提交到了暂存区
[root@git git_data]# git add a

[root@git git_data]# ll .git/
total 16
drwxr-xr-x 2 root root   6 Nov 25 16:50 branches
-rw-r--r-- 1 root root  92 Nov 25 16:50 config
-rw-r--r-- 1 root root  73 Nov 25 16:50 description
-rw-r--r-- 1 root root  23 Nov 25 16:50 HEAD
drwxr-xr-x 2 root root 242 Nov 25 16:50 hooks
-rw-r--r-- 1 root root  96 Nov 25 17:03 index
drwxr-xr-x 2 root root  21 Nov 25 16:50 info
drwxr-xr-x 5 root root  40 Nov 25 17:03 objects
drwxr-xr-x 4 root root  31 Nov 25 16:50 refs

[root@git git_data]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   a      #发现一个新的文件
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   b
#   c

#查看提交的内容
#使用git add . 或者 * 添加目录中所有改动过的文件
[root@git git_data]# git add .
[root@git git_data]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   a
#   new file:   b
#   new file:   c
#

2) Delete the way

#1.只是删除缓存中的
[root@git git_data]# git rm --cached c
rm 'c'
[root@git git_data]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   a
#   new file:   b
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   c
#2.删除工作目录文件
[root@git git_data]# rm -f c 
[root@git git_data]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   a
#   new file:   b
#

或者:
#把暂停区和工作目录同时删除
[root@git git_data]# git rm -f b
rm 'b'
[root@git git_data]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   a
#

3) File Compare

#提交到本地仓库
[root@git git_data]# git commit -m "create a b"
[master (root-commit) da7ed82] create a b
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a
 create mode 100644 b
[root@git git_data]# git status
# On branch master
nothing to commit, working directory clean

#文件比对
[root@git git_data]# echo '1111' >>a
#比对工作目录跟暂存区的不同
[root@git git_data]# git diff a 
diff --git a/a b/a
index e69de29..5f2f16b 100644
--- a/a
+++ b/a
@@ -0,0 +1 @@
+1111
#提交到暂存区后,再次比对,没有变化
[root@git git_data]# git add .
[root@git git_data]# git diff a 
#比对暂存区和本地仓库的区别
[root@git git_data]# git diff --cached
diff --git a/a b/a
index e69de29..5f2f16b 100644
--- a/a
+++ b/a
@@ -0,0 +1 @@
+1111
#提交到本地仓库
[root@git git_data]# git commit -m 'modify a'
[master e20b4f9] modify a
 1 file changed, 1 insertion(+)
 #再次比对,没有变化
[root@git git_data]# git diff --cached

4) cover

#暂存区中的内容覆盖到工作目录
[root@git git_data]# echo 2222 >> a
[root@git git_data]# git diff a 
diff --git a/a b/a
index 5f2f16b..4f142ee 100644
--- a/a
+++ b/a
@@ -1 +1,2 @@
 1111
+2222
#从暂存区中的文件覆盖到工作目录
[root@git git_data]# git checkout -- a
[root@git git_data]# git diff
[root@git git_data]# cat a
1111

5) code has been added to the staging area and found wrong

[root@git git_data]# echo 2222 >> a
[root@git git_data]# git add .
[root@git git_data]# git diff a
[root@git git_data]# cat a
1111
2222
[root@git git_data]# git diff --cached
diff --git a/a b/a
index 5f2f16b..4f142ee 100644
--- a/a
+++ b/a
@@ -1 +1,2 @@
 1111
+2222
#将本地仓库的文件覆盖暂存区
[root@git git_data]# git reset HEAD a
Unstaged changes after reset:
M   a
[root@git git_data]# git diff --cached
[root@git git_data]# git diff 
diff --git a/a b/a
index 5f2f16b..4f142ee 100644
--- a/a
+++ b/a
@@ -1 +1,2 @@
 1111
+2222

[root@git git_data]# git checkout a
[root@git git_data]# git diff 
[root@git git_data]# cat a
1111

6) 将代码提交到本地仓库,发现写错了

#将代码提交到本地仓库,发现写错了
[root@git git_data]# echo 2222 >> a
[root@git git_data]# git commit -am "modify 222 a"
[master b7818c5] modify 222 a
 1 file changed, 1 insertion(+)
[root@git git_data]# git diff
[root@git git_data]# git diff --cached
[root@git git_data]# cat a
1111
2222
#查看git的提交记录
#用1行内容来表示记录
[root@git git_data]# git log --oneline
b7818c5 modify 222 a
e20b4f9 modify a
da7ed82 create a b
#显示提交的指针方向
[root@git git_data]# git log --oneline --decorate
b7818c5 (HEAD, master) modify 222 a
e20b4f9 modify a
da7ed82 create a b
[root@git git_data]# cat a
1111
2222
[root@git git_data]# echo 3333 >> a
[root@git git_data]# git commit -am "modify 3333 a"
[master c949243] modify 3333 a
 1 file changed, 1 insertion(+)
[root@git git_data]# git log --oneline --decorate
c949243 (HEAD, master) modify 3333 a
b7818c5 modify 222 a
e20b4f9 modify a
da7ed82 create a b
[root@git git_data]# git reset --hard da7ed82
HEAD is now at da7ed82 create a b
[root@git git_data]# cat a

#突然发现恢复错了
[root@git git_data]# git reflog --oneline
da7ed82 HEAD@{0}: reset: moving to da7ed82
c949243 HEAD@{1}: commit: modify 3333 a
b7818c5 HEAD@{2}: commit: modify 222 a
e20b4f9 HEAD@{3}: commit: modify a
da7ed82 HEAD@{4}: commit (initial): create a b
[root@git git_data]# git reset --hard b7818c5
HEAD is now at b7818c5 modify 222 a
[root@git git_data]# cat a
1111
2222

Git服务程序中有一个叫做HEAD的版本指针,当用户申请还原数据时,其实就是将HEAD指针指向到某个特定的提交版本,但是因为Git是分布式版本控制系统,为了避免历史记录冲突,故使用了SHA-1计算出十六进制的哈希字串来区分每个提交版本,另外默认的HEAD版本指针会指向到最近的一次提交版本记录

[root@git ~/git_data]# git reset --hard 18c89e4
HEAD is now at 18c89e4 modified a

刚刚的操作实际上就是改变了一下HEAD版本指针的位置,就是你将HEAD指针放在那里,那么你的当前工作版本就会定位在那里,要想把内容再还原到最新提交的版本,先看查看下提交版本号

打开发现回退错了,应该回退到bbb版本

#打开发现回退错了,应该回退到bbb版本
[root@git ~/git_data]# cat aaaa
#这时候查看log没有commit bbb的历史了
[root@git ~/git_data]# git log --oneline
18c89e4 modified a
1a85735 rename a.txt
a64e0f41 commit a.txt
c6b0ac2 new file a

竟然没有了add bbb这个提交版本记录?原因很简单,因为我们当前的工作版本是历史的一个提交点,这个历史提交点还没有发生过add bbb 更新记录,所以当然就看不到了,要是想"还原到未来"的历史更新点,可以用git reflog命令来查看所有的历史记录:

#使用git reflog 可查看总历史内容
[root@git ~/git_data]# git reflog
18c89e4 HEAD@{0}: reset: moving to 18c89e4
cc5c366 HEAD@{1}: commit: add ccc
6118c8d HEAD@{2}: commit: add bbb
18c89e4 HEAD@{3}: commit: modified a
1a85735 HEAD@{4}: commit: rename a.txt
a64e0f41 HEAD@{5}: commit: commit a.txt
c6b0ac2 HEAD@{6}: commit (initial): new file a
#然后使用reset回到bbb的版本内容下
[root@git ~/git_data]# git reset --hard 6118c8d
HEAD is now at 6118c8d add bbb
[root@git ~/git_data]# cat a
aaa
bbb

Guess you like

Origin www.cnblogs.com/gongjingyun123--/p/11969713.html