0

I have a git repository. There has been 3 total contributors to the repository and one contributor used Windows from a certain commit so the file (file.html) has Windows newlines (\r\n) instead of Unix newlines (\n).

How do I remove all the \rs from the file and from all of the commits?

I'm not trying to change my local settings, I want to remove those \rs from the file in all commits.

EDIT: Solved, the command is to use `it filter-branch -f --tree-filter 'dos2unix file.txt' -- --all

Sorry
  • 532
  • 2
  • 6
  • 19
  • I have added a response in that linked-as-duplicate answer. The only thing I would add is that in your case, you will have to checkout the revision where the developer changed the files to CRLF, change the format of the files (after you have set the .gitattributes file properly) by runnig dos2unix on them and then amend the revision. Hope it helps. – eftshift0 Jun 13 '19 at 19:17
  • @eftshift0 git is not messing with EOL. I'm just supposed to fix the `\r` endings and apparently the tool is to use `filter-branch` somehow. – Sorry Jun 13 '19 at 19:23
  • If it's just a few revisions that are busted, I would _not_ go with filter-branch. That's an overkill. Just amend the busted revisions (check out the revision, run dos2unix on the affected files, add, commit--amend --no-edit) and you should be fine (not saying that it's not a pain in the.... read end). If it's already a line of revisions, it will probably require a little bit more effort. The question has been closed so can't write a recipe... will try in the following comment. – eftshift0 Jun 13 '19 at 20:00
  • @eftshift0 I don't know from which revision the problematic endline started, that's why I thought of `filter-branch`. My general idea is to remove `\r` from all commits that have them but I'm not sure how to do that. – Sorry Jun 13 '19 at 20:04
  • 1
    Oh... well.. then probably filter-branch is the way to go. But I don't know the details of how to make it work. In general, you should run it so that in every revision that it works on, it runs dos2unix on the affected files. – eftshift0 Jun 13 '19 at 20:05
  • @eftshift0 that was the solution, thank you! – Sorry Jun 13 '19 at 23:03

0 Answers0