Git - replace line endings in an already committed file

I read .gitattributes and told git not to change line endings for multiple files. The problem is that they are already committed. The stupidly smart git now doesn't want to undo what he did. Deleting and re-adding files does not help (it optimizes the change). Right now, I have to manually re-copy these files whenever I exit the repo.

What can I do? Report it as an error and wait for the fix? How to delete commit objects somehow to force git to recreate them? The latter seems difficult / dangerous.

EDIT: I found this great GitHub guide for completely deleting a file from a repo. The problem is that I really do not want to remove it from the whole story. Should I, or can I only do this for the last commit? If I do this for the last commit, will git find and optimize again?

+4
git
source share
2 answers

Now I will explain the problem again when I went deeper (my original description was a bit off) and explain the workaround.

My problem files on my windows machine have LF endings. When I pushed them to beanstalkapp.com, they kept their LF endings (as expected, regardless of Git settings). When I pulled them to another Windows machine, they were changed to CRLF. I added .gitattributes to treat them as binary, but I couldnโ€™t get this file on another Win machine to check them as LF.

Git on other Win SHOULDs correctly dropped them when they discovered new .gitattributes, but did not. In addition, deleting in one commit, re-adding them to the next, BUT, pushing them 1 step and pulling them 1 step also failed.

I had to pull out a commit where they were all removed. Then I had to pull again when they were added again. This led to another Win machine checking them correctly. I did not try to delete them on another Win machine and do a reset -hard, which someone suggested might have also cleared Git brains.

I will write to the mailing list about how .gitattributes behavior should look.

+1
source share

1) Reset your story to the last correct commit ( WARNING: do this only if you or someone else has not made new changes to the project )

2) update .gitattributes to adjust the values

3) commit

4) click with the --force attribute.

-one
source share

All Articles