git工作流程
原理
sequenceDiagram
工作区(work tree)->>暂存区(staged):add
暂存区(staged)->>工作区(work tree):restore --staged <file>
暂存区(staged)->>本地库(local):commit (-m "<commit message>")
本地库(local)->>工作区(work tree):reset <commitID/Tag>
本地库(local)->>远程库(remote):push
远程库(remote)->>本地库(local):本地库撤回后强制提交
流程
设置
ssh-keygen -t rsa -C <e-mail>
git init <你的存储库>
git config (--global) user.name <name>
git config (--global) user.email <email>
git config (--global) core.quotepath false #解决git中文乱码问题
将~/.ssh/rsa.pub中的密钥上传至服务器
git remote add gitee/github/gitlab/<name> git@gitee.com:xxx/xxx.git
使用
git add <file>
git commit -m <message>
git push (-f) gitee/github/gitlab
附:常用命令
git log # 显示当前版本库的管理情况
git log --graph # 命令行图形化显示当前版本库的管理情况
git status # 显示当前本地存储库的管理情况
git diff <file> # 显示暂存区与工作区的差异
git diff --cache <file> # 显示暂存区与本地库的差异
git restore -S <file> # 将文件从暂存区丢回工作区
git restore -W <file> # 撤销工作区的修改
git switch <branch> # 切换至某分支
git remote -vv # 显示本仓库对应的远程库及相关信息
git branch # 新建分支
git branch -vv # 显示所有分支及信息
git reset --soft HEAD~1 # 退回到上一个提交,上次提交所有文件回到stage