Git安裝配置使用
一、git簡介
git是一個開源分佈式版本控制系統,用於敏捷高效地處理任何或大或小的項目。
Git是linus Tovalds爲了幫助管理 Linux 內核開發而開發的一個開放源碼的版本控制軟件。
Git 與常用的版本控制工具 CVS, Subversion 等不同,它採用了分佈式版本庫的方式,不必服務器端軟件支持。
二、Git工作流程
三、工作區、暫存區和版本庫
工作區:就是你在電腦裏能看到的目錄
暫緩區:英文叫stage, 或index。一般存放在 ".git目錄下" 下的index文件(.git/index)中,所以我們把暫存區有時也叫作索引(index)
版本庫:工作區有一個隱藏目錄.git,這個不算工作區,而是Git的版本
四、安裝及配置
1、安裝
]#yum -y install git
2、配置作者信息
[root@node1 ~]# git config --global user.name "liushiju"
[root@node1 ~]# git config --global user.email "[email protected]"
[root@node1 ~]# git config --global core.editor vim
[root@node1 ~]# git config --list
[root@node1 ~]# cat .gitconfig
五、使用Git
1、初始化
[root@node1 ~]# mkdir devops
[root@node1 ~]# cd devops
[root@node1 devops]# git init
[root@node1 devops]# ls -a
2、添加跟蹤文件
[root@node1 devops]# echo 'hello world' > hello.txt
[root@node1 devops]# git add .
3、查看暫存區域
[root@node1 devops]# git status
[root@node1 devops]# git status -s
4、確認文件到版本庫
[root@node1 devops]# git commit -m "add hello.txt"
[root@node1 devops]# git status
5、刪除版本庫中文件
[root@node1 devops]# git ls-files
[root@node1 devops]# git rm hello.txt
[root@node1 devops]# git commit -m "rm hello.txt"
6、把不想放到版本庫中的文件寫到.gitignore中
[root@node1 devops]# vim .gitignore
*.swp
*.pyc
.gitignore