一个用Git交互可视化教学的项目

Learn git branching Git的可视化教学项目

这是个能够让新手快速上手Git的教程

这两天花时间把 Learn Git Branching Main部分的做了一遍。 对理解git分支的使用很有帮助,另外发现git的帮助文档和github的帮助文档都很详细,应该好好读一遍。

使用命令查看 答案
$ show solution
复制代码

答案记录在下面

基础篇

循序渐进地介绍 Git 主要命令

1.1 Introduction to Git Commits

将当前对文件的修改 创建一个提交记录
git commit <-m "提交说明">
复制代码

1.2 Branching in Git

创建一个分支
git branch bugFix

切换到 bugFix分支
git checkout bugFix
复制代码

1.3 Merging in Git

创建一个分支 并切换为该分支
git checkout -b bugFix
git commit
git checkout master
git commit

将bugFix 合并到当前分支
git merge bugFix
复制代码

1.4 Rebase Introduction

Rebase 实际上就是取出一系列的提交记录,“复制”它们,
然后在另外一个地方逐个的放下去。
即将某个分支的提交 移动到另一个分支上 使提交历史呈现一条直线
eg.
    git rebase [branchName]   将当前的分支移动到指定的分支上
    git rebase [base] [from]  将form 移动到base上 
        (base/from可以是版本号 分支名)

git checkout -b bugFix
git commit
git checkout master
git commit
git checkout bugFix
git rebase master
复制代码

高级篇

要开始介绍 Git 的超棒特性了,快来吧!

相对引用
    1. 使用 ^ 向上移动 1 个提交记录
    2. 使用 ~<num> 向上移动多个提交记录,如 ~3
eg.
    HEAD^       即当前分支的上一个提交
    master~3    master 往前 第3个提交 
复制代码

2.1 Detach yo’ HEAD

git checkout C4
复制代码

2.2 Relative refs (^)

git checkout C4^
复制代码

2.3 Relative refs #2 (~)

git branch -f master C6
git branch -f bugFix C0
git checkout C1
复制代码

2.4 Reversing Changes in Git

git reset local~1
git checkout pushed
git revert pushed
复制代码

移动提交记录

自由修改提交树

git cherry-pick <提交号>...
将一些提交复制到当前所在的位置(HEAD)下面的话,
Cherry-pick 是最直接的方式了。个人非常喜欢 cherry-pick,因为它特别简单。
复制代码

3.1 Cherry-pick Intro

git cherry-pick C3 C4 C7
复制代码

3.2 Interactive Rebase Intro

交互式rebase  加上-i 选项 
将提供可视化操作的方式让你 
按自定义方式 重新组合排序多个提交
git rebase -i master~4 --aboveAll
复制代码

杂项

Git 技术、技巧与贴士大集合

4.1 Grabbing Just 1 Commit

git checkout master
git cherry-pick C4
复制代码

4.2 Juggling Commits

git rebase -i caption~2 --aboveAll
git commit --amend
git rebase -i caption~2 --aboveAll
git branch -f master caption
复制代码

4.3 Juggling Commits #2

git checkout master
git cherry-pick C2
git commit --amend
git cherry-pick C3
复制代码

4.4 Git Tags

git tag v0 C1
git tag v1 C2
git checkout C2
复制代码

4.5 Git Describe

git commit
复制代码

高级话题

只为真正的勇士!

5.1 Rebasing over 9000 times

git rebase master bugFix
git rebase bugFix side
git rebase side another
git rebase another master
复制代码

5.2 Multiple parents

git branch bugWork master~^2~
复制代码

5.3 Branch Spaghetti

git checkout one
git cherry-pick C4 C3 C2
git checkout two
git cherry-pick C5 C4 C3 C2
git branch -f three C2
复制代码

Push & Pull —— Git 远程仓库!

是时候分享你的代码了,让编码变得社交化吧

6.1 Git Clone

git clone 
复制代码

6.2 远程分支

git commit
git checkout o/master
git commit
复制代码

6.2 Git Fetch 拉取远程提交 不合并

git fetch
复制代码

6.3 Git Pull 拉取远程提交 进行合并

git pull
复制代码

6.4 Git 模拟团队提交

git fakeTeamwork 2
git commit 
git pull
复制代码

6.5 Git remote5

git clone 
git fakeTeamwork 2
git commit 
git pull
复制代码

6.5 Git Push

代码推送
git push 负责将你的变更上传到指定的远程仓库,
并在远程仓库上合并你的新提交记录。
一旦 git push 完成, 你的朋友们就可以从这个远程仓库下载你分享的成果了!
复制代码

6.6 偏离的工作

在git push时,若远程仓库存在新的提交 Git将拒绝push请求 
需要远程代码拉取到本地 进行合并后才能进行push

git clone
git fakeTeamwork
git commit 
git pull --rebase
git push
复制代码

关于 origin 和它的周边 —— Git 远程仓库高级操作

做一名仁慈的独裁者一定会很有趣……

7.1 推送主分支

方案1:
git fetch
git rebase o/master side1
git rebase side1 side2
git rebase side2 side3
git rebase side3 master
git push

方案二:
git fetch
git rebase o/master side1
git cherry-pick C2 C3 C4 C5 C6 C7
git push
复制代码

7.2 合并远程分支

git checkout master 
git pull
git merge side1
git merge side2
git merge side3
git push
复制代码

7.3 远程追踪


git chekout -b side o/master
git commit
git pull --rebase
git push
复制代码

7.4 Git Push 的参数

参数详解 git push origin <source>:<destination>
git push origin master
git push origin foo
复制代码

7.5 Git Push 的参数 2

参数详解 git push origin <source>:<destination>
git push origin master^:foo
git push origin foo:master 
复制代码

7.6 Git fetch 的参数

git fetch origin master~1:foo
git fetch origin foo:master
git checkout foo
git merge master
复制代码

7.7 没有 source 的 source

刪除远程的分支 (即推送空值到指定分支)
git push origin :foo
在本地创建一个新分支
git fetch origin :bar
复制代码

7.8: Git pull 的参数

git pull origin bar:foo
git pull origin master:side
复制代码
当你完成所有的关卡时 将会看到下面的提示信息

转载于:https://juejin.im/post/5bffab6bf265da61553a8b3b

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值