Aniruddha Bhondwe
Aniruddha Bhondwe

Reputation: 831

Git untracked working tree files would be overwritten by merge

I made a commit and now when I try to pull i get this error.

error: The following untracked working tree files would be overwritten by merge:
    login/models.pyc
    timer/__init__.pyc
    timer/admin.pyc
    timer/api.pyc
    timer/email.pyc
    timer/exceptions.pyc
    timer/models.pyc
    timer/serializers.pyc
    timer/urls.pyc
    timer/views.pyc
Please move or remove them before you can merge.
Aborting

This is how my .gitignore looks like

*.pyc
*.~
*.swp
*.xml
*.iml 

I have added the pyc files in gitignore yet they are commited. What have I done wrong and how can I make a successful pull now?

Upvotes: 0

Views: 897

Answers (2)

M.Sharma
M.Sharma

Reputation: 224

If you add a file/ext/folder in .gitignore file, then push .gitignore file first. Git status will still show you those files as 'not staged' if your gitignore changes are not pushed. I suggest you delete those files from git remote and then add them locally. Now git should work properly and ignore those files.

more details Here

Upvotes: 0

lucash
lucash

Reputation: 2062

If the files have been committed before ignoring them, you will need to remove them from the repository to make the ignore effective. How to do that is described in this answer.

In your case the files are changed locally as well as in the remote repository. Assuming that these are compiled files which can be reproduced at any time by compiling your source code, I would suggest to do the following:

  • Restore the last committed version of the files (e.g. with git checkout -- filea fileb).
  • Pull changes from the remote repository.
  • Delete files as described in the answer linked above.

This will have the benefit to avoid conflicts in those files which are going to be deleted and ignored anyway.

Upvotes: 1

Related Questions