0

I committed everything. This is my git status

On branch frontend/leo/auth
Your branch is up to date with 'origin/frontend/leo/auth'.

nothing to commit, working tree clean

However, when I try to checkout dev branch, I get

error: Your local changes to the following files would be overwritten by checkout:
    frontend/package.json
Please commit your changes or stash them before you switch branches.
Aborting

What's happening here? Why would it ask me to commit when I committed everything?

Leonard
  • 2,978
  • 6
  • 21
  • 42

1 Answers1

0

The problem happened because I was deliberately not tracking package.json, following this answer, which turns out to be wrong.

Here in Git FAQ it says,

How do I ignore changes to a tracked file?

Git doesn’t provide a way to do this. The reason is that if Git needs to overwrite this file, such as during a checkout, it doesn’t know whether the changes to the file are precious and should be kept, or whether they are irrelevant and can safely be destroyed. Therefore, it has to take the safe route and always preserve them.

It’s tempting to try to use certain features of git update-index, namely the assume-unchanged and skip-worktree bits, but these don’t work properly for this purpose and shouldn’t be used this way.

Correct apporoach:

The correct approach seems to be the accepted and the most popular answer on that SO post.

Leonard
  • 2,978
  • 6
  • 21
  • 42