Nathaniel D. Waggoner
Nathaniel D. Waggoner

Reputation: 2886

git thinks i've replaced all contents of build.gradle, even though I only added one line

Steps:

1) git checkout master

2) git reset HEAD --hard (i wanted to be REALLY sure).

3) nano build.gradle

4) hit enter once, add the sentence on the new line "// a git test"

   - I've been able to reproduce this a couple of ways, this is the simplest.

5) git status - shows build.gradle as a change not staged for commit

6) use gitk to view changes - shows every single line in the file.

7) commit

8) push

9) commit shows on github.com as if i had deleted and replaced every single line (red section with minus, green section with +) even though most of it is identical.

I've never seen this behavior before and so I'm super confused about what might be going on here. This is the only file in the project for which this behavior is happening. I am using AndroidStudio if that matters to anyone.

Edit: I'm on mac, just a heads up.

Upvotes: 1

Views: 586

Answers (1)

Nathaniel D. Waggoner
Nathaniel D. Waggoner

Reputation: 2886

I ended up doing the following:

first i ran:

file build.gradle

and saw that it was in CR line endings. Based off of other comments I tried following this guide:

https://help.github.com/articles/dealing-with-line-endings

But I couldn't get that to actually make the changes I needed.

So Instead manually changed the file from CR to *nix format via:

tr '\r' '\n' < inputfile > outputfile

from http://en.wikipedia.org/wiki/Newline

I committed the result in place of the original, and everything is working correctly now.

Upvotes: 1

Related Questions