Chris Dutrow
Chris Dutrow

Reputation: 50362

GIT will not commit within PyCharm because of "local modifications"

Using PyCharm to commit to git. After going through the dialogs to commit, t I keep getting this error:

error: 'static/static/js/backbone_objects/router.js' has local modifications
(use --cached to keep the file, or -f to force removal)

The problem is that I'm using PyCharm's interface to do this, so as far as I know, I cannpt add those commands to the git commit command.

What is a good way to handle this situation?

Thanks so much!

Upvotes: 1

Views: 1990

Answers (1)

LoKi
LoKi

Reputation: 3855

Most probably, the situation that happened is the following:

  1. you've made some modifications to the file and staged them to the index.
  2. you've deleted the file.
  3. when you call commit, PyCharm automatically calls "git add" on all modified files, and "git rm" on all deleted files.

The latter command produced the error. By this message Git warns you that you are about to delete a file, which you have not only changed, but even have staged the changes.

To solve the problem just call git rm -f <file> from the command line.

The reason why PyCharm doesn't handle this situation properly is because it doesn't understand Git staging area in the implementation. Feel free to vote for IDEA-63391 (general problem) and IDEA-85948 (probably the same issue as you've faced).


Btw, my version of Git reports a more clear message, so you must be using some older one:

error: 'dir with spaces/newfile.txt' has changes staged in the index
(use --cached to keep the file, or -f to force removal)

Upvotes: 7

Related Questions