Learn Git Branching 答案汇总

打印 上一主题 下一主题

主题 910|帖子 910|积分 2730

Git 在线学习网站
一、主要

1. 基础篇

1.1 Git Commit

  1. git commit
  2. git commit
复制代码
1.2 Git Branch

  1. git checkout -b bugFix
  2. 或者
  3. git branch bugFix
  4. git checkout bugFix
复制代码
1.3 Git Merge

  1. git checkout -b bugFix
  2. git commit
  3. git checkout main
  4. git commit
  5. git merge bugFix
复制代码
1.4 Git Rebase

  1. git checkout -b bugFix
  2. git commit
  3. git checkout main
  4. git commit
  5. git checkout bugFix
  6. git rebase main
复制代码
2. 高级篇

2.1 分离 HEAD

  1. git checkout c4
复制代码
2.2 相对引用 (^)

  1. git checkout bugFix^
复制代码
2.3 相对引用2 (~)

  1. git branch -f bugFix HEAD~2
  2. git branch -f main c6
  3. git checkout HEAD^
复制代码
2.4 撤销变更

  1. git reset main
  2. git checkout pushed
  3. git revert pushed
复制代码
3. 高级篇

3.1 Git Cherry-pick

  1. git cherry-pick c3 c4 c7
  2. 或者
  3. git cherry-pick bugFix c4 another
复制代码
3.2 交互式 Rebase

  1. git rebase -i overHere
  2. 或者
  3. git rebase -i HEAD~4
  4. 或者
  5. git rebase -i main~4
复制代码
4. 高级篇

4.1 只取一个提交记录

  1. git rebase -i main
  2. git branch -f main bugFix
  3. 或者
  4. git checkout main
  5. git cherry-pick bugFix
复制代码
4.2 提交的本领 #1

  1. git rebase -i caption~2
  2. git commit
  3. --amend
  4. git rebase -i HEAD~2
  5. git branch -f main caption
复制代码
4.3 提交的本领 #2

  1. git checkout main
  2. git cherry-pick newImage
  3. git commit
  4. --amend
  5. git cherry-pick caption
复制代码
4.4 Git Tag

  1. git tag v0 c1
  2. git tag v1 HEAD^
  3. git checkout HEAD^
  4. 或者
  5. git checkout c2
  6. 或者
  7. git checkout main~1
  8. 或者
  9. git checkout main^
复制代码
4.5. Git Describe

  1. git commit
复制代码
5. 高级话题

5.1 多次Rebase

  1. git rebase main bugFix
  2. git rebase bugFix side
  3. git rebase side another
  4. git branch -f main another
复制代码
5.2 两个父节点

  1. // An highlighted block
  2. git branch bugWork HEAD~^2~
  3. 或者
  4. git checkout HEAD~^2~
  5. git branch -f bugWork HEAD
  6. git checkout main
复制代码
5.3 纠缠不清的分支

  1. git checkout one
  2. git cherry-pick c4 c3 c2
  3. git checkout two
  4. git cherry-pick c5 c4 c3 c2
  5. git branch -f three c2
复制代码
// 可以查看网站的答案
  1. show solution
复制代码
二、长途

1. 长途仓库

1.1 Git clone

  1. git clone
复制代码
1.2 长途分支

  1. git commit
  2. git checkout o/maingit commit
复制代码
1.3 Git Fetch

  1. git fetch // 可以认为是将远程仓库中新增的东西下载到本地仓库
复制代码
1.4 Git Pull

  1. git pull // git pull = git fetch + git merge xxx
复制代码
1.5 模拟团队合作

  1. git clone
  2. git fakeTeamwork 2git commit
  3. git pull
复制代码
1.6 Git Push

  1. git commit
  2. git commit
  3. git push
复制代码
1.7 偏离的提交汗青

  1. git clone
  2. git fakeTeamworkgit commit
  3. git pull --rebase // git pull --rebase = git fetch + git rebasegit push
复制代码
1.8 锁定的Master

  1. git reset --hard o/main
  2. git checkout -b featurer c2
  3. git push origin feature
复制代码
2. 长途仓库高级利用

2.1 推送主分支

  1. git checkout main
  2. git pull
  3. git checkout side1
  4. git rebase main
  5. git checkout side2
  6. git rebase side1
  7. git checkout side3
  8. git rebase side2
  9. git checkout main
  10. git push
  11. 或者
  12. git fetch
  13. git rebase o/main side1
  14. git rebase side1 side2
  15. git rebase side2 side3
  16. git rebase side3 main
  17. git push
复制代码
2.2 归并长途仓库

  1. git fetch
  2. git rebase o/main main
  3. git merge side1
  4. git merge side2
  5. git merge side3
  6. git push
  7. 或者
  8. git checkout main
  9. git pull
  10. git merge side1
  11. git merge side2
  12. git merge side3
  13. git push
复制代码
2.3 长途追踪

  1. git checkout -b side o/maingit commit
  2. git pull --rebasegit push
复制代码
2.4 Git Push的参数

  1. git push origin main
  2. git push origin foo
复制代码
2.5 Git Push的参数2

  1. git push origin foo:main
  2. git push origin main^:foo
  3. 或者
  4. git push origin main^:foo
  5. git push origin foo:main
复制代码
2.6 Git Fetch的参数

  1. git fetch origin c3:foo
  2. git fetch origin c6:mian
  3. git checkout foo
  4. git merge main
复制代码
2.7 没有Source的Source

  1. git push origin :foo
  2. git pull origin :bar
复制代码
2.8 Git Pull的参数

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
  1. git pull origin c3:foo
  2. git pull origin c2:side
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

傲渊山岳

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表