xcodeswift-package-manager

Package.resolved gets deleted on branch switching


Sometimes after executing git checkout branch or git reset another-branch (while Xcode is open) I find out that the Package.resolved file gets mysteriously deleted. I can easily restore it from git or just recreate it from Xcode, but it gets annoying. It seems like Xcode itself deletes it. Any idea why it happens and how to fix it?


Solution

  • Don't switch branches or reset or anything like that with Xcode open. Just don't do it. You can make Xcode very unhappy and Weird Stuff (tm, pat. pend.) can result. Xcode's Git integration is extremely poor, and changing stuff on disk (like wit git switch, checkout, or reset) while Xcode has things open just confuses the heck out of Xcode. This is true even if you ordered those changes by way of the Xcode interface!

    Instead, simply close the project window, switch branches using the command line, and then open the project window. Then wait while Xcode indexes afresh, and so forth. Yes, this can take a long time. Go get a cup of coffee or something.

    One of the things Xcode will do during this preparation after you open the project window is to reconstruct the Packages.resolved file. So this should solve the issue.