使用“git add --patch”的 diff 输出之间的差异和“文件合并”
我正在尝试使用 git add --patch
,我注意到它的差异与使用 opendiff
生成的差异不同。
- 这常见吗?是否有不同的差异算法?我只是疯了吗?
- 假设上面是“yes”,有没有办法强制git使用opendiff算法?
I'm trying to use git add --patch
, and I noticed that it's diffs aren't the same as those generated using opendiff
.
- Is this common? Are there different diff algorithms? Am I just nuts?
- Assuming the above is "yes", is there a way to force git to use the opendiff algorithm?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确实存在不同的 diff 算法。 (并且有许多可能的差异会导致对文件进行完全相同的更改 - 这就是 git 不存储更改的原因之一,它只存储每次提交时树的状态:))
即使在 git 中,对于某些命令,您也可以在两种不同的 diff 算法之间进行选择 - 例如,尝试在某些 C 代码中移动函数并比较以下输出:
... 和:
后者通常更具可读性,尽管计算速度较慢。
我不确定 opendiff 使用什么算法,但也许它类似于 patience diff?
不幸的是,我不认为 git 目前可以在 git add -p 中使用不同的 diff 算法,尽管我发现这也非常有用。这里有一个补丁系列添加该功能,但似乎作者尚未将其发送到上游。
There are indeed different diff algorithms. (And there are many possible diffs that will result in exactly the same change to a file - this is one of the reasons it's so sensible that git doesn't store changes, it only stores the state of the tree at each commit :))
Even within git, for some commands you can choose between two different diff algorithms - for example, try moving a function in some C code and compare the output of:
... and:
The latter is usually more readable, albeit slower to calculate.
I'm not sure what algorithm opendiff uses, but perhaps it's similar to patience diff?
Unfortunately, I don't believe that it is currently possible in git to use a different diff algorithm in
git add -p
, although I would find that very useful too. There is a patch series here to add that feature, but it seems as if the author hasn't sent that upstream yet.