3

I have a fairly new repository with 12 commits, all done without line-ending normalization.

No one else is using the repository and I'd like to rewrite history such that line-ending normalization is applied from the beginning (and avoid a commit in the middle that changes line-endings).

Can this be done with git rebase -i or something else? I'm guessing just reordering it with a commit of .gitattributes to the beginning won't fix it.

1j01
  • 3,714
  • 2
  • 29
  • 30

2 Answers2

3

If you didn't have a .gitattributes versioned in your repository and have a single branch, I think it should be enough to just create the .gitattributes file and git rebase -i from the first commit of the repo. Edit your first commit, so every commit based on it gets changed, and you'd be done.

If you had multiple branches you may have wanted to use some git filter-branch thing like they say to remove some file from each commit in the history, but having just 12 commits it shouldn't be necessary at all.

Community
  • 1
  • 1
mgarciaisaia
  • 14,521
  • 8
  • 57
  • 81
0

I am surprised there is not more activity on this six year old Q&A so here is a quick dump of what I found.

Simple option

git rebase -i --root

Change first to edit

.gitattributes

* text=auto eol=lf

then

git add .gitattributes
git rebase --continue

And what eluded to might require https://www.edwardthomson.com/blog/advent_day_21_renormalizing_line_endings.html

(happy to update this answer)

KCD
  • 9,873
  • 5
  • 66
  • 75