trylearning-git-branching
- 手机
- 2025-09-03 15:30:01

文章目录 mergerebase分离 HEAD相对引用利用父节点branch -f 撤销变更cherry-pick交互式 rebase只取一个提交记录提交的技巧rebase 在上一次提交上amendcherry-pick 在上一次提交上 amend tag多分支 rebase两个parent节点纠缠不清的分支偏离的提交历史锁定的Main推送主分支合并远程仓库远程跟踪push 的参数push 的参数2fetch 的参数没有 source 的 sourcepull 参数 发现一个小工具,复习一下 git 相关的操作,对 git 的一些命令又有了深入的理解。 learning git branching merge 创建新分支 bugFix用 git checkout bugFix 命令切换到该分支提交一次用 git checkout main 切换回 main再提交一次用 git merge 把 bugFix 合并到 main git checkout -b bugFix git commit git checkout main git commit git merge bugFix rebase
操作:
新建并切换到 bugFix 分支提交一次切换回 main 分支再提交一次再次切换到 bugFix 分支,rebase 到 main 上 git checkout -b bugFix git commit git checkout main git commit git checkout bugFix git rebase main 分离 HEAD git checkout c4 相对引用 利用父节点 git checkout HEAD^寻找 bugFix 的父节点
git checkout bugFix^ branch -f强制修改分支位置
git branch -f bugFix c0 git branch -f main c6 git checkout c1或者
git checkout c1 git branch -f bugFix HEAD~1 git branch -f main c6 撤销变更 git reset HEAD~1 git checkout pushed git revert HEAD cherry-pick git cherry-pick c3 c4 c7 交互式 rebase git rebase -i HEAD~4 只取一个提交记录 git rebase -i main git branch -f main bugFix或者
git checkout main git cherry-pick bugFix 提交的技巧 rebase 在上一次提交上amend git rebase -i main git commit --amend git rebase -i main git branch -f main caption或者(多种方法尝试)
git rebase -i caption~2 git commit --amend git rebase -i HEAD~2 git branch -f main caption cherry-pick 在上一次提交上 amend git checkout main git cherry-pick newImage git commit --amend git cherry-pick caption tag git tag v0 c1 git tag v1 c2 git checkout v1 多分支 rebase git rebase main bugFix git rebase bugFix side git rebase side another git branch -f main another 两个parent节点操作符 ^ 与 ~ 符一样,后面也可以跟一个数字。
但是该操作符后面的数字与 ~ 后面的不同,并不是用来指定向上返回几代,而是指定合并提交记录的某个 parent 提交。还记得前面提到过的一个合并提交有两个 parent 提交吧,所以遇到这样的节点时该选择哪条路径就不是很清晰了。
Git 默认选择合并提交的“第一个” parent 提交,在操作符 ^ 后跟一个数字可以改变这一默认行为。
git checkout HEAD~^2~ git branch -f bugWork HEAD # git branch -f bugWork git checkout main或者
git branch bugWork HEAD~^2~ 纠缠不清的分支 git checkout one git cherry-pick c4 c3 c2 git checkout two git cherry-pick c5 c4 c3 c2 git branch -f three c2 偏离的提交历史 git clone git fakeTeamwork git commit git fetch git rebase o/main git push或者
git clone git fakeTeamwork git commit git pull --rebase git push 锁定的Main git reset --hard o/main git checkout -b feature c2 git push # git push origin feature 推送主分支 git fetch git rebase o/main side1 git rebase side1 side2 git rebase side2 side3 git rebase side3 main git push 合并远程仓库 git fetch git rebase o/main main git merge side1 git merge side2 git merge side3 git push 远程跟踪 git checkout -b side o/main git commit git fetch git rebase o/main side git push或者
git checkout -b side o/main git commit git pull --rebase git push push 的参数 git push origin main git push origin foo push 的参数2 git push origin foo:main git push origin main^:foo fetch 的参数 git fetch origin c3:foo git fetch origin c6:main git checkout foo git merge main 没有 source 的 source git push origin :foo git fetch origin :bar pull 参数git pull 到头来就是 fetch 后跟 merge 的缩写。可以理解为用同样的参数执行 git fetch,然后再 merge 所抓取到的提交记录。
git pull origin foo 相当于:git fetch origin foo; git merge o/foo
git pull origin bar:bugFix 相当于:git fetch origin bar:bugFix; git merge bugFix
git fetch origin c3:foo git fetch origin c2:side git merge foo git merge side或者
git pull origin c3:foo git pull origin c2:sidetrylearning-git-branching由讯客互联手机栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“trylearning-git-branching”
上一篇
【私人笔记】Web前端