编辑
2024-06-01
👨‍🎓 无限进步
00
请注意,本文编写于 383 天前,最后修改于 225 天前,其中某些信息可能已经过时。

目录

How Git Commands work
How does Git Work?
Git merge vs. Git rebase

How Git Commands work

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:

image.png

  • 工作目录:我们编辑文件的地方
  • 暂存区:一个临时位置,用于保存下一次提交的文件
  • 本地仓库:包含已提交代码的地方
  • 远程仓库:存储代码的远程服务器

大多数Git命令主要在这四个位置之间移动文件。

How does Git Work?

image.png

Git是一个分布式版本控制系统。

每个开发人员都维护主仓库的本地副本,并在本地副本上进行编辑和提交。

提交操作非常快,因为该操作不与远程仓库进行交互。

如果远程仓库崩溃,可以从本地仓库恢复文件。

Git merge vs. Git rebase

What are the differences?

image.png

当我们从一个Git分支合并更改到另一个分支时,我们可以使用“git merge”或“git rebase”。下面的图表显示了这两个命令的工作原理。

Git合并

这会在主分支中创建一个新的提交G'。G'将主分支和功能分支的历史联系起来。

Git合并是非破坏性的。主分支和功能分支都不会改变。

Git变基

Git变基将功能分支历史移动到主分支的头部。它为功能分支中的每个提交创建新的提交E'、F'和G'。

变基的好处是它有一个线性的提交历史。

如果不遵循“git rebase的黄金法则”,变基可能会很危险。

Git Rebase的黄金法则

永远不要在对公共分支使用它!

本文作者:Eric

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!