Search code examples
gitrebasegitattributes

Trying to rebase to correct an attribute filter, but can't due to "unstaged changes"


Problem

My cleaning filter failed to apply (a separate issue unrelated to Git) resulting in Git storing "dirty" files. I fixed the filter, but now I need to clean the files and then store them again.

What is happening

I know from another question of mine that if files were commited without a filter when there is an active filter present, no matter what I do those files will be seen as changed since the hashes will fail to match up. No ammount of git reset --hard or git stash will fix this, nor anything else.

Failed solution

My first thought was to do an interactive rebase. However, even with --force it won't let me. With the force option, it simply says it can't be done, but without it Git complains about unstaged changes.

cannot rebase: you have unstaged changes

Unfruitful searches

I tried looking for a way to force Git to ignore unstaged changes, but all that lead to were the usual methods of HANDLING unstaged changes (ie reset and stash).

What I'm in the midst of attempting

I'm currently trying to do the rebase manually, but for some reason it isn't working as expected. Its too soon to give more details than that, and its time for some lunch. I'm going mentioning this now since it came up in the comments.

The only thing left as far as I can see.

The only solution I can think of is to set the current working directory aside, then git reset --hard last-good-commit. I'd then move the files back and commit, however I'd lose history, and I don't want that.

By "losing history" I mean the commits leading up to the "present" will be lost. I wish to avoid this.

Question

How do force a rebase in this scenario?


Solution

  • The answer was to disable filters and then apply the filters manually as I rebase. As I had mentioned in the comments, there was a bit of a snag. That snag was that doing so resulted in empty commits. The solution to that was to remove the commit since it was an automated commit in the first place which is also the reason the filter wasn't applied.

    Further information

    In ~/.bashrc I have a load path defined for the lib I wrote which is used by the filter scripts. The problem was that the automated git commit script was bypassing that environmental variable causing the cleaning script to fail. The solution to this was to specify the path to the lib explicitly in the script.