启用 git rerere 有什么缺点吗?
我已经阅读了有关 git 的 rerere
功能的各种内容,并且正在考虑启用它。
git rerere
功能是一个隐藏的功能。该名称代表“重用记录的解决方案”,顾名思义,它允许您要求 Git 记住您是如何解决大块冲突的,以便下次遇到相同的冲突时, Git 可以自动为您解决它。
但我还没有看到有人提到使用rerere
时可能出现的任何问题。
我必须假设有一个缺点,或者它可能会默认启用。那么启用 rerere 有什么缺点吗?它会导致哪些原本不会发生的潜在问题?
I've read various things about git's rerere
feature, and I'm considering enabling it.
The
git rerere
functionality is a bit of a hidden feature. The name stands for “reuse recorded resolution” and, as the name implies, it allows you to ask Git to remember how you’ve resolved a hunk conflict so that the next time it sees the same conflict, Git can resolve it for you automatically.
But I haven't seen anyone mention any possible problems that could arise while using rerere
.
I have to assume there is a downside, or it would probably be enabled by default. So is there any downside to enabling rerere? What potential problems can it cause that would not otherwise occur?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您错误地进行了合并,则将其丢弃,然后再次进行“相同”合并,它将再次错误。不过,您可能会忘记记录的解决方案。来自文档:
请小心在特定路径上使用它;你不想把所有记录下来的决心都毁掉。 (
忘记
没有参数已经已弃用以防止您这样做,除非您输入git rerereforget .
来明确请求它。)但如果您不想这样做,您很容易就会陷入困境将错误的合并放入您的历史记录中..
If you do a merge incorrectly, then discard it, then do the "same" merge again, it will be incorrect again. You can forget a recorded resolution, though. From the documentation:
Be careful to use it on specific paths; you don't want to blow away all of your recorded resolutions everywhere. (
forget
with no arguments has been deprecated to save you from doing this, unless you typegit rerere forget .
to explicitly request it.)But if you don't think to do that, you could easily end up putting that incorrect merge into your history..
正如 JC Hamano 在他的文章中提到的“rerere 的乐趣”(我的粗体)
因此,如果您在过于广泛的内容上激活
rerere
,您可能会因为最后一点而得到令人惊讶或混乱的合并解决方案。另一个缺点是
rerere
要求您提供 GPG 签名的 PIN(如果您已激活commit.gpgSign
)。Git 2.38(2022 年第 3 季度) 已修复此问题
As J. C. Hamano mentions in his article "Fun with rerere" (my bold)
So if you activate
rerere
on too broad a content, you might end up with surprising or confusing merge resolution because of the last point.Another downside was
rerere
asking you for your pin for GPG signature (if you had activatedcommit.gpgSign
).This has been fixed with Git 2.38 (Q3 2022)
我已经全局启用了 rerere。我真的没有注意到任何问题,而且它通常似乎让我的生活变得更轻松。
I've got rerere globally enabled. I really haven't noticed any problems, and it usually seems to make my life easier.
我精心挑选了一个仅包含二进制文件的提交(在 gitk 中)。 Cherrypick 由于冲突而失败(仔细想想这是很自然的),我解决了保留 Cherry Pick 的冲突。后来我惊讶地发现在另一个 rebase 分支中我的 dll 没有表现 - 只是发现它们没有作为(我推测)自动冲突解决方案被带入 rebase 中。所以这是我遇到的唯一一个(启用了 rerere )遇到违反直觉(尽管我确信完全一致)行为的情况。
I cherry picked a commit (in gitk) that only contained a binary file. Cherrypick failed due to conflict (which coming to think about it is natural) and I resolved the conflict keeping the cherry pick. I was surprised later to find in another rebased branch that my dlls did not behave - only to discover they were not carried into the rebase as (I speculate) automatic conflict resolution. So this is the only case I met (having rerere enabled) of running into counterintuitive (though I am sure perfectly consistent) behavior.
根据这个问题和答案,Rerere< /em> 不记录冲突文件中不存在的部分分辨率。可能发生这种情况的一种情况是在文件重构期间,其中某些行被提取并移动到另一个文件,并且冲突的提交随后会更改这些行。这种情况下的解决方案将涉及在新文件中进行更改。
示例
初始状态
文件
a
:重构
新文件
b
:重构文件
a
:冲突
在另一个文件中对
a
进行 更改分支:解决方案
解决方案按原样保留文件
a
中重构的内容,并将新行添加到文件b
中。但请注意,Rerere 仅将解析重新应用于文件a
,因为它在初始解析期间发生了冲突,而文件b
没有遇到任何冲突。最初发生冲突。According to this question and answer, Rerere doesn't record parts of the resolution that are not in the conflicting file. One instance where this might occur is during the refactoring of a file, wherein certain lines are extracted and moved to another file, and a conflicting commit subsequently alters those lines. The resolution in this scenario would involve making the changes in the new file.
Example
Initial state
file
a
:Refactoring
new file
b
:refactored file
a
:Conflicting Change
change to
a
in another branch:Resolution
The resolution retains the refactored content in file
a
as is and adds the new line to fileb
. However, note that Rerere only reapplies the resolution to filea
since it had conflicts during the initial resolution, whereas fileb
didn't encounter any conflicts initially.