git使用
[root@cicd1 ~]# yum install -y git[root@cicd1 ~]# mkdir demo[root@cicd1 ~]# cd demo/
初始化版本库
[root@cicd1 demo]# git init
查看状态
[root@cicd1 demo]# git status[root@cicd1 demo]# git status -s #简化输出
[root@cicd1 demo]# echo test > README.md[root@cicd1 demo]# ls[root@cicd1 demo]# git status -s
[root@cicd1 demo]# git add README.md[root@cicd1 demo]# git status -s
[root@cicd1 demo]# git config --global user.email "924023742@qq.com"[root@cicd1 demo]# git config --global user.name "hjl"[root@cicd1 demo]# git commit -m "add README.md"
[root@cicd1 demo]# echo hello >> README.md[root@cicd1 demo]# git status -s
[root@cicd1 demo]# git add README.md[root@cicd1 demo]# git status -s
[root@cicd1 demo]# echo world >> README.md[root@cicd1 demo]# git status -s
[root@cicd1 demo]# git commit -m "v1"[root@cicd1 demo]# git status -s
[root@cicd1 demo]# git add .[root@cicd1 demo]# git status -s[root@cicd1 demo]# git commit -m "v2"[root@cicd1 demo]# git status -s
忽略隐藏文件
[root@cicd1 demo]# touch .a[root@cicd1 demo]# git status -s
[root@cicd1 demo]# vim .gitignore
[root@cicd1 demo]# git status -s
[root@cicd1 demo]# echo helloworld > test.txt[root@cicd1 demo]# git add test.txt[root@cicd1 demo]# git commit -m "add test.txt"
撤销文件修改
[root@cicd1 demo]# rm -f test.txt[root@cicd1 demo]# git status -s[root@cicd1 demo]# git checkout -- test.txt
取消暂存区文件
[root@cicd1 demo]# git rm test.txt[root@cicd1 demo]# git status -s[root@cicd1 demo]# git reset HEAD test.txt
版本回退
[root@cicd1 demo]# git rm test.txt[root@cicd1 demo]# git commit -m "delete test.txt"[root@cicd1 demo]# git reflog[root@cicd1 demo]# git reset --hard 110c7e6
github远程代码仓库
登录:https://github.com/
上传公钥
[root@cicd1 ~]# ssh-keygen[root@cicd1 ~]# cat .ssh/id_rsa.pub
推送仓库
[root@cicd1 ~]# cd demo/[root@cicd1 demo]# git branch -M main[root@cicd1 demo]# git remote add origin git@github.com:he-bao/demo.git[root@cicd1 demo]# git remote -v[root@cicd1 demo]# git push -u origin main
克隆仓库
[root@cicd1 ~]# rm -fr demo/[root@cicd1 ~]# git clone git@github.com:he-bao/demo.git[root@cicd1 ~]# cd demo/[root@cicd1 demo]# ls