gpt4 book ai didi

git - 使用 git,为什么在 merge 到功能分支后提交不出现在历史记录中?

转载 作者:太空狗 更新时间:2023-10-29 14:28:11 28 4
gpt4 key购买 nike

我有 2 个分支,主分支和功能分支。两个分支都有持续的变化。我将主分支的更改 merge 到功能分支中。有一些冲突,我解决了。然后我暂存更新的文件。

在 merge 中,有许多其他提交没有有任何冲突文件。

有了这个,有两件事我不明白。

  1. 对于没有任何冲突的提交,它们不应该出现在功能分支的历史记录中吗? merge 之后,在主分支上完成的任何工作的功能分支历史记录中都没有任何内容。
  2. 再次关于没有任何冲突的提交,为什么在功能分支上运行 git status 时这些文件显示为已更改?

不可否认,我对应该发生的事情的理解可能存在一些根本性的缺失......

最佳答案

For the commits that didn't have any conflicts, shouldn't they show up in the history of the feature branch? Following the merge, there is nothing in the feature branch history for any of the work that was done on the main branch.

在您的问题中,您谈到了发生在提交 上的 merge 冲突。

In the merge, there were a number of other commits that didn't have any conflicting files.

Git 不 merge 提交,它 merge 内容。这向我表明您对 Git 的工作方式有误解(Git 并没有做太多的工作来消除这种误解,所以不用担心)。让我们勾画一下您的存储库在 merge 之前的样子...

A - B - C - D - E - F [master]
\
1 - 2 - 3 [feature]

您有一个包含提交 A、B、C ... F 的主分支。然后您有一个 C 的功能分支,包含提交 1、2 和 3。您可以使用 git log --graph 看到这一点--decorate --all 或者您可以使用图形工具,例如 gitkGitX-dev

您想将更改从 master merge 到 feature 中。 Git 通过获取 master 和 feature 的内容并创建一个新的提交来 merge 两者。

A - B - C - D - E - F [master]
\ \
1 - 2 - 3 - F3 [feature]

How it does that merge is another question .重要的是要意识到 Git 正在 merge F 的内容和 3 的内容

从图中可以看出,feature 和 master 并没有交织在一起。 feature 的历史仍然与 master 的历史不同。 merge 时分支不会消失。如果您继续致力于 feature 和 master,它们将再次出现分歧。

A - B - C - D - E - F - G - H [master]
\ \
1 - 2 - 3 - F3 - 4 - 5 [feature]

这就是为什么 master 的历史可能不会出现在特征中,但现在 F3 有 F 和 3 作为其父级。

Pertaining again to the commits that didn't have any conflicts, why do those files show up as being changed when running git status on the feature branch?

如上所述,当 Git 进行 merge 时,它会创建一个新的提交,其中包含两个分支中的组合更改。这是一个正常的提交,就像其他任何提交一样,除了它有多个父项。如果有冲突,Git 需要人来解决。你留下了 Git 未完成的工作。 Git 能够成功 merge 的任何文件都将被更改和暂存(添加)。任何有冲突的东西都将被更改(带有冲突标记)并且不会被暂存。由您来编辑冲突的文件,添加它们并提交。与正常过程相同。

关于git - 使用 git,为什么在 merge 到功能分支后提交不出现在历史记录中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28157399/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com