經(jīng)歷6-14師傅的分享,嘗試一下實(shí)例操作輸出。
一、配置git
1、操作前提是已安裝git,可查看git版本:
[root@localhost ~]# git --version
git version 2.7.2
2、配置用戶和郵箱:
[root@localhost ~]# git config --global user.name "momo"
[root@localhost ~]# git config --global user.email "wo@163.com"
配置完查看是否配置成功:
[root@localhost ~]# git config --global user.name
momo
[root@localhost ~]# git config --global user.email
wo@163.com
3、配置默認(rèn)的文本編輯器 vim:
[root@localhost ~]# git config --global core.editor vim
4、查看git的所有配置:
[root@localhost ~]# git config --list
user.name=momo
user.email=wo@163.com
core.editor=vim
備注:上述操作中的 global命令,代表“全局設(shè)置”,即整個(gè)系統(tǒng)中的git管理都遵循此種配置。與之對應(yīng)的有 local命令,代表“本地設(shè)置”,只是部分項(xiàng)目的獨(dú)立設(shè)置。
二、git操作實(shí)例
1、新建git倉庫
1)新建 momo-git 倉庫目錄
[root@localhost ~]# mkdir -p /usr/local/web/momo-git
2)進(jìn)入目錄中
[root@localhost ~]# cd /usr/local/web/momo-git/
3)初始化 git
[root@localhost momo-git]# git init
初始化空的 Git 倉庫于 /usr/local/web/momo-git/.git/
2、提交文件
1)創(chuàng)建文件
A、創(chuàng)建文件夾:A-file、B-file、C-file
[root@localhost momo-git]# mkdir -p /usr/local/web/momo-git/A-file
[root@localhost momo-git]# mkdir -p /usr/local/web/momo-git/B-file
[root@localhost momo-git]# mkdir -p /usr/local/web/momo-git/C-file
B、創(chuàng)建文件:config.xml
[root@localhost momo-git]# touch config.xml
C、查看創(chuàng)建的內(nèi)容
[root@localhost momo-git]# ll
總用量 0
drwxr-xr-x. 2 root root 6 6月 15 15:11 A-file
drwxr-xr-x. 2 root root 6 6月 15 15:12 B-file
drwxr-xr-x. 2 root root 6 6月 15 15:12 C-file
-rw-r--r--. 1 root root 0 6月 15 15:22 config.xml
D、在文件夾中創(chuàng)建子文件,并編輯內(nèi)容
[root@localhost momo-git]# cd /usr/local/web/momo-git/A-file
[root@localhost A-file]# touch a-file
[root@localhost A-file]# vi a-file
Hello momo
Welcome to git-a-file
Happy to use it !
~
"a-file" 3L, 51C written
E、查看文件內(nèi)容
[root@localhost A-file]# cat a-file
Hello momo
Welcome to git-a-file
Happy to use it !
F、同理創(chuàng)建 b-file、c-file
[root@localhost B-file]# cat b-file
Hello momo
Welcome to git-b-file
Please use it carefully !
[root@localhost C-file]# cat c-file
Hello momo
Welcome to git-c-file
Enjoy the use of !
G、編輯 config.xml 完顯示
[root@localhost momo-git]# cat config.xml
Hello momo
Welcome to config
Please enter the text !
2)添加文件
A、使用add 添加
[root@localhost momo-git]# git add A-file/a-file
[root@localhost momo-git]# git add B-file/b-file
[root@localhost momo-git]# git add C-file/c-file
[root@localhost momo-git]# git add config.xml
[root@localhost momo-git]# git commit -m "add ABC files!"
-bash: !": event not found
B、備注的 ! 符號有誤,修改后重新備注,運(yùn)行完提示新增文件信息
[root@localhost momo-git]# git commit -m "add ABC files."
[master(根提交) 9fde4ea] add ABC files.
4 files changed, 12 insertions(+)
create mode 100644 A-file/a-file
create mode 100644 B-file/b-file
create mode 100644 C-file/c-file
create mode 100644 config.xml
C、查看git 上傳文件狀態(tài)
[root@localhost momo-git]# git status
位于分支 master
無文件要提交,干凈的工作區(qū)
D、查看git 操作記錄
[root@localhost momo-git]# git log
commit 9fde4ea743a2e15155722dae9a66a0eb24dde55e
Author: momo <wo@163.com>
Date: Fri Jun 16 10:50:37 2017 +0800
add ABC files.
3、打包 A、B、C、config 文件為整個(gè) istester.tar.gz 包
[root@localhost web]# tar -cvf istester.tar.gz /usr/local/web/momo-git/A-file /usr/local/web/momo-git/B-file /usr/local/web/momo-git/C-file /usr/local/web/momo-git/config.xml
tar: 從成員名中刪除開頭的“/”
/usr/local/web/momo-git/A-file/
/usr/local/web/momo-git/A-file/a-file
/usr/local/web/momo-git/B-file/
/usr/local/web/momo-git/B-file/b-file
/usr/local/web/momo-git/C-file/
/usr/local/web/momo-git/C-file/c-file
/usr/local/web/momo-git/config.xml
4、部署 tar 包
1)新建目錄 istester,將tar包移入目錄內(nèi)
[root@localhost web]# mkdir -p istester/
[root@localhost web]# mv istester.tar.gz /usr/local/web/istester/
[root@localhost web]# cd istester
[root@localhost istester]# ll
總用量 12
-rw-r--r--. 1 root root 10240 6月 16 15:33 istester.tar.gz
2)解壓 tar 包
[root@localhost istester]# tar -zxvf istester.tar.gz
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
(解壓報(bào)錯(cuò),所以上述方法操作失敗??。?/h2>
總結(jié)上述實(shí)例過程命令:
1、新建git倉庫:mkdir、git init
2、創(chuàng)建文件夾及文件,并編輯:mkdir、touch、vi
3、添加文件:add、commit
4、打包tar:tar -cvf
5、部署,移到新文件夾,解壓:tar -zxvf
(上述過程都是在同一個(gè)總目錄下操作,沒有配置外部遠(yuǎn)程倉庫)
求解進(jìn)行中.....
20170619補(bǔ)充:
經(jīng)“瑞德吳”同學(xué)的點(diǎn)撥(非常感謝),和自身的實(shí)踐,上述tar包解壓報(bào)錯(cuò)問題已解決,結(jié)果如下:
[root@localhost istester]# tar -xvf istester.tar.gz
usr/local/web/momo-git/A-file/
usr/local/web/momo-git/A-file/a-file
usr/local/web/momo-git/B-file/
usr/local/web/momo-git/B-file/b-file
usr/local/web/momo-git/C-file/
usr/local/web/momo-git/C-file/c-file
usr/local/web/momo-git/config.xml
解決辦法:
我上述的壓縮包沒有用 gzip 壓縮,故解壓時(shí),不能用 tar -zxvf 命令,而是用 tar -xvf 。這也是兩種命令使用不熟練的結(jié)果,后期需要加強(qiáng)!