1

I've a series of commits to a file that I now realize was created with incorrect line endings. I want to rebase the commits and apply dos2unix command at each step. I can't see an easy way to do this as after each step git registers a full conflict with the file. Any ideas?

EoghanM
  • 25,161
  • 23
  • 90
  • 123

2 Answers2

1

Use filter-branch.

git filter-branch --tree-filter 'dos2unix filename' master

(Assuming the commits you want to modify are on master. You can also use a more specific list of commit names, instead of applying the filter to the entire branch.)

chepner
  • 497,756
  • 71
  • 530
  • 681
  • Hmmm, doesn't seem to work. As there are 10K+ commits I'm executing it as follows: `git filter-branch --tree-filter 'dos2unix filename' commit-before-file-was-first-added..master` It runs through all those commits, but then says `WARNING: Ref 'refs/heads/master' is unchanged` at the end, (and `filename` has been changed to unix format, but in the working directly only). – EoghanM Apr 16 '15 at 16:23
  • You might need to checkout another branch first, so that the branch head can be updated. – chepner Apr 16 '15 at 16:25
  • Hm, I think `filter-branch` is the way to go here, but I do not know the command well enough to debug the issue or to advise further. Maybe someone else can provide a better answer. – chepner Apr 16 '15 at 16:35
  • Thanks for the answer though! I experimented with the `rm -f` command (example from docs) instead of `dos2unix` and got the same result (no change to commit history but file removed at the end) – EoghanM Apr 16 '15 at 16:48
0

which environment was used to modify the file with incorrect line endings ? if it's windows make sure your workspace is using UTF-8 encoding.

You can manage that through git config (see link for option) :

git config core.autocrlf true

if set to true this converts LF endings into CRLF when you check out code (when working under windows)

More infos : http://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#Formatting-and-Whitespace

flafoux
  • 2,080
  • 1
  • 12
  • 13
  • 1
    Thanks, but this isn't what I was asking - the file was not originally committed by me (and was originally committed via svn anyway). – EoghanM Apr 16 '15 at 10:13
  • It seems that EoghanM's problem is that the actual git objects in the repo already have the Windows line endings. – Kaz Apr 16 '15 at 13:34