Search code examples
gitrebase

Error rebasing: non existing untracked files would be overwritten


I'm trying to squash a few commits into a single one. The changes made involve changing file contents, as well as only changing the filename case on some files or their directories.

When running git status,

nothing to commit, working tree clean

However, when I rebase -i <sha>,

error: The following untracked working tree files would be overwritten by checkout:
        myDir/file1
        myDir/file2
        ...
        myDir/fileN
Please move or remove them before you switch branches.
Aborting

At some point in the history of commits I'm trying to squash, myDir was renamed to MyDir

However, none of those files are actually on my disk. Running ls shows the new MyDir, but no myDir.

How can I fix this so I can rebase?

fyi, ignorecase = false in .git/config under [core] and I'm on Mac OSX


Solution

  • The core.ignorecase setting is Git's way of keeping track of how your operating system actually behaves. If Git can create a file named README, and then open it using the name readme, your OS's file system is case-insensitive. This means your OS can't create two separate files whose name differs only in case.

    That applies to directories as well. If MyDir exists, Git's attempt to create myDir to hold files named myDir/file1 and so on will fail (in a way Git considers mostly harmless, namely that the directory already exists), because the OS will just use the existing MyDir. Git's attempt to write myDir/file1 will then overwrite the MyDir/file1 file. If those files currently contain valuable data, you will want to move them out of the way, just as Git suggests. In any case you will probably want to move the entire directory MyDir out of the way so that Git can create one spelled myDir (lowercase m).

    If your operating system / file-system really, truly is not case insensitive—if you can create different files all named README, readme, ReadMe, and so on—you can change the core.ignorecase setting to inform Git of this fact. However, if your system is case insensitive, changing that would be lying to Git, which would be a bad idea.