From: Laurence Tratt <laurie@tratt.net>
To: git@vger.kernel.org
Subject: recurse-submodules can remove local changes when switching branches?
Date: Mon, 25 May 2020 10:40:19 +0100 [thread overview]
Message-ID: <20200525094019.22padbzuk7ukr5uv@overdrive.tratt.net> (raw)
If one creates a new repository, makes a new branch, adds a submodule, makes
local changes to that submodule, then switches to another branch, it seems
that git can silently remove those local changes.
Here's an example (the repositories involved are irrelevant other than
they're small!):
$ git clone https://github.com/ltratt/supuner/
$ cd supuner
$ git submodule add https://github.com/ltratt/extsmail extsmail
$ git checkout --recurse-submodules -b b
$ git commit -m "add submodule" .
At this point make a local change to extsmail/README.md and confirm that
git has noticed that something in the submodule has changed:
$ git status
On branch b
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: extsmail (modified content)
no changes added to commit (use "git add" and/or "git commit -a")
then change branch (in the supuner repository, not extsmail!):
$ git checkout --recurse-submodules master
The switch of branch succeeds without warning me that I have changes in my
submodule. But then:
$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
My local changes to the submodule have disappeared entirely.
Switching back to `b` does not restore my changes:
$ git checkout --recurse-submodules b
On branch b
nothing to commit, working tree clean
This happens on 2.26.2 and the current master. AFAICS this only happens
because the master branch does not yet have the submodule registered in it.
If it does, "checkout --recurse-submodules" maintains my local changes in
the submodule across the branch switch.
Laurie
--
Personal http://tratt.net/laurie/
Software Development Team http://soft-dev.org/
https://github.com/ltratt http://twitter.com/laurencetratt
next reply other threads:[~2020-05-25 9:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-25 9:40 Laurence Tratt [this message]
2020-05-25 17:28 ` recurse-submodules can remove local changes when switching branches? Philippe Blain
2020-05-25 22:09 ` Laurence Tratt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200525094019.22padbzuk7ukr5uv@overdrive.tratt.net \
--to=laurie@tratt.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).