Git rebase when rebasing master with a feature - 了解 rebase 图

标签 git github merge rebase

我只是将 master 与我的功能分支重新定位(这意味着我将 master merge 到我的功能分支上)。我在我的功能分支上使用了以下命令:

git rebase -i master

我在我的功能分支 zzL1、zzL2、zzL3、zzL4 上进行了以下四次提交。我将 zzL1 和 zzL2 压缩为一条提交消息,即“这是 zzL1+zzL2 的组合消息”。这是我基于此提出的两个问题:

  1. 当我将 master 重新定位到名为 zzf 的分支时。基本上看起来 master 已经 merge 到我的分支 zzf 上了。然而,据我了解, rebase 不同于 merge 基本上会重播提交历史。这是否意味着看起来好像在 Master 上但在我的分支上丢失的提交现在看起来好像它们也在我的分支上创建了?

  2. 你能解释一下下面的 rebase 图吗?

    蓝线是master,红线是feature branch。我正在将 master 重新定位到我的功能分支上。基本上将 master merge 到我的功能分支上。为什么 rebase 点(带有新的提交消息)在 master 分支上显示为点。即使功能分支的更改不在主分支上。

这是我使用的代码

PS C:\Test\MsGitTest\proj> git rebase -i master
[detached HEAD 1aeb5a5] This is a combined meesage of zzL1+zzL2
 Date: Sun Sep 1 20:10:09 2019 -0700
 1 file changed, 2 insertions(+)
Successfully rebased and updated refs/heads/zzF.
PS C:\Test\MsGitTest\proj> git checkout master
Switched to branch 'master'

这是gitk图

enter image description here

最佳答案

I am rebasing master onto my feature branch. Basically merging master onto my feature branch.

这不是真的。这是 attlasian 对 rebase 的评价:

This moves the entire feature branch to begin on the tip of the master branch, effectively incorporating all of the new commits in master. But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch.

https://www.atlassian.com/git/tutorials/merging-vs-rebasing

因此,您不是将提交从一个分支“复制”到另一个分支( merge ),而是进行新的提交并“复制”代码并推送这些代码。本质上是 CTRL+X + CTRL+V。你把分支 A 放在分支 B 的末尾。

唯一奇怪的是你的功能分支正在“merge ”回你的主分支。 rebase 不会发生这种情况。也许您将 master 重新定位到您的功能分支,然后将其 merge 回来?

enter image description here

关于Git rebase when rebasing master with a feature - 了解 rebase 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57755236/

相关文章:

git - 在 gitignore 中添加 ._* 是否安全?

asp.net-core - 使用 Github 操作进行部署

git - '.gitignore' 文件中应该忽略哪些项目文件? ( Spring 启动)

git - 将多个子目录分离(移动)到单独的 Git 存储库中

SVN:如何通过接受传入添加(删除本地添加)来解决邪恶双胞胎树冲突

git - merge github上的不同问题

git - 如何使用 git-svn clone 仅从 Subversion 存储库获取 HEAD 修订版?

r - 在 for 循环中合并和命名数据帧

python - 将 df1 列中的值合并为 df2 列中逗号分隔值的两个数据帧

xcode - 无法执行操作,因为 "PROJECTNAME"有一个或多个树冲突