threads / bug / 52010

Possible bug in git stash with submodule.recurse

Subject: Possible bug in git stash with submodule.recurse

## tl;dr

One message between Oct 10, 2019 and Oct 10, 2019.

replies: 0people: 1as markdown or json

Jakob Jarmar· Oct 10, 2019, 15:26 UTC · lore
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

← back to recent threads