Git:由于看似随机的合并,更改不断丢失

发布于 2024-11-09 18:12:36 字数 524 浏览 0 评论 0原文

我有一种感觉,这将是一个显而易见的答案,但我似乎无法解决。

似乎发生的情况是,我向服务器提交/推送了一些更改,并且我的副本上的一切都显示正常。

然后,另一个开发人员从同一分支的服务器中拉取(据我所知,据称看到了我的更改),进行一些修改,将它们提交到自己的本地副本,然后最终将其推回服务器。

在执行此操作的过程中,我的更改丢失了,因为它们的推送(326c8fd0 ...)导致与大量删除/添加行的合并,将存储库重置回更旧的版本。即使使用存储库的新副本,这种情况也已经发生过几次。

下面突出显示的行(8def6e9..)是我所做的提交,假设其他开发人员拉取了更改,则以下提交应该位于同一分支上。合并发生在 326c8fd0,最终错误地重置了存储库,丢失了之前的更改。

TortoiseGit log

我是否遗漏了一些非常明显的事情来解释为什么会发生这种情况?我们都使用 TortoiseGit。

对于可能含糊的解释感到抱歉。

I have a feeling this will be an obvious answer, but I can't seem to work it out.

What appears to happen is that I commit/push some changes to the server and everything appears fine on my copy.

Another developer then pulls from the server from the same branch (allegedly seeing my changes, as far as I'm aware), makes some modifications, commits them to their own local copy then finally pushes it back to the server.

Somewhere in the middle of doing this my changes get lost as their push (326c8fd0...) causes a merge with lots of delete/add lines resetting the repository back to a much older revision. This has happened a few times now even with fresh copies of the repository.

The highlighted line below (8def6e9..) was a commit I made, the following commits should have been on this same branch assuming the other developer pulled the changes. A merge happens at 326c8fd0 which ends up resetting the repository incorrectly, losing previous changes.

TortoiseGit log

Am I missing something very obvious as to why this is happening? We're both using TortoiseGit.

Sorry for the probably vague explanation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光磨忆 2024-11-16 18:12:36

在您的示例中,有人正在合并 f36908d(第一个父级;合并时的 HEAD)和 8def6e9(第二个父级;可能是合并时原始分支的尖端)以生成 326c8fd0。

如果合并提交 (326c8fd0) 缺少与其父级相关的重要内容(f36908d 和 8def6e9;您说它缺少后者的部分),那么创建合并提交的人可能会以不适当的方式执行合并。时尚。

此人可能正在使用 ours 合并策略(使用 -s ours/--strategy=ours 合并或拉取),ours 选项默认的递归合并策略(使用 -X ours/--strategy-option=ours 合并或拉取),或者他们可能只是在做手动解决合并冲突时做出错误的决定。

ours 策略完全忽略历史记录中除第一个父母之外的所有父母所做的任何内容更改。您通常可以识别这种类型的合并,因为合并提交及其第一个父级(即它们的更改)将具有相同的树(即 git diff f36908d 326c8fd0 不会显示任何差异)。

ours 合并策略选项还将忽略第二个父级历史记录中的更改(即您的更改),但仅忽略与第一个父级历史记录中所做的更改(即他们的更改)冲突的更改。在这种情况下,来自第二个父级的一些更改可能会进入结果,但其他更改可能会被完全删除。

另一种可能的选择是,他们只是在解决默认合并期间产生的冲突时做出了错误的决定。

无论哪种方式,有人可能必须与进行合并的用户交谈,以查明他们到底做了什么,以及为什么这样做,以便制定策略来防止将来出现问题。


要恢复,您可以自己重做合并,然后将结果合并到历史记录的当前提示中:

git checkout -b remerge f36908d
git merge 8def6e9
# resolve conflicts and commit
git checkout develop
git merge remerge
# maybe resolve more conflicts

# eventually: git branch -d remerge

或者,如果您同意重写历史记录:

git checkout -b remerge f36908d
git merge 8def6e9
# resolve conflicts and commit
git rebase --onto remerge 326c8fd0 develop
# maybe more conflicts to resolve at each rebased commit

In your example, someone is merging f36908d (the first parent; their HEAD at the time of the merge) and 8def6e9 (the second parent; probably the tip of the origin branch at the time of the merge) to produce 326c8fd0.

If the merge commit (326c8fd0) is missing significant pieces of content with respect to either of its parents (f36908d and 8def6e9; you say it is missing pieces of the latter), then whoever create the merge commit is probably executing the merge in an inappropriate fashion.

This person may be using the ours merge strategy (merge or pull with -s ours/--strategy=ours), the ours option to the default recursive merge strategy (merge or pull with -X ours/--strategy-option=ours), or they may just be making bad decisions when manually resolving the merge conflicts.

The ours strategy completely ignores any content changes made in the history all parents but the first. You can usually identify this type of merge because the merge commit and its first parent (i.e. their changes) will have identical trees (i.e. git diff f36908d 326c8fd0 would show no differences).

The ours merge strategy option will also ignore changes from the history of the second parent (i.e. your changes), but only those that conflict with changes made in the history of the first parent (i.e. their changes). In this case, some changes from the second parent may make it into the result, but others may be dropped entirely.

The other likely alternative is that they are just making bad decisions while resolving conflicts generated during a default merge.

Either way, someone will probably have to talk to the user that did the merge to find out exactly what they did, and why they did it so that a policy can be devised to prevent the problem in the future.


To recover, you might redo the merge yourself and them merge the result into the current tip of the history:

git checkout -b remerge f36908d
git merge 8def6e9
# resolve conflicts and commit
git checkout develop
git merge remerge
# maybe resolve more conflicts

# eventually: git branch -d remerge

Or, if you are okay with rewriting history:

git checkout -b remerge f36908d
git merge 8def6e9
# resolve conflicts and commit
git rebase --onto remerge 326c8fd0 develop
# maybe more conflicts to resolve at each rebased commit
爱*していゐ 2024-11-16 18:12:36

如果您丢失了提交,请确保你们都没有在 gui 上使用 --force 或强制标志来摆脱拒绝。看看DAG的解释。

http://progit.org/book

希望这会有所帮助。

If you are losing commits, ensure that neither of you is using --force or a force flag on your gui to get rid of rejected. Take a look at the explanation of the DAG.

http://progit.org/book

hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文