一. 针对三大区的操作
将修改保存到缓存区
git stash
git stash list
git stash pop
从暂存区中删除,相当于取消勾选
git rm --cached test.c
暂存区恢复到工作区(会覆盖)
git restore --staged test.c
版本回退或前进
git reset --mixed commit-id
// 回退后,提前版本的提交会到工作区
git reset --soft head~3
// 回退后,提前版本的提交会到暂存区
git reset --hard commit-id
// 三区保持一致(会覆盖)
撤销某次提交,某一个版本(针对已经push了的)
git revert commit-id
二. log、整理版本库
git log
git log --oneline
git reflog
// 所有操作的日志
gitk
整理版本库,如对某个版本修改commit message;或修改文件内容,增删文件等;或将某几次提交合并到上一次提交
git rebase -i commit-id
git push -f
// 若是对已push的提交进行整理,整理完后需要强推
一些检索和提取关键信息的命令:
git shortlog
git log --skip=[10] -3
// 跳过前面10条提交,显示前3条提交
git log --after="2022-5-2"
git log --before="2022-5-2"
git log --author="simon"
git log grep="test"
// 按提交信息,提交文本中包含test
git log -S "main"
// 按内容,所有文件中包含main字符串的修改
git log -p
git log --stat
// 查看简化版的diff日志信息
git log -p test.c
// 按文件,查看test.c迭代过程
git log --oneline test.c
git show commit-id
git show commit-id test.c
git diff test.c
//查看本地对test.c做了哪些修改
git diff commit-id1 commit-id2
git diff commit-id 文件名
三. merge
git pull = git fetch + git merge
git push:只是把本地分支更新到远端分支,并不会在远端执行合并操作,故push之前必须保证本地分支提前于远端分支(即保证在本地仓库,远程仓库必须是最新的)
四. 其他
tag标签:
git tag v1.0 commit-id -m'bumped version to v1.0'
git tag
git show v1.0
git push origin v1.0
git push origin --tags
// 推送所有的tag到远端
git checkout v1.0
// 检出v1.0的代码
git tag -d v1.0
git push origin :tags/v1.0
解决项目之间的依赖:submodule(父模块,子模块)
github 和 gitee
zenhub 和 gitlab