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

Possible bug in git stash with submodule.recurse

From
Jakob Jarmar <jakob.j@gmail.com>
Date
Oct 10, 2019, 15:26 UTC
Message-ID
<CA+xNDHseTCoD+7Vbb4AG0kt9itXn0Z1Kto0vDjF9bBn+Fuk3TA@mail.gmail.com>
Hi,

I ran into an issue where git stash seems to be losing modified content from submodules without warning, if submodule.recurse is true. See below for an example:

1. enable submodule.recurse:
~ $ git config --global submodule.recurse true
2. create the repo to be used as a submodule:
~ $ git init sub
Initialized empty Git repository in /home/jakob/sub/.git/
~ $ cd sub/
~/sub $ touch sub.txt
~/sub $ git add sub.txt
~/sub $ git commit -m initial
[master (root-commit) 651a90c] initial
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 sub.txt
~/sub $ cd ..
3. create the main repo, add sub as a submodule:
~ $ git init main
Initialized empty Git repository in /home/jakob/main/.git/
~ $ cd main/
~/main $ touch main.txt
~/main $ git add main.txt
~/main $ git submodule add ../sub/
Cloning into '/home/jakob/main/sub'...
done.
~/main $ git commit -m initial
[master (root-commit) 2f9f4e8] initial
 3 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 100644 main.txt
 create mode 160000 sub
4. make *both* main and sub dirty (if main is clean, stash does nothing):

~/main $ echo changes > main.txt ~/main $ echo changes > sub/sub.txt ~/main $ git diff sub/ Submodule sub contains modified content

5. git stash and git stash pop:
~/main $ git stash
Saved working directory and index state WIP on master: 2f9f4e8 initial
~/main $ git stash pop
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
    modified:   main.txt

no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (00a38b73407e7e3041c9459ef6d61bc90940b91f) ~/main $ git diff sub/ ~/main $

At this point, I can't seem to find any way to retrieve the changes made to sub/sub.txt.

Thanks, Jakob

Message 1 of 1 in “Possible bug in git stash with submodule.recurse”
  1. Jakob JarmarOct 10, 2019

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.