To begin with, it's essential to identify where our code is stored. The common assumption is that there are only two locations - one on a remote server like Github and the other on our local machine. However, this isn't entirely accurate. Git maintains three local storages on our machine, which means that our code can be found in four places:
大多数Git命令主要在这四个位置之间移动文件。
Git是一个分布式版本控制系统。
每个开发人员都维护主仓库的本地副本,并在本地副本上进行编辑和提交。
提交操作非常快,因为该操作不与远程仓库进行交互。
如果远程仓库崩溃,可以从本地仓库恢复文件。
What are the differences?
当我们从一个Git分支合并更改到另一个分支时,我们可以使用“git merge”或“git rebase”。下面的图表显示了这两个命令的工作原理。
Git合并
这会在主分支中创建一个新的提交G'。G'将主分支和功能分支的历史联系起来。
Git合并是非破坏性的。主分支和功能分支都不会改变。
Git变基
Git变基将功能分支历史移动到主分支的头部。它为功能分支中的每个提交创建新的提交E'、F'和G'。
变基的好处是它有一个线性的提交历史。
如果不遵循“git rebase的黄金法则”,变基可能会很危险。
Git Rebase的黄金法则
永远不要在对公共分支使用它!
本文作者:Eric
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!