tags:

views:

60

answers:

2

So I was working in a branch and decided to remove my docs directory from the repo using git rm -r --cached docs. This all went well. Committed, working directory clean, all good. Now when I try to git checkout master so that I can merge this branch back into master I get the following error:

error: Untracked working tree file 'docs/bin/.htaccess' would be overwritten by merge.

Is there anything I can do now to get back to my master branch? Do I need to put the docs directory back into the repo, then switch branches, and then remove it on master?

+1  A: 

Note that git rm --cached removes files from the index only. Why didn't you want to delete them from the filesystem too?

git is trying its best to stop you from losing work. Assuming the files in docs are safely committed in another branch, use

$ git checkout -f master

From the git checkout documentation:

-f
--force
When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.

When checking out paths from the index, do not fail upon unmerged entries; instead, unmerged entries are ignored.

Greg Bacon
Thanks this is just what I needed. I wanted to docs folder to exist, I just didn't want to track it.
seth
+1  A: 

It sounds like the problem is that you removed the directory from the repo, but not from your working tree, so when trying to check out master, Git sees that there's a file that would be overwritten. I'm assuming that you would like to merge the branch, and include the delete in the merge; afterwards, this directory would no longer be tracked by Git, but you would still have it in your working copy.

You could do what you describe, or you could move that directory out of the way, check out master, merge your branch, and then move the directory back. You would probably add a .gitignore rule this directory too, so that Git doesn't keep listing it in the status, or accidentally add it back to the repo.

Brian Campbell