When I try to git pull in my branch, I get:
error: Your local changes to the following files would be overwritten by merge:
Vendor/JSONKit
Indeed, when I do a git status, it says Vendor/JSONKit is “modified”.
Vendor/JSONKit contains a third-party project called JSONKit (https://github.com/johnezang/JSONKit). I’ve never touched this code. I didn’t set up the folder, either — but I gather that it’s what’s called a “submodule”.
What is causing this error and how do I get past it? If I try to git stash, it claims I have “No local changes to save.” If I go into Vendor/JSONKit and try to do anything, git says I’m not on a branch anymore.
In a single repository:
You should be able to explore the diff with
git diff -- Vendor/JSONKit, but if you want to just reset the file (and abandon the changes), issue this command:That’ll checkout the most recent version of
Vendor/JSONKitin your working directory and abandon the modifications.In a repository with submodules:
Git submodules allow you to embed git repositories inside one another. Suppose “JSONKit” were a submodule inside “MyApp”. The top-level git repository,
MyApp, only tracks theHEADcommits ofJSONKit, so you can perfectly reconstruct bothMyApp‘s andJSONKit‘s states at any point in history.Suppose you committed changes inside the
JSONKitrepository. InsideJSONKit, this would look like a normal diff and have a normal history. Inside the parent repository,MyApp, it would register as a change to theHEADcommit. It might look something like this diff, taken from the git scm docs. The submodule in this example is a directory called “rack”.How does
MyAppknow which directories are submodules? It’s tracked inside the.gitmodulesfile.catit, and you’ll see every submodule registered inMyApp:When you issued
git submodule update, you told git to checkout the most recentHEADcommit forJSONKitin your parent repo’s index, thus abandoning the change in the submodule repository: