Search code examples
gitgit-submodulesgit-rebase

"The following untracked working tree files would be overwritten" during rebase after transforming folder in submodule


In my git repository, I've converted a folder named firmware/SDK into a submodule using the recipe from this link. Then I made two commits:

  • One removing the folder: git rm -r firmware/SDK
  • The next adding the submodule: git submodule add https://blablabla/sdk.git firmware/SDK

This worked very well... until I tried to do an interactive rebase: git rebase -i HEAD~4. Then I got the error: The following untracked working tree files would be overwritten and the rebase aborted.

I understand this happened because the rebase was undoing the commits one by one, but still left the files in my workspace so they conflicted with the other commit.

I tried squashing the these two commits in a single commit, but I still got the same error in the rebase.

Then I tested adding the submodule with a different name, like firmware/submodularized_SDK. In this case, the rebase worked perfectly. But I would like to keep the same name, otherwise I'll have to change my configurations and also choose a new folder name (that's even worse 😅).

Is there a way I can both keep the same directory names and do rebases and checkouts the standard way?


Solution

  • The names—in this case, path names of files or within a submodule—collide when:

    • the names match, and
    • you do something that causes Git to refer to some older commit with that name before the submodule conversion and some newer commit with that name after the submodule conversion.

    So:

    Is there a way I can both keep the same directory names and do rebases and checkouts the standard way?

    Yes: go far enough forward in time (and commits) to the point where you never mix "old" with "new" again, and the problem will stop happening.

    Until then, your current solution—using a different name, so that the names don't collide—works pretty well. It's up to you to decide when you've gone "far enough forward in time" that you won't be going "back in time" to the point where the names collide. At that time, whatever that time is, you can rename the submodule.


    "There are two hard problems in computer science: cache invalidation, naming things, and off-by-1 errors."