經(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管理都遵循此種配置。與之對(duì)應(yīng)的有 local命令括袒,代表“本地設(shè)置”次兆,只是部分項(xiàng)目的獨(dú)立設(shè)置。
二锹锰、git操作實(shí)例
1芥炭、新建git倉(cāng)庫(kù)
1)新建 momo-git 倉(cāng)庫(kù)目錄
[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 倉(cāng)庫(kù)于 /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嫌佑、備注的 豆茫! 符號(hào)有誤侨歉,修改后重新備注,運(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
無(wú)文件要提交为肮,干凈的工作區(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: 從成員名中刪除開(kāi)頭的“/”
/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ò)妒峦,所以上述方法操作失斨匕摺??虾А)
總結(jié)上述實(shí)例過(guò)程命令:
1窥浪、新建git倉(cāng)庫(kù):mkdir、git init
2笛丙、創(chuàng)建文件夾及文件漾脂,并編輯:mkdir、touch胚鸯、vi
3骨稿、添加文件:add、commit
4姜钳、打包tar:tar -cvf
5坦冠、部署,移到新文件夾哥桥,解壓:tar -zxvf
(上述過(guò)程都是在同一個(gè)總目錄下操作辙浑,沒(méi)有配置外部遠(yuǎn)程倉(cāng)庫(kù))
求解進(jìn)行中.....
20170619補(bǔ)充:
經(jīng)“瑞德吳”同學(xué)的點(diǎn)撥(非常感謝),和自身的實(shí)踐拟糕,上述tar包解壓報(bào)錯(cuò)問(wèn)題已解決判呕,結(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
解決辦法:
我上述的壓縮包沒(méi)有用 gzip 壓縮,故解壓時(shí)已卸,不能用 tar -zxvf 命令佛玄,而是用 tar -xvf 硼一。這也是兩種命令使用不熟練的結(jié)果累澡,后期需要加強(qiáng)!