基础篇
Git commit(提交)



Git Branch(分支)





git checkout -b bugFix

Git Merge(合并1)
把合并到当前分支



Git Rebase(合并2)
把当前分支里的工作合并(复制)到
git rebase branch1 branch2:将分支2的提交合并到分支1



高级篇
Git checkout(在提交树上移动)
HEAD:是对当前提交记录的符号引用

通过指定提交记录哈希值(如C1 C2)的方式在 Git 中移动




相对引用1(^)






相对引用2(~)


强制修改分支位置:git branch -f





1 2 3
| git branch -f main c6 git checkout HEAD^ git branch -f bugFix HEAD^
|
Git reset|Git revert(撤销变更)



- git revert:用于远程,将记录的撤销(回退)记录加到当前分支记录


移动提交记录
Git cherry-pick(整理提交记录)

把一些提交号复制到当前位置



Git rebase -i (交互式的 rebase)






杂项
本地栈式提交




1 2 3
| git checkout main
git cherry-pick c5 或 git cherry-pick bugFix
|
提交的技巧 #1




1 2 3 4 5 6 7 8
| git rebase -i HEAD~2 调整C2 C3 //进行一些小修改 git commit --amend git rebase -i HEAD~2 调整C2'' C3 //将main移动到修改的最前端 git rebase caption main
|




提交的技巧 #2




1 2 3 4
| git checkout main git cherry-pick C2 git commit --amend git cherry-pick C3
|






Git Describe



高级话题
多分支 rebase



1 2 3 4
| git rebase main bugFix git rebase bugFIx side git rebase side another git rebase another main
|
选择父提交记录






^num是横向移动;~num是纵向移动
纠缠不清的分支



1 2 3 4
| git cherry-pick C4 C3 C2 git checkout two git cherry-pick C5 C4 C3 C2 git branch -f three C2
|
Push & Pull —— Git 远程仓库!
Git clone




远程分支




Git Fetch(抓取)





Git Pull(拉取=抓取+合并)





git pull=git fetch + git merge
模拟团队合作






1 2 3 4
| git clone git fakeTeamwork 2 git commit git pull
|
Git Push(推送)



偏离的工作













1 2 3
| git pull = git fetch + git merge
git pull --rebase = git fetch + git rebase
|





1 2 3 4 5
| git fake' Teamwork objective git commit git pull --rebase git push
|
远程服务器拒绝!(Remote Rejected)





1 2 3 4 5 6 7 8
| $ git reset --hard o/main ➊在本程序中默认的行为是--hard 硬重置,可 以尽情省略掉那个选项以避免麻烦!但是要记录 Git中默认的是--mixed。 $ git checkout -b feature C2 $ git push origin feature 0 local branch "feature" set to track remote branch "o/ feature"
|
关于 origin 和它的周边 —— Git 远程仓库高级操作
合并特性分支






1 2 3 4 5 6
| $ git fetch $ git rebase o/main side1 $ git rebase side1 side2 $ git rebase side2 side3 $ git rebase side3 main $ git push
|
合并远程仓库





1 2 3 4 5 6
| git checkout main git pull git merge side1 git merge side2 git merge side3 git push
|
远程跟踪分支


1. git checkout -b foo o/main





2.git branch -u o/main foo




1 2 3 4
| git checkout -b side o/main git commit git pull --rebase git push
|
Git Push 的参数









1 2
| git push origin main git push origin foo
|
<place>
参数详解







1 2
| git push origin main^:foo git push origin foo:main
|
Git fetch 的参数














1 2 3 4
| git fetch origin main~1:foo git fetch origin foo:main git checkout foo git merge main
|
古怪的 <source>





Git pull 参数





