Yegie
Yegie

Reputation: 61

Deleting ghost files that don't exist in the file system but are left in git after a merge?

So I just did a merge between two repositories. In one of those a file was called FOOBar and in the other it was called FooBar. The merge went fine, it correctly identified that the two files were renamings of one another, and in the end I kept all the changes merged to FooBar since that fits naming convention. After completing and committing the merge doing a "git status" shows a change not staged for commit pointing to FOOBar. Except FOOBar no longer exists only FooBar is left.

I have tried "git add .", "git checkout -- .", "git clean -f", "rm FOOBar", "git restore ." but after all of these the files still show up as unstaged for commit and not existing in the file system.

What can I do to get rid of these files in git?

Upvotes: 0

Views: 1502

Answers (2)

marcusshep
marcusshep

Reputation: 1964

In addition to Lasse's answer you can run git clean -df which will clean the working tree of deleted directories and files. Here's a link to the docs.

Upvotes: 0

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391456

I think most top level git commands operate on the files they find on disk, and then locate the correct file in the index to manipulate. Since the files you have on disk has the wrong case, this might be tripping it up.

Anyway, that's just guesswork.

Here's how to get rid of it, you have to manipulate the index directly.

The following command should get rid of the file:

git update-index --remove FOOBar

Upvotes: 3

Related Questions