0

Consider the *.ipynb file extension. This is a text file formatted for use as a Jupyter Notebook.

git diff for these files is impossible to decipher. Merging operations are able to make changes that break the notebook format.

Is there a way to write a plugin or extension for Git which provides custom diffing and merging logic based on file extension?

torek
  • 448,244
  • 59
  • 642
  • 775
cppProgrammer
  • 349
  • 1
  • 2
  • 12
  • 1
    I found a few existing questions which might answer your question: https://stackoverflow.com/q/9154110/157957 https://stackoverflow.com/q/35606909/157957 https://stackoverflow.com/q/20069976/157957 – IMSoP Oct 10 '21 at 16:22
  • 1
    https://www.wrighters.io/jupytext-notebooks-as-markdown-or-python/ – phd Oct 10 '21 at 16:48
  • Thanks for the links, after reading through the Q/A and exploring, I found this: https://github.com/Praqma/git-merge-driver – cppProgrammer Oct 10 '21 at 17:50

1 Answers1

2

Yes you can, using Git filters

There are also a few tools that do this for Jupyter Notebooks, for example nbdime or nbstripout, both support Git filters.

Nils Werner
  • 34,832
  • 7
  • 76
  • 98
  • Thank you! Git filters looks like the way to go. Where is the interface documented? What are the requirements for my own executable that acts as a diff and merge filter? – cppProgrammer Oct 10 '21 at 17:37
  • So it looks like this method is for diff only. There appears to be no solution for merge. Here the documentation is pointed to but contains no further details regarding output formatting: https://stackoverflow.com/a/35607744/2580891 – cppProgrammer Oct 10 '21 at 17:45
  • This project has built a "merge driver". Wonder if it can be adapted for generic use: https://nbdime.readthedocs.io/en/latest/vcs.html#merge-driver – cppProgrammer Oct 10 '21 at 17:47
  • Aha: https://github.com/Praqma/git-merge-driver – cppProgrammer Oct 10 '21 at 17:48