0

For example, if I want to change a branch git checkout testing (from dev), I'll get this warning:

error: Your local changes to the following files would be overwritten by checkout:
        app/src/api/server.js

But as you can see, the file is being ignored:

enter image description here

Why is this happening?

alex
  • 7,111
  • 15
  • 50
  • 77
  • 1
    But (a) I *can't* see that the file is being ignored, and (b) clearly, it's *not* being ignored. (If the right hand pane of your image is meant to show the contents of `.gitignore`, note that a file that is actually in the index is tracked, regardless of whether it appears in `.gitignore`.) – torek Sep 21 '16 at 03:30

1 Answers1

2

It seems that the file was being tracked before so you need to explicitly remove it once, by this command:

git rm --cached <file>

This is related to this topic: How to make Git "forget" about a file that was tracked but is now in .gitignore?

Community
  • 1
  • 1
afsafzal
  • 592
  • 5
  • 15
  • Do I need to do git commit after the code you provided me? – alex Sep 21 '16 at 03:35
  • Yes. If you want to see the effect immediately you need to commit. – afsafzal Sep 21 '16 at 03:36
  • @alex could you please close this question by accepting the answer? (if the answer worked! :) ) – afsafzal Sep 21 '16 at 03:46
  • is the file supposed to have its own version between branches? or the file will be the same for all branches? – alex Sep 21 '16 at 03:50
  • It will have several versions among branches. So I guess you need to remove it from all branches. or remove it once in a commit and then merge that commit in all branches. – afsafzal Sep 21 '16 at 03:58