I have a repository which has some files that are non-standard filetypes but are actually text files - unfortunately it has lacked a .gitattributes file for its entire history (~125 commits) so all of these files are being treated as binary instead of text as they should be. I am trying to find a way to retroactively apply the text attributes to the existing commits of the repository.
My first thought was to create a new commit based off the first commit of the repository which includes the attributes, then to rebase off of that:
G GitAttributes
/
A---B---C---D---E---F master
To achieve this I tried using git rebase -X theirs GitAttributes but for nearly every commit it applies I have to manually stash or commit changes before continuing the rebase. I always want to commit the changes from each successive commit, as the differences I am getting are just users committing files with different line endings.
error: Your local changes to the following files would be overwritten by merge:
<<file path>>
Please commit your changes or stash them before you merge.
Aborting
hint: Could not execute the todo command
hint:
hint: pick <<commit hash>> <<commit name>>
hint:
hint: It has been rescheduled; To edit the command before continuing, please
hint: edit the todo list first:
hint:
hint: git rebase --edit-todo
hint: git rebase --continue
Could not apply <<commit hash>> <<commit name>>
What I want is to rebase to apply the text attribute to all these files, while always choosing the next commit's changes automatically. Manually resolving everything for each file changed in each commit is not feasible.
My questions are:
- Is rebase even the correct approach to take to this problem?
- Am I correct in my understanding that
-X theirsis the correct strategy to achieve what I want? This part I find somewhat confusing. - Is there a more effective way to automate this? Or do I really have to resort to manually committing each time the rebase aborts?