{"thread":{"id":"60585","subject":"git checkout --recurse-submodules deletes local modifications","startedAt":"2023-12-06T07:16:23Z","lastAt":"2023-12-06T07:16:23Z","messageCount":1,"participants":["Simon Etter"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"485361","messageId":"CAFy4k4JpyqWCDH48YZJ6wc6nhtUq7J43ZHwg8-LDTQfDMsMqSg@mail.gmail.com","threadId":"60585","inReplyTo":null,"subject":"git checkout --recurse-submodules deletes local modifications","fromName":"Simon Etter","fromEmail":"simon0etter@gmail.com","sentAt":"2023-12-06T07:16:12Z","receivedAt":"2023-12-06T07:16:23Z","isPatch":false,"sender":{"key":"simon0etter@gmail.com","avatar":null},"body":"Hi there!\n\nIt seems git checkout --recurse-submodules doesn't live up to its\ndocumentation. According to the docs:\n\n> If local modifications in a submodule would be overwritten the checkout will fail unless -f is used.\n\nHere's an MWE where git checkout --recurse-submodules does overwrite\nlocal modifications:\n\n```\n# Prepare repo\nrm -rf /tmp/test\nmkdir /tmp/test\ncd /tmp/test\ngit init\ngit submodule add git@github.com:octocat/Hello-World.git\ngit commit -m \"Add submodule\"\ngit checkout -b other\ncd Hello-World\ngit checkout 762941318ee16e59dabbacb1b4049eec22f0d303\ncd ..\ngit add Hello-World\ngit commit -m \"Change submodule commit\"\n\n# Add local modification\necho boo! > Hello-World/README\n\n# Switch branches. This completes without error, and deletes the\nchange introduced in the previous line.\ngit checkout main --recurse-submodules\n```\n\nI believe part of the problem is that\n762941318ee16e59dabbacb1b4049eec22f0d303 and\n7fd1a60b01f91b314f59955a4e4d4e80d8edf11d (the Hello-World master\ncommit) are the same; the last line does report an error if I make\n`other` point at 553c2077f0edc3d5dc5d17262f6aa498e69d6f8e instead of\nthe above commit. However, I don't think this changes the fact that\nthe above MWE makes git checkout --recurse-submodules look pretty\ndangerous.\n\nI'd love to hear if\n\n1) the above is intended behavior,\n2) I'm doing something wrong, or\n3) this is a bug.\n\nBest regards, and thanks for all your hard work,\nSimon\n"}]}