git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git checkout --recurse-submodules deletes local modifications

From
SESimon Etter <simon0etter@gmail.com>
Date
Dec 6, 2023, 07:16 UTC
Message-ID
<CAFy4k4JpyqWCDH48YZJ6wc6nhtUq7J43ZHwg8-LDTQfDMsMqSg@mail.gmail.com>
Hi there!

It seems git checkout --recurse-submodules doesn't live up to its documentation. According to the docs:

> If local modifications in a submodule would be overwritten the checkout will fail unless -f is used.

Here's an MWE where git checkout --recurse-submodules does overwrite local modifications:

``` # Prepare repo rm -rf /tmp/test mkdir /tmp/test cd /tmp/test git init git submodule add git@github.com:octocat/Hello-World.git git commit -m "Add submodule" git checkout -b other cd Hello-World git checkout 762941318ee16e59dabbacb1b4049eec22f0d303 cd .. git add Hello-World git commit -m "Change submodule commit"

# Add local modification echo boo! > Hello-World/README

# Switch branches. This completes without error, and deletes the change introduced in the previous line. git checkout main --recurse-submodules ```

I believe part of the problem is that 762941318ee16e59dabbacb1b4049eec22f0d303 and 7fd1a60b01f91b314f59955a4e4d4e80d8edf11d (the Hello-World master commit) are the same; the last line does report an error if I make `other` point at 553c2077f0edc3d5dc5d17262f6aa498e69d6f8e instead of the above commit. However, I don't think this changes the fact that the above MWE makes git checkout --recurse-submodules look pretty dangerous.

I'd love to hear if
1) the above is intended behavior,
2) I'm doing something wrong, or
3) this is a bug.

Best regards, and thanks for all your hard work, Simon

Message 1 of 1 in “git checkout --recurse-submodules deletes local modifications”
  1. Simon EtterDec 6, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.