kynan / nbstripout

strip output from Jupyter and IPython notebooks
Other
1.19k stars 95 forks source link

Windows newlines in diff --cached after git add with nbstripout #110

Closed tgandor closed 4 years ago

tgandor commented 4 years ago

I installed nbstripout without arguments (locally) in the repository.

Then I added a "dirty" notebook, say with git add myNb.ipynb.

Ok, doing a check with git diff --cached - I don't see outputs or metadata (OK!), but all the inserted lines have a "^M" (carriage return) in the diff view.

I ran nbstripout myNb.ipynb and git status showed no changes. Even so, I re-ran git add myNb.ipynb and then git diff --cached showed a lot of newlines.

I also have nbdime installed, so I saw that the [diff ipynb] (or sth like that) section in .git/config and deleted it. The ugly JSON diffs with ^M disappeared, and the structured nbdime diff shows no appended newlines (but - it may actually mask the problem).

I can't be sure what is at fault here:

I'd like to know, if this is a false alarm, or actual whitespace pollution to the repository.

kynan commented 4 years ago

Can you please confirm your platform, Python and nbstripout version?

tgandor commented 4 years ago

I'm sorry but I've been working in a setup where I wanted to commit the cell outputs together with the notebooks recently. In the next few days I'll set up nbstripout again and try to reproduce this.

amard33p commented 4 years ago

Windows10 == 1809 Python == 3.8.1 nbstripout == 0.3.7

--- a/arrays_strings/rotation/rotation_challenge.ipynb
+++ b/arrays_strings/rotation/rotation_challenge.ipynb
@@ -165,9 +165,9 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.5.0"
+   "version": "3.8.1"^M
   }
  },
  "nbformat": 4,
- "nbformat_minor": 0
+ "nbformat_minor": 1^M
 }
kynan commented 4 years ago

What is your Git config setting for core.autocrlf and core.safecrlf?

amard33p commented 4 years ago

What is your Git config setting for core.autocrlf and core.safecrlf?

$ git config core.autocrlf input

$ git config core.safecrlf \<no output>

kynan commented 4 years ago

I don't have access to a Windows system to reproduce this and I don't have a good idea what might cause this behaviour and if it's working as intended or not.

Does nbstripout change this behavious i.e. when you change a notebook without having nbstripout installed and then git add it, does git diff --cached show the ^M?

kynan commented 4 years ago

@amard33p any update on this?

amard33p commented 4 years ago

@amard33p any update on this?

@kynan Sorry this was quite a while back. I have since switched Google Colab for Jupyter notebooks. It serves my purpose.
https://github.com/kynan/nbstripout/pull/126 looks promising though...can't verify it.

kynan commented 4 years ago

@ooiM has this been addressed by #126? Can we close this?

ooiM commented 4 years ago

@kynan Yes, I think the problem was solved.