How do I force git to checkout the master branch and remove carriage returns after I've normalized files using the "text" attribute?

Jason picture Jason · Jun 20, 2013 · Viewed 271k times · Source

Okay, so I added the file .gitattributes with lines like this

*.css text
*.js text
etc...

I then followed the instructions at http://git-scm.com/docs/gitattributes#_checking-out_and_checking-in

$ rm .git/index     # Remove the index to force Git to
$ git reset         # re-scan the working directory
$ git status        # Show files that will be normalized
$ git add -u
$ git add .gitattributes
$ git commit -m "Introduce end-of-line normalization"

But now my working copy still has the carriage returns! I have untracked files that I would like to keep. How do I have git checkout the master branch again with the normalized files?

I know the files are normalized in the repository because when I clone the repo, I have all the files without the carriage returns.

Answer

Jason picture Jason · Jun 20, 2013

Ahah! Checkout the previous commit, then checkout the master.

git checkout HEAD^
git checkout -f master