Git:分布式版本控制工具
Git:分布式版本控制工具
-
安装
# yum install -y git
-
提交代码需要配置[root@node1个人信息
[root@room8pc16 python]# git config --global user.name "zhangzhg"
[root@room8pc16 python]# git config --global user.email "zhangzg@tedu.cn"
3、设置编写代码说明的编辑器是vim
[root@room8pc16 python]# git config --global core.editor vim
-
查看
[root@room8pc16 python]# git config --list
[root@room8pc16 python]# cat ~/.gitconfig
-
创建工作区
[root@room8pc16 ~]# mkdir mycode
-
初始化版本库
[root@room8pc16 ~]# cd mycode
[root@room8pc16 mycode]# git init .
[root@room8pc16 mycode]# ls -a
-
编写程序文件
[root@room8pc16 mycode]# echo 'hello world' > hi.txt
[root@room8pc16 mycode]# git status 查看状态
-
添加跟踪文件(所有文件)到版本库
[root@room8pc16 mycode]# git add .
[root@room8pc16 mycode]# git status
-
提交文件到版本库
[root@room8pc16 mycode]# git commit -m "add hi.txt"
[root@room8pc16 mycode]# git status
-
修改hi.txt
[root@room8pc16 mycode]# echo "new line" >> hi.txt
[root@room8pc16 mycode]# git add .
[root@room8pc16 mycode]# git commit -m "modify hi.txt"
-
恢复hi.txt到以前版本
[root@room8pc16 mycode]# git log
查看第一次提交的ID号,它的显示如下:
commit 48c488c8efb45b2c31afa225c0d7ad281ecb6b11
Author: MrZhangzhg <zhangzg@tedu.cn>
Date: Mon Jul 16 11:23:39 2018 +0800
add hi.txt
[root@room8pc16 mycode]# git checkout 48c488c8efb45b2c31afa225c0d7ad281ecb6b11
-
如果有误加入到版本库的文件,可以查到它,并删除
[root@room8pc16 mycode]# git ls-files 查看版本库中的文件
[root@room8pc16 mycode]# git rm hi.txt
[root@room8pc16 mycode]# git commit -m "delete hi.txt"
搭建