I'm cleaning up a git repository that is taken over from another development team. There is no need for the new development team to have the original commit hashes (As we all know, after an amended commit in an interactive rebase, every subsequent commit has a different hash.), so I can rebase/cherry-pick/graft/filter-branch... as much as I want until the repository is "clean".
The other team used a mix of Windows and Linux line endings. When on master
, I added a new branch, checked out the root commit in the cleanup
branch, added a sensible .gitattributes
file, and amended the root commit. Now my repository has 2 root commits, as intended.
Next I want to cherry-pick the master
branch onto the root commit of the cleanup
branch (which will later become the new master
branch). I used this command (14c4a129
is obviously the root commit of the master
branch):
git cherry-pick 14c4a129..master -Xignore-space-change
However, one quarter through the cherry-pick aborts with
error: Your local changes to the following files would be overwritten by merge:
(list of files)
Please commit your changes or stash them before you merge.
Aborting
The changes in these files are only whitespace, because git diff -w
turns up blank. Another clue: find src -type f -print0 | xargs -0 file | sort | grep 'CRLF'
gives me exactly the same list of files as git status
.
This occurs when a new developer appears in the git log, who uses different line endings. To be precise, the cherry-pick borks on his second commit. What I assume happend is, his first commit got normalized line endings, but then his next commit got the original CRLF line endings again, which conflict with the committed files, before the next commit could be cherry-picked.
However, I was expecting that -Xignore-space-change
would solve this for me, so I wouldn't need to do any manual intervention at all. Apparently I misunderstood.
I also tried with --strategy=recursive --strategy-option=renormalize
, same result.
I also tried with an interactive rebase of the master
branch, edit (amend) the root commit to add .gitattributes
, and keep all subsequent commits - which is essentially the same as the cherry-picking, except that it happens in another branch.
What would be the correct way to solve this with a hypothetical "overwrite-whatever-is-here-dammit" option? I'm also open to answers that involve an interactive rebase of the master
branch where I amend only the root commit, because the end result would be identical to a cherry-pick.
- Answers that do not require any manual intervention after amending the root commit, will be upvoted.
- Answers that result in manually fixing individual commits, will be downvoted.
- Comments that result in me further clarifying my question, will be upvoted.