wesleyy
wesleyy

Reputation: 2735

git: can't remove a file

This happens when I try running the git cherry-pick <commit sha> command.

  1. git cherry-pick eaf640bd3ce9f2a4e0650a0c9b9d0fbb920a77a9
  2. error: The following untracked working tree files would be overwritten by merge: myfile.java Please move or remove them before you merge. Aborting fatal: cherry-pick failed

Now I want to remove that file, because I don't need it anymore.

  1. git rm myfile.java
  2. This gets me an error: fatal: pathspec 'myfile.java' did not match any files

But I do see the file when running git status. If I delete it manually from disk, any time I do rm -f ./.git/index.lock it gets recreated.

How do I remove that file permanently not having to care about it?

Upvotes: 4

Views: 4748

Answers (1)

melpomene
melpomene

Reputation: 85887

The first error message says the file is untracked, i.e. it is not part of recorded history and git doesn't know about it.

git rm gives you an error for the same reason: You can't remove files from the repo that aren't part of it in the first place.

Plain rm myfile.java should get rid of it.

Upvotes: 1

Related Questions