生成SSH
ssh-keygen -t ras -C "email@xxx"
ssh-keygen
查看SSH
cat ~/.ssh/id_rsa.pub
修改用户名和邮箱
git config --global user.name "xxx"
git config --global user.email "xxxx@qq.com"
初始化本地仓库
git init
将工作区的内容添加到缓存区
git add * //将工作区所有修改添加到暂存区
git add . //将工作区所有修改添加到暂存区
git add filename //将指定文件添加到暂存区
查看变更文件
git status
git提交规范
- 'build'
- 'chore' 杂务
- 'ci'
- 'docs'
- 'feat'
- 'fix'
- 'perf' 完善
- 'refactor' 重构
- 'revert' 还原
- 'style'
- 'test'
将缓存区的内容添加到本地仓库
git commit -m 'feat: 添加xxx功能'
将本地仓库内容推送到远程仓库
git remote add origin https://github.com/qianduanxiaoc/test.git
git push -u origin master
// 若关联报错执行后面代码
git remote rm origin //移除
git remote add origin git@github.com:gitname/test.git //添加
放弃缓存区的修改
git checkout -- filename //放弃暂存区修改(修改不在)
git rm --cached filename //放弃add(修改还在,但产生一条delete记录)
git reset HEAD filename //同上(没有delete记录)
git stash //暂时放弃未提交的修改
git stash pop //恢复
分支操作
git branch //查看分支
git branch xxxname //创建分支
git checkout xxxname // 切换分支
git checkout -b xxxmane // 直接创建并切换到新分支
git merge origin/xxxname git push //合并分支
git branch -d xxxname // 删除某分支
git remote update origin --prune // 同步远程分支
日志操作
git log // 查看日志
git reflog // 查看日志id
版本回退
git reset --hard HEAD^ // 回退到上一个版本
git reset --hard xxxid // 回退到指定版本