5

I read up on .gitattributes and told git not to change line endings for a few files. Problem is, they're already committed. Stupid clever git now does not want to undo what it's done. Deleting and re-adding the files does not help (it optimizes out the change). Right now, I have to manually re-copy these files whenever I pull from the repo.

What can I do? Report this as a bug and wait for a fix? Somehow delete the commit objects to force git to re-create them? The latter seems difficult/dangerous.

EDIT: I found this nice guide on GitHub for completely deleting a file from a repo. Problem is, I don't really want to remove it from the entire history. Do I have to, or can I do it only for the last commit? If I do it for the last commit, will Git re-find and optimize again?

Aleksandr Dubinsky
  • 22,436
  • 15
  • 82
  • 99

2 Answers2

1

I'll re-explain the problem now that I've dug deeper (my original description was slightly off), and explain the work-around.

My problem files on my Windows machine have LF endings. When I pushed them to beanstalkapp.com, they retained their LF endings (as to be expected regardless of Git settings). When I pulled them on another Windows machine, they got changed to CRLF. I added .gitattributes to treat them as binary, but pulling this file on the other Win machine did not get it to check them out as LF.

Git on other Win SHOULD have re-chcked them out properly when it detected the new .gitattributes, but didn't. Also, deleting in one commit, re-adding them in the next, BUT pushing them in 1 step and pulling them in 1 step did not work either.

I had to pull the commit where they're all deleted. Then I had to pull again when they're re-added. This got the other Win machine to check them out correctly. I did not try deleting them on the other Win machine and doing a reset --hard, which someone suggested might have also cleared Git's brains.

I'll write to the mailing list about what the behavior of pulling .gitattributes should be.

Aleksandr Dubinsky
  • 22,436
  • 15
  • 82
  • 99
  • What was the outcome of the mailing list query? – Arafangion Feb 12 '13 at 00:54
  • 2022-07-02. Have faced same issue. Git remote contains file with CLRF. Locally changing this simply to LR. git status shows changed file. However, Git ignores "git add" staging command. Git sucks. – lol lol Feb 07 '22 at 10:31
-1

1) Reset your history to the last correct commit (WARNING: do this only if you or some body else have not done new changes in project)

2) update .gitattributes to correct values

3) commit

4) push with --force attribute.

radistao
  • 14,889
  • 11
  • 66
  • 92
  • There is no last correct commit. These files were incorrect from the get-go, and they were added a number of (useful) commits back. But what do you mean by "reset"? Will this delete the objects? Because I expect git will just re-find those objects and use them. – Aleksandr Dubinsky Sep 01 '12 at 21:03