Good news, I've been working an adding file content hashing to Ninja: https://github.com/ninja-build/ninja/pull/2735
That will fix the "switch branches back and forward" case :)