Weeble
Weeble

Reputation: 17930

Recover from bad .gitattributes

I put this in a .gitattributes file due to a misunderstanding:

* text=auto eol=lf

I thought this meant that for all files git should autodetect if it's text, and if it is text, enforce LF-only when files are added to the repo, by converting CRLF to LF. What I believe it actually does that the second setting overrides the first, and forces git to treat all files as text with LF-only line endings, even binary files like PNG.

My situation now is that other people have added binary files. I have checked out a version that includes those files. Further changes have been made to the repo. I want to pull the latest version (I have no changes of my own) and then fix the .gitattributes file. But I cannot pull because git thinks I have changes.

[64]D:\projects\spark_raw_quotes$ git pull --ff-only
Updating 69f37b0..fced821
error: Your local changes to the following files would be overwritten by merge:
        src/avg_price/jars/quotearchive-thrift-assembly-0.1.jar
Please, commit your changes or stash them before you can merge.
Aborting

[64]D:\projects\spark_raw_quotes$ git status
On branch master
Your branch is behind 'origin/master' by 225 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   data/quotes_UK1_2015-02-16_23_0_244.thrift.b64.gz
        modified:   src/avg_price/jars/quotearchive-thrift-assembly-0.1.jar

no changes added to commit (use "git add" and/or "git commit -a")

I cannot follow the instructions here, because git always thinks I have changes:

Git Pull While Ignoring Local Changes?

The files haven't been changed, they just exist in the repository and on disk with CRLFs (since they're moderately large binary files this sequence occurs occasionally) and git recognized that the .gitattributes rule says that the CRLFs should be converted to LF. (At least, that's what I believe is going on.)

I can clone the repository to a new directory, but I'd like to know how to fix this properly. For example, if I had changes stashed in this repo that I wanted to replay and so I couldn't just throw it away and reclone? Can I temporarily override the .gitattributes settings, until I've managed to apply my changes and I'm back in sync with the master branch?

Upvotes: 1

Views: 206

Answers (1)

David Deutsch
David Deutsch

Reputation: 19035

Assuming you have no "real" changes in your working directory (i.e. you don't care if your working directory gets totally overwritten), the following will bring you up to date (assuming you are on master): git reset --hard origin/master. This moves your HEAD to point to origin/master, overwriting your working directory and index with the contents of origin/master.

Upvotes: 1

Related Questions