{"thread":{"id":"53541","subject":"recurse-submodules can remove local changes when switching branches?","startedAt":"2020-05-25T09:46:12Z","lastAt":"2020-05-25T22:09:49Z","messageCount":3,"participants":["Laurence Tratt","Philippe Blain"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"398483","messageId":"20200525094019.22padbzuk7ukr5uv@overdrive.tratt.net","threadId":"53541","inReplyTo":null,"subject":"recurse-submodules can remove local changes when switching branches?","fromName":"Laurence Tratt","fromEmail":"laurie@tratt.net","sentAt":"2020-05-25T09:40:19Z","receivedAt":"2020-05-25T09:46:12Z","isPatch":false,"sender":{"key":"laurie@tratt.net","avatar":null},"body":"If one creates a new repository, makes a new branch, adds a submodule, makes\nlocal changes to that submodule, then switches to another branch, it seems\nthat git can silently remove those local changes.\n\nHere's an example (the repositories involved are irrelevant other than\nthey're small!):\n\n  $ git clone https://github.com/ltratt/supuner/\n  $ cd supuner\n  $ git submodule add https://github.com/ltratt/extsmail extsmail\n  $ git checkout --recurse-submodules -b b\n  $ git commit -m \"add submodule\" .\n\nAt this point make a local change to extsmail/README.md and confirm that\ngit has noticed that something in the submodule has changed:\n\n  $ git status\n  On branch b\n  Changes not staged for commit:\n    (use \"git add <file>...\" to update what will be committed)\n    (use \"git restore <file>...\" to discard changes in working directory)\n    (commit or discard the untracked or modified content in submodules)\n          modified:   extsmail (modified content)\n\n  no changes added to commit (use \"git add\" and/or \"git commit -a\")\n\nthen change branch (in the supuner repository, not extsmail!):\n\n  $ git checkout --recurse-submodules master\n\nThe switch of branch succeeds without warning me that I have changes in my\nsubmodule. But then:\n\n  $ git status\n  On branch master\n  Your branch is up to date with 'origin/master'.\n\n  nothing to commit, working tree clean\n\nMy local changes to the submodule have disappeared entirely.\n\nSwitching back to `b` does not restore my changes:\n\n  $ git checkout --recurse-submodules b\n  On branch b\n  nothing to commit, working tree clean\n\nThis happens on 2.26.2 and the current master. AFAICS this only happens\nbecause the master branch does not yet have the submodule registered in it.\nIf it does, \"checkout --recurse-submodules\" maintains my local changes in\nthe submodule across the branch switch.\n\n\nLaurie\n-- \nPersonal                                             http://tratt.net/laurie/\nSoftware Development Team                                http://soft-dev.org/\n   https://github.com/ltratt              http://twitter.com/laurencetratt\n\n"},{"id":"398497","messageId":"1788146A-420A-41F9-A286-165F574089BD@gmail.com","threadId":"53541","inReplyTo":"20200525094019.22padbzuk7ukr5uv@overdrive.tratt.net","subject":"Re: recurse-submodules can remove local changes when switching branches?","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2020-05-25T17:28:24Z","receivedAt":"2020-05-25T17:28:30Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Laurence,\n\n> Le 25 mai 2020 à 05:40, Laurence Tratt <laurie@tratt.net> a écrit :\n> \n> If one creates a new repository, makes a new branch, adds a submodule, makes\n> local changes to that submodule, then switches to another branch, it seems\n> that git can silently remove those local changes.\n> \n> Here's an example (the repositories involved are irrelevant other than\n> they're small!):\n> \n>  $ git clone https://github.com/ltratt/supuner/\n>  $ cd supuner\n>  $ git submodule add https://github.com/ltratt/extsmail extsmail\n>  $ git checkout --recurse-submodules -b b\n>  $ git commit -m \"add submodule\" .\n> \n> At this point make a local change to extsmail/README.md and confirm that\n> git has noticed that something in the submodule has changed:\n> \n>  $ git status\n>  On branch b\n>  Changes not staged for commit:\n>    (use \"git add <file>...\" to update what will be committed)\n>    (use \"git restore <file>...\" to discard changes in working directory)\n>    (commit or discard the untracked or modified content in submodules)\n>          modified:   extsmail (modified content)\n> \n>  no changes added to commit (use \"git add\" and/or \"git commit -a\")\n> \n> then change branch (in the supuner repository, not extsmail!):\n> \n>  $ git checkout --recurse-submodules master\n> \n> The switch of branch succeeds without warning me that I have changes in my\n> submodule. But then:\n> \n>  $ git status\n>  On branch master\n>  Your branch is up to date with 'origin/master'.\n> \n>  nothing to commit, working tree clean\n> \n> My local changes to the submodule have disappeared entirely.\n\nI believe this is the same bug that was reported in 2018 here:\nhttps://lore.kernel.org/git/CAHsG2VT4YB_nf8PrEmrHwK-iY-AQo0VDcvXGVsf8cEYXws4nig@mail.gmail.com/\n\n> \n> Switching back to `b` does not restore my changes:\n> \n>  $ git checkout --recurse-submodules b\n>  On branch b\n>  nothing to commit, working tree clean\n> \n> This happens on 2.26.2 and the current master. AFAICS this only happens\n> because the master branch does not yet have the submodule registered in it.\n> If it does, \"checkout --recurse-submodules\" maintains my local changes in\n> the submodule across the branch switch.\n\nThanks, this information should be useful for debugging.\n\nPhilippe."},{"id":"398563","messageId":"20200525220946.kau2d3etavf2qsso@overdrive.tratt.net","threadId":"53541","inReplyTo":"1788146A-420A-41F9-A286-165F574089BD@gmail.com","subject":"Re: recurse-submodules can remove local changes when switching branches?","fromName":"Laurence Tratt","fromEmail":"laurie@tratt.net","sentAt":"2020-05-25T22:09:46Z","receivedAt":"2020-05-25T22:09:49Z","isPatch":false,"sender":{"key":"laurie@tratt.net","avatar":null},"body":"On Mon, May 25, 2020 at 01:28:24PM -0400, Philippe Blain wrote:\n\nHello Philippe,\n\n> I believe this is the same bug that was reported in 2018 here:\n> https://lore.kernel.org/git/CAHsG2VT4YB_nf8PrEmrHwK-iY-AQo0VDcvXGVsf8cEYXws4nig@mail.gmail.com/\n\nYes, I agree!\n\n\nLaurie\n"}]}