git
git使用
[root@server1 ~]# yum install -y git
[root@server1 ~]# mkdir demo
[root@server1 ~]# cd demo/
初始化版本库
[root@server1 demo]# git init
查看状态
[root@server1 demo]# git status
[root@server1 demo]# git status -s #简化输出
[root@server1 demo]# echo test > README.md
[root@server1 demo]# ls
[root@server1 demo]# git status -s
?? README.md
[root@server1 demo]# git add README.md
[root@server1 demo]# git status -s
A README.md
[root@server1 demo]# git config --global user.email "yakexi007@westos.org"
[root@server1 demo]# git config --global user.name "shx"
[root@server1 demo]# git commit -m "add README.md"
[root@server1 demo]# echo hello >> README.md
[root@server1 demo]# git status -s
M README.md
[root@server1 demo]# git add README.md
[root@server1 demo]# git status -s
M README.md
[root@server1 demo]# echo world >> README.md
[root@server1 demo]# git status -s
MM README.md
[root@server1 demo]# git commit -m "v1"
[root@server1 demo]# git status -s
M README.md
[root@server1 demo]# git add .
[root@server1 demo]# git status -s
M README.md
[root@server1 demo]# git commit -m "v2"
[root@server1 demo]# git status -s
忽略隐藏文件
[root@server1 demo]# touch .a
[root@server1 demo]# git status -s
?? .a
[root@server1 demo]# vim .gitignore
.*
[root@server1 demo]# git status -s
![](https://i-blog.csdnimg.cn/blog_migrate/3e4641bd8514a9ad5ddfd7e5cd46f77c.png)
撤销文件修改
[root@server1 demo]# echo helloworld > test.txt
[root@server1 demo]# git add test.txt
[root@server1 demo]# git commit -m "add test.txt"
[root@server1 demo]# rm -f test.txt
[root@server1 demo]# git status -s
D test.txt
[root@server1 demo]# git checkout -- test.txt
取消暂存区文件
[root@server1 demo]# git rm test.txt
[root@server1 demo]# git status -s
D test.txt
[root@server1 demo]# git reset HEAD test.txt
版本回退
[root@server1 demo]# git rm test.txt
[root@server1 demo]# git commit -m "delete test.txt"
[root@server1 demo]# git reflog
[root@server1 demo]# git reset --hard 6823e45
github远程代码仓库
创建一个新仓库
上传公钥
推送仓库
[root@server1 ~]# cd demo/
[root@server1 demo]# git branch -M main
[root@server1 demo]# git remote add origin https://github.com/suhongxing/demo.git
[root@server1 demo]# git remote -v
origin https://github.com/suhongxing/demo.git (fetch)
origin https://github.com/suhongxing/demo.git (push)
[root@server1 demo]# git push -u origin main
克隆仓库
[root@server1 ~]# rm -fr demo/
[root@server1 ~]# git clone git@gitee.com:su-hongxing/demo.git