Git单机安装使用
一、安装git
##安装前需要安装扩展源epel-release-6-8.noarch
1:yum安装git包
[root@ghs ~]# yum -y install git
2:使用git前定义用户和邮箱地址,这边测试就填使用自己的,定义的用户和邮箱信息可以在.gitconfig文件查看
[root@ghs ~]# git config --global user.name "ghs"
[root@ghs ~]# git config --global user.email "973363174@qq.com"
[root@ghs ~]# cat .gitconfig
[user]
name = ghs
email = 973363174@qq.com
2:在home目录下创建git仓库存储目录
[root@ghs ~]# mkdir /home/gitroot
[root@ghs ~]# cd /home/gitroot
3:初始化git版本库
[root@ghs gitroot]# git init
Initialized empty Git repository in /home/gitroot/.git/
4:编写测试1.txt文件
[root@ghs gitroot]# vi 1.txt
test
5:推送文件到存储库,add标记,commit推送到版本库
[root@ghs gitroot]# git add 1.txt
[root@ghs gitroot]# git commit -m "add 1.txt"
1 files changed, 13 insertions(+), 0 deletions(-)
create mode 100644 1.txt
6:查看git状态
[root@ghs gitroot]# git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: 1.txt
#
7:git checkout恢复删除的文件
[root@ghs gitroot]# rm -rf 1.txt
[root@ghs gitroot]# git checkout 2.txt
[root@ghs gitroot]# ls
1.txt
8:git diff 可以查看版本变更前后的对比差异
[root@ghs gitroot]# cat 1.txt
test
[root@ghs gitroot]# echo "123" >> 1.txt
[root@ghs gitroot]# cat 1.txt
test
123
[root@ghs gitroot]# git diff 1.txt
diff --git a/1.txt b/1.txt
index 9daeafb..357bfd8 100644
--- a/1.txt
+++ b/1.txt
@@ -1 +1,2 @@
test
+123
记录每一天有趣的事情!!

浙公网安备 33010602011771号