git - 让 TortoiseGit 在 jupyter 笔记本上使用 nbstripout 运行 git diff.textconv 过滤器

标签 git jupyter-notebook tortoisegit

我已将 git 配置为使用 nbstripout 删除 jupyter notebook 输出在提交和差异之前。它在 git bash shell(在 Windows 中)中工作得很好。 现在我想在 TortoiseGit 中拥有相同的功能。 输出在提交时被正确剥离,但是从资源管理器上下文菜单运行 TortoiseGit 内部差异工具不会触发 nbstripout 在 .git/config 中配置的 git diff.textconv 过滤器:

[diff "ipynb"]
    textconv = \"D:/Applications/Anaconda3/python.exe\" \"D:/Applications/Anaconda3/lib/site-packages/nbstripout.py\" -t

有没有办法在diff之前自动运行nbstripout?

我目前的解决方法是在运行 diff 之前手动删除笔记本输出。

最佳答案

从 2.7.0 开始,TortoiseGit 不支持 diff.textconv 过滤器。在 TortoiseGit 中使用高级差异设置:https://tortoisegit.org/docs/tortoisegit/tgit-dug-settings.html#tgit-dug-settings-Progs-Adv

.ipynb 文件的 Advanced Diff Viewer Settings 下配置为 C:\path\to\script.bat %base %mine 时,以下批处理脚本会完成这项工作.它首先运行 nbstripout 并在 TortoiseGit 差异查看器中打开剥离后的文件以及 %base 版本。

:: Run nbstripout on a jupyter notebook before opening it with TortoiseGit
:: Call Signature: nbstripout_TortoiseGit.bat %base %mine

:: Parameters and options
@echo off
set "python_exe=C:\path\to\python.exe"
set "nbstripout=C:\path\to\nbstripout.py"
set "tmpfilename=%temp%\nbstripout_tempfile_%USERNAME%_%RANDOM%.ipynb"
set "diffViwer=TortoiseGitMerge.exe"

:: Get cmdline arguments
set base=%1
set mine=%2

:: Strip output from notebook
%python_exe% %nbstripout% -t %mine% > %tmpfilename%

:: Open file in diff viewer
%diffViwer% %base% %tmpfilename%

:: Remove tmpfilename
del %tmpfilename%

关于git - 让 TortoiseGit 在 jupyter 笔记本上使用 nbstripout 运行 git diff.textconv 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53652881/

相关文章:

Git 交互式 merge ?

GitHub 还是 BitBucket?

git - 从命令行清除 Jupyter 笔记本的输出单元

python - 在 iPython/Jupyter 笔记本中安装多个 Python 3 内核

git - TortoiseGit 将干净目录显示为冲突

git - 我可以在 git 中 checkout 树对象吗?

Git 从另一个没有历史记录的存储库中 pull

python - IPython 笔记本中的标准输出与 CLI IPython

git - TortoiseGit 和 Pageant,每次都必须为 "add key"

git-branch - 如何使用 tortoisegit 创建一个孤立分支?