error: Your local changes to the following files would be overwritten by checkout:

I do not make changes to any of the stable branches, yet randomly I get “… local changes …”

$ git branch
devel
stable-1.9

  • stable-2.0

$ git diff
diff --git a/lib/ansible/modules/core b/lib/ansible/modules/core
index de47e4d…93d0218 160000
— a/lib/ansible/modules/core
+++ b/lib/ansible/modules/core
@@ -1 +1 @@
-Subproject commit de47e4d81a0a91cea31b72f3f24cc459431a1846
+Subproject commit 93d02189f6dcfa0578a0fac0fb1f289369ac13a5-dirty

$ git submodule update --recursive
error: Your local changes to the following files would be overwritten by checkout:
utilities/helper/fireball.py
Please, commit your changes or stash them before you can switch branches.
Aborting
Unable to checkout ‘de47e4d81a0a91cea31b72f3f24cc459431a1846’ in submodule path ‘lib/ansible/modules/core’

I did not change this file.

Why does this happen?

I know how to “fix” it but I’d like to know what I’m doing wrong.

Thanks.

There are likely numerous situations that could lead to this, such as:

  1. running git pull --recurse-submodules
  2. running git pull while in the core or extras directories

There shouldn’t be a need to run those above commands, after doing a git pull in the main repo or a git fetch you should be able to just run git submodule update --recursive to update those submodules to the pointers/commits specified in the upstream repo.

I’m however unsure of the specific scenario that got you to a point where it appeared that fireball.py was modified. It could just be that you jumped commits between when fireball.py was there, and when it was removed, but done in a way that didn’t actually remove the file.

Happened again.

Here is the commands I use from inside the ansible directory.

$ pwd
/Users/tanner/projects/ansible.git/ansible

$ git pull --rebase ; git submodule update --recursive --init;

Current branch devel is up to date.
error: Your local changes to the following files would be overwritten by checkout:
cloud/docker/docker_image.py
Please, commit your changes or stash them before you can switch branches.
Aborting
Unable to checkout ‘e9454fa44f5ff507c0dad3ed91a866854287e4dc’ in submodule path ‘lib/ansible/modules/core’

$ git diff
diff --git a/lib/ansible/modules/core b/lib/ansible/modules/core
index e9454fa…8d126bd 160000
— a/lib/ansible/modules/core
+++ b/lib/ansible/modules/core
@@ -1 +1 @@
-Subproject commit e9454fa44f5ff507c0dad3ed91a866854287e4dc
+Subproject commit 8d126bd877444c9557b1671521516447cc557d3f-dirty