使用“git add --patch”的 diff 输出之间的差异和“文件合并”

发布于 2024-11-14 06:39:14 字数 252 浏览 0 评论 0原文

我正在尝试使用 git add --patch,我注意到它的差异与使用 opendiff 生成的差异不同。

  1. 这常见吗?是否有不同的差异算法?我只是疯了吗?
  2. 假设上面是“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.

  1. Is this common? Are there different diff algorithms? Am I just nuts?
  2. Assuming the above is "yes", is there a way to force git to use the opendiff algorithm?

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

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

发布评论

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

评论(1

花想c 2024-11-21 06:39:14

确实存在不同的 diff 算法。 (并且有许多可能的差异会导致对文件进行完全相同的更改 - 这就是 git 不存储更改的原因之一,它只存储每次提交时树的状态:))

即使在 git 中,对于某些命令,您也可以在两种不同的 diff 算法之间进行选择 - 例如,尝试在某些 C 代码中移动函数并比较以下输出:

git diff

... 和:

git diff --patience

后者通常更具可读性,尽管计算速度较慢。

我不确定 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:

git diff

... and:

git diff --patience

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.

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