`git rebase -i` error: The following untracked working tree files would be overwritten by checkout:

Viewed 678

When running git rebase -i I get an error:

$ git rebase -i 01a182d66b14ef8f32eb09614fe2c7144044a537^
error: The following untracked working tree files would be overwritten by checkout:
        Annotation/README.MD
Please move or remove them before you switch branches.
Aborting
error: could not detach HEAD

I don't see what the issue is, since when I run git status it tells me there are no unstaged changes:

git status
On branch dataset
nothing to commit, working tree clean

Running git stash also doesn't help:

$ git stash
No local changes to save
1 Answers

The final error message (about failing to detach HEAD) should just be ignored here; it's an artifact of the earlier error.

The earlier error is pretty straightforward though:

error: The following untracked working tree files would be overwritten by checkout:
       Annotation/README.MD

This means that right now, you have an untracked working tree file named Annotation/README.md. (If you're not sure what "untracked file" and/or "working tree" mean, read my answer here for instance. Since git status is not complaining about it, it seems to be both untracked and ignored.)

Meanwhile, the commit that git rebase is first going to check out, so as to copy some other commits, has a file in it named Annotation/README.MD. To check out that commit, Git must check out that file. Checking out that file will clobber the file named Annotation/README.MD that is sitting in your working tree right now.

To avoid losing the contents of the working tree file Annotation/README.MD, Git won't check out that commit right now. If you save the file—by adding and committing it—or remove the file entirely or move it out of the way, that will solve the problem:

Please move or remove [this file] before you [check out the target commit]

Since git rebase needs to check out the target commit before it can begin the commit-copying process, git rebase needs you to do what git checkout needs you to do.

Related