git merge中缺少提交更改(Commit changes missing from git merge)

编程入门 行业动态 更新时间:2024-10-10 04:19:11
git merge中缺少提交更改(Commit changes missing from git merge)

我有两个分支,A)开发和B)功能

我在B上工作,现在准备将B合并到A.显然已经做了很多工作,其中很多其他功能分支合并在via pull请求中。 我拉出A的最新头并且出于测试目的,假设我将A合并到B中(注意,我在两个方向上都得到相同的行为,但我正在试图找出问题所在)。

我将A合并到B中,但在解决合并冲突后我有很多编译器错误。 我注意到实际上A中包含的代码只是没有将它转移到B.这导致构建失败,并且有很多东西丢失(它至少是一个大代码的代码)。

我跟踪了从A到B有“问题”合并问题的提交。虽然它并没有合并,但是当我在合并后签出B时键入“git log”时,我确实看到了它。 出于某种原因,与提交相关的实际更改才会消失。 关于相关代码没有合并冲突,我确信在处理B时我从未接触过该部分,因此其他任何事情都可能发生。

关于“丢失”提交(即使我在分支日志中看到它),我应该做些什么来恢复实际的更改? 我会使用diff工具,但我担心这是一个更大问题的症状,而我不知道的其他代码也可能会丢失。

我对git很新,所以我不太清楚如何处理这个问题。 如果有任何其他可能有用的信息,请告诉我。

到目前为止我尝试了什么:

将A合并到B中,提交就在那里,但是来自提交的代码不是将B合并到A,同样的问题与相同的代码/提交

我已经尝试过变基础,但许多冲突的许多提交都让分支机构失效了。 所有提交也在服务器上,所以从我读到的这可能是一个坏主意。 如果我应该尝试在某个方向(A-> B或B-> A)进行调整,请告诉我。

I have two branches, A) develop and B) feature

I work on B, and am now ready to merge B into A. A has obviously had a lot of work done, with a lot of other feature branches merging in via pull requests. I pull the latest head of A and for testing purposes, let's say I merge A in to B (Note, I get the same behavior going both directions, but I'm trying to figure out where the problem is).

I merged A in to B, but I have a lot of compiler errors after resolving the merge conflicts. I noticed that there is actually code included in A that is just not making it over to B. This causes the build to fail, and there are many things missing (it's at least one large commit worth of code).

I tracked down the commit that I'm having issues "merging" from A to B. It's not that it's not merging though, I do see it when I type "git log" when B is checked out after the merge. For some reason the actual changes associated with the commit just disappear. There are no merge conflicts regarding the code in question, and I'm certain I never touched that section while working on B so that anything else could happen.

Regarding the "missing" commit (even though I see it in the branches log), what am I supposed to do to recover the actual changes? I would use a diff tool, but I'm worried this is a symptom of a larger problem and that other code that I'm unaware of could also be missing.

I'm fairly new to git, so I'm a little unsure of how to approach this. Please let me know if there's any other information that could be useful.

What I've tried so far:

Merging A in to B, commit is there but code from commit is not Merging B to A, same issue with same code/commit

I've tried rebasing, but the branches are off by many commits with many conflicts. All commits are also on the server so from what I've read this may be a bad idea. Please let me know if I should try rebasing in some direction (A->B or B->A).

最满意答案

如果它只是一个缺少的提交,你可以通过在B分支上发出cherry-pick命令轻松地将它应用于A分支:

git cherry-pick commit_name

此命令采用特定提交(按名称)并将其作为新提交应用于当前分支。 只需检查日志中的提交名称并将其粘贴为参数即可。

以下是有关该命令的更多信息: https : //git-scm.com/docs/git-cherry-pick

更多关于可能的原因

至于问题本身。 您遇到这种情况可能有很多原因,其中一些可能是微不足道的,有些则不是。 我认为GIT最有可能看到差异,但由于某种原因得出结论,他们不应该应用(在自动合并过程中)。 您必须检查B分支的历史记录,它是如何以及何时(关于此A提交)创建的,并且它具有该特定提交的任何历史记录。

无论如何,如果来自该提交的更改实际上不存在于B代码中,那么一个挑选应该帮助您解决这个问题,因为它将使用新的提交名称应用这些更改,从而避免任何问题。

Solution

If it's just one commit that's missing you can easily apply it to the A branch by issuing a cherry-pick command whilst being on the B branch:

git cherry-pick commit_name

This command takes a specific commit (by name) and applies it to the current branch as a new commit. Just check the name of the commit in your log and paste it as an argument.

Here is some more information on the command: https://git-scm.com/docs/git-cherry-pick

More on the probable cause

As to the problem itself. There may be numerous reasons why you are experiencing such a situation, some of which may be trivial, some not. I'd say it's most probable that GIT sees the differences, but for some reason comes to a conclusion that they should not be applied (during the auto-merge process). You would have to check the history of B branch, how and when (with regards to this A commit) was it created and does it have any history with that specific commit.

Anyway, if the changes from that commit are not physically present in the B code, a cherry-pick should help you solve this as it will apply these changes with a NEW commit name thus avoiding any problems.

更多推荐

本文发布于:2023-08-07 01:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1458400.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:merge   git   missing   Commit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!