git-add和git-diff使用不同的差异工具?
tl; dr I配置了一个差异和git-diff
给出了“智能”差异,但git-add
创建了“愚蠢的” hunks。为什么?
我配置了difftool以使用 nbdime 带有nbdime config -git -able -able -git- -global
,我认为本质上只是将这些行添加到我的.gitConfig:
[diff "jupyternotebook"]
command = git-nbdiffdriver diff
[merge "jupyternotebook"]
driver = git-nbmergedriver merge %O %A %B %L %P
name = jupyter notebook merge driver
[difftool "nbdime"]
cmd = git-nbdifftool diff \"$LOCAL\" \"$REMOTE\" \"$BASE\"
[difftool]
prompt = false
[mergetool "nbdime"]
cmd = git-nbmergetool merge \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
[mergetool]
prompt = false
现在git diff
给出了我期望的好输出:
nbdiff /var/folders/6b/03yw1pts2nx_q8vftrh6fv140000gp/T//FILE.ipynb FOLDER/FILE.ipynb
--- /var/folders/6b/03yw1pts2nx_q8vftrh6fv140000gp/T//FILE.ipynb 2022-05-17 14:29:39.937318
+++ FOLDER/FILE.ipynb 2022-05-17 14:09:45.222229
## inserted before /cells/0:
+ code cell:
+ source:
+ ...
+ markdown cell:
+ source:
+ ...
## deleted /cells/0:
- markdown cell:
- source:
- ...
## inserted before /cells/2:
+ code cell:
+ source:
+ ...
但是,如果我执行git git git add add -e folder/files/file .ipynb
,它给我一个“非常糟糕的”差异:
diff --git a/FOLDER/FILE.ipynb b/FOLDER/FILE.ipynb
index 3a1540c..17363f8 100644
--- a/FOLDER/FILE.ipynb
+++ b/FOLDER/FILE.ipynb
@@ -1,621 +1,716 @@
{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- ...
- ]
- },
- ... almost every line in the file is removed
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "j1qKT6qtAYEj"
+ },
+ "outputs": [],
+ "source": [
+ ...
+ ]
+ },
+ ... almost every line in the file is added back
我可能对git-add做什么有根本的误解,但是为什么不使用nbdime diff工具git add
?有什么方法可以添加我在git-diff
中看到的更改?
TL;DR I configured a difftool and git-diff
gives "intelligent" diffs but git-add
creates "stupid" hunks. Why?
I configured the difftool to use nbdime with nbdime config-git --enable --global
which I think essentially just adds these lines to my .gitconfig:
[diff "jupyternotebook"]
command = git-nbdiffdriver diff
[merge "jupyternotebook"]
driver = git-nbmergedriver merge %O %A %B %L %P
name = jupyter notebook merge driver
[difftool "nbdime"]
cmd = git-nbdifftool diff \"$LOCAL\" \"$REMOTE\" \"$BASE\"
[difftool]
prompt = false
[mergetool "nbdime"]
cmd = git-nbmergetool merge \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
[mergetool]
prompt = false
Now git diff
gives the good output I expect:
nbdiff /var/folders/6b/03yw1pts2nx_q8vftrh6fv140000gp/T//FILE.ipynb FOLDER/FILE.ipynb
--- /var/folders/6b/03yw1pts2nx_q8vftrh6fv140000gp/T//FILE.ipynb 2022-05-17 14:29:39.937318
+++ FOLDER/FILE.ipynb 2022-05-17 14:09:45.222229
## inserted before /cells/0:
+ code cell:
+ source:
+ ...
+ markdown cell:
+ source:
+ ...
## deleted /cells/0:
- markdown cell:
- source:
- ...
## inserted before /cells/2:
+ code cell:
+ source:
+ ...
But if I do git add -e FOLDER/FILE.ipynb
, it gives me a "really bad" diff:
diff --git a/FOLDER/FILE.ipynb b/FOLDER/FILE.ipynb
index 3a1540c..17363f8 100644
--- a/FOLDER/FILE.ipynb
+++ b/FOLDER/FILE.ipynb
@@ -1,621 +1,716 @@
{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- ...
- ]
- },
- ... almost every line in the file is removed
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "j1qKT6qtAYEj"
+ },
+ "outputs": [],
+ "source": [
+ ...
+ ]
+ },
+ ... almost every line in the file is added back
I may have a fundamental misunderstanding of what git-add does, but why isn't git add
using the nbdime diff tool? And is there a way I can add just the changes that I see in git-diff
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
git add -e
和git add -p
都需要能够理解编辑 diff。他们通常对DIFF的理解有限,并且需要Plaingit diff
的“愚蠢”格式。nbdime
工具将原始文件分开,将其重新拆除为可用的文本,然后差异可用的文本, 1 ,但这不是的实际 >文件和git add -e
需要在文件中的上进行工作,而不是其清理介绍。1 文件中的内容是机器可读的JSON。
nbdime
工具的结果似乎是yaml。如果Git具有本机JSON DIFF引擎,git add -p
,并且公司将能够处理结果,但是Git却没有,因此不是。如果Jupyter Notebook使用YAML,则Git的面向线路的工具将能够处理它们,但是Jupyter-Notebook却没有,因此不是。Both
git add -e
andgit add -p
need to be able to understand an edited diff. They have a limited amount of comprehension of diffs in general, and require the "dumb" format from plaingit diff
. Thenbdime
tools take the original files apart, re-shuffle them into usable text, and diff that usable text,1 but that's not what's actually in the files, andgit add -e
needs to work on what's in the files, not some cleaned-up presentation thereof.1What's in the files is machine-readable JSON. The result of the
nbdime
tools appears to be yaml. If Git had a native JSON diff engine,git add -p
and company would be able to deal with the result, but Git doesn't, so it isn't. If Jupyter-notebooks used yaml, Git's line-oriented tools would be able to deal with them, but Jupyter-notebooks doesn't, so it isn't.