这两天花时间把 Learn Git Branching Main部分的作了一遍。 对理解git分支的使用颇有帮助,另外发现git的帮助文档和github的帮助文档都很详细,应该好好读一遍。git
使用命令查看 答案
$ show solution
复制代码
答案记录在下面github
按部就班地介绍 Git 主要命令bash
将当前对文件的修改 建立一个提交记录 git commit <-m "提交说明"> 复制代码
建立一个分支
git branch bugFix
切换到 bugFix分支
git checkout bugFix
复制代码
建立一个分支 并切换为该分支
git checkout -b bugFix
git commit
git checkout master
git commit
将bugFix 合并到当前分支
git merge bugFix
复制代码
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 的超棒特性了,快来吧!markdown
相对引用
1. 使用 ^ 向上移动 1 个提交记录
2. 使用 ~<num> 向上移动多个提交记录,如 ~3
eg.
HEAD^ 即当前分支的上一个提交
master~3 master 往前 第3个提交
复制代码
git checkout C4
复制代码
git checkout C4^
复制代码
git branch -f master C6 git branch -f bugFix C0 git checkout C1 复制代码
git reset local~1 git checkout pushed git revert pushed 复制代码
自由修改提交树ide
git cherry-pick <提交号>...
将一些提交复制到当前所在的位置(HEAD)下面的话,
Cherry-pick 是最直接的方式了。我的很是喜欢 cherry-pick,由于它特别简单。
复制代码
git cherry-pick C3 C4 C7
复制代码
交互式rebase 加上-i 选项
将提供可视化操做的方式让你
按自定义方式 从新组合排序多个提交
git rebase -i master~4 --aboveAll
复制代码
Git 技术、技巧与贴士大集合oop
git checkout master
git cherry-pick C4
复制代码
git rebase -i caption~2 --aboveAll git commit --amend git rebase -i caption~2 --aboveAll git branch -f master caption 复制代码
git checkout master
git cherry-pick C2
git commit --amend
git cherry-pick C3
复制代码
git tag v0 C1
git tag v1 C2
git checkout C2
复制代码
git commit
复制代码
只为真正的勇士!fetch
git rebase master bugFix
git rebase bugFix side
git rebase side another
git rebase another master
复制代码
git branch bugWork master~^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 commit
git checkout o/master
git commit
复制代码
git fetch
复制代码
git pull
复制代码
git fakeTeamwork 2
git commit
git pull
复制代码
git clone git fakeTeamwork 2 git commit git pull 复制代码
代码推送
git push 负责将你的变动上传到指定的远程仓库,
并在远程仓库上合并你的新提交记录。
一旦 git push 完成, 你的朋友们就能够从这个远程仓库下载你分享的成果了!
复制代码
在git push时,若远程仓库存在新的提交 Git将拒绝push请求 须要远程代码拉取到本地 进行合并后才能进行push git clone git fakeTeamwork git commit git pull --rebase git push 复制代码
作一名仁慈的独裁者必定会颇有趣……spa
方案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
复制代码
git checkout master
git pull
git merge side1
git merge side2
git merge side3
git push
复制代码
git chekout -b side o/master
git commit
git pull --rebase
git push
复制代码
参数详解 git push origin <source>:<destination> git push origin master git push origin foo 复制代码
参数详解 git push origin <source>:<destination> git push origin master^:foo git push origin foo:master 复制代码
git fetch origin master~1:foo
git fetch origin foo:master
git checkout foo
git merge master
复制代码
刪除远程的分支 (即推送空值到指定分支)
git push origin :foo
在本地建立一个新分支
git fetch origin :bar
复制代码
git pull origin bar:foo
git pull origin master:side
复制代码