Viewing git filters output when using meld as a diff tool

自闭症网瘾萝莉.ら 提交于 2019-11-30 15:34:16

Here's a hack solution for this problem. The original git filter you are referring to has been formalized as the package nbstripout (pip3 install nbstripout), but you could put any filter into this script and it would work the same. I'll assume you want to configure this for the user rather than a particular repo.

In ~/.gitconfig, add a new diff driver named git-nb-clean-diff:

[diff "git-nb-clean-diff"]
    command = git-nb-clean-diff

In ~/.config/git/attributes, configure notebooks to be diffed with that diff driver:

*.ipynb diff=git-nb-clean-diff

Now we need to make the actual diff driver! In ~/bin/git-nb-clean-diff (must have this filename but the location is optional):

#!/bin/bash
# pass the stripped working tree file and the repo copy 
# to meld for diffing
meld <(cat $1 | nbstripout) $2

Lastly, we make this file executable

chmod +x ~/bin/git-nb-clean-diff

and add it to the path so git can find our diff driver when it runs

echo "PATH=$PATH:~/bin" >> ~/.bashrc
# reload the edited .bashrc
source ~/.bashrc
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!