技术流ken

运维拯救世界

每天五分钟轻松学运维2019-05-23: 分布式版本控制系统git常用操作演示(一)–技术流ken

git安装

 

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

 

git常用操作

 

git add: 添加文件至暂存区域

git branch: 查看分支和创建分支

git checkout: 进行撤销也可以进行分支切换

git clone: 克隆远程主机仓库

git commit: 把暂存区域的文件提交至仓库中

git init: 初始化目录(工作目录)

git merge: 合并分支

git pull: 拉取远程主机的仓库

git push: 把本地仓库推送到远程主机

git reset: 撤销操作

git status: 查看git目录中文件状态

 

git使用演示

 

第一步:创建一个目录

[root@ken ~]# mkdir /ken
[root@ken ~]# cd /ken

 

第二步:初始目录为git工作目录

[root@ken ken]# git init
Initialized empty Git repository in /ken/.git/
[root@ken ken]# ls -a
. .. .git

 

第三步:创建文件并提交

[root@ken ken]# touch test
[root@ken ken]# ls
test
[root@ken ken]# git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use “git add <file>…” to include in what will be committed)
#
# test
nothing added to commit but untracked files present (use “git add” to track)
[root@ken ken]# git add .    #表示把当前所有的文件都进行提交
[root@ken ken]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use “git rm –cached <file>…” to unstage)
#
# new file: test
#
[root@ken ken]# git commit -m “v1”

*** Please tell me who you are.

Run

git config –global user.email “you@example.com”
git config –global user.name “Your Name”

to set your account’s default identity.
Omit –global to set the identity only in this repository.

fatal: unable to auto-detect email address (got ‘root@ken.(none)’)
[root@ken ken]#
[root@ken ken]# git config –global user.email “you@example.com”
[root@ken ken]# git config –global user.name “Your Name”
[root@ken ken]# git commit -m “v1”
[master (root-commit) 6c53735] v1
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test
[root@ken ken]# git status
# On branch master
nothing to commit, working directory clean

 

第四步:查看已经提交的版本
[root@ken ken]# git log
commit 6c537358b0c8bae465460aea86c4ce2ddd4b6ea4
Author: Your Name <you@example.com>
Date: Thu May 23 14:59:01 2019 +0800

v1

 

第五步:写入内容至文件并提交

[root@ken ken]# echo “111” >> test
[root@ken ken]#
[root@ken ken]#
[root@ken ken]# 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: test
#
no changes added to commit (use “git add” and/or “git commit -a”)
[root@ken ken]# git add test
[root@ken ken]# git status
# On branch master
# Changes to be committed:
# (use “git reset HEAD <file>…” to unstage)
#
# modified: test
#
[root@ken ken]# git commit -m “v2”
[master aa70338] v2
1 file changed, 1 insertion(+)
[root@ken ken]# git log
commit aa70338daf23b487237c9f51d10a80c6bd757e75
Author: Your Name <you@example.com>
Date: Thu May 23 15:01:37 2019 +0800

v2

commit 6c537358b0c8bae465460aea86c4ce2ddd4b6ea4
Author: Your Name <you@example.com>
Date: Thu May 23 14:59:01 2019 +0800

v1

 

 

第六步:回滚到V1版本

[root@ken ken]# git log
commit aa70338daf23b487237c9f51d10a80c6bd757e75
Author: Your Name <you@example.com>
Date: Thu May 23 15:01:37 2019 +0800

v2

commit 6c537358b0c8bae465460aea86c4ce2ddd4b6ea4
Author: Your Name <you@example.com>
Date: Thu May 23 14:59:01 2019 +0800

v1
[root@ken ken]# git reset –hard 6c537358b0c8bae465
HEAD is now at 6c53735 v1
[root@ken ken]# cat test

 

 

《未完待续》

发表评论

电子邮件地址不会被公开。