git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jens Lehmann <Jens.Lehmann@web.de>
To: Shane da Silva <shane@dasilva.io>, git@vger.kernel.org
Subject: Re: Why can't I stash submodule changes?
Date: Mon, 06 Apr 2015 19:58:03 +0200	[thread overview]
Message-ID: <5522C92B.6090700@web.de> (raw)
In-Reply-To: <CAAKwDd8SVA=ynzH_U1M3bb+mLZMnF79-imBLrU+x9qcbXfWO3g@mail.gmail.com>

Am 06.04.2015 um 04:15 schrieb Shane da Silva:
> I’m having trouble understanding why I cannot stash changes to a submodule.
>
> When adding a submodule to a repository (`git submodule add
> ./sub-repo`), I can then run `git stash` and `git stash pop` with
> expected results—the submodule disappears and reappears in the working
> tree.

Just to be sure: Only the index of the superproject and the .gitmodules
file are updated by stash to either contain the submodule or not. But
the subdirectory "sub-repo" stays unchanged and won't be removed or
reappear, right?

> However, when I try stashing an update to a submodule, `git stash`
> reports “No local changes to save”. The following shell script
> illustrates this behavior:
>
>
> # Create repo
> mkdir test-repo
> cd test-repo
> git init
> git commit --allow-empty -m "Initial commit"
>
> # Create submodule
> mkdir sub-repo
> cd sub-repo
> git init
> git commit --allow-empty -m "Initial commit"
> cd -
>
> # Add submodule
> git submodule add ./sub-repo
> git commit -m "Add submodule"
>
> # Modify submodule
> cd sub-repo
> touch foo
> git add foo
> git commit -m "Submodule changed"
> cd -
>
> # Stash submodule change
> git stash # <---------------------------Displays "No local changes to save”

Thanks for providing a recipe to reproduce this!

> I’m trying to wrap my head around why this is the current behavior, as
> I suspect this is intentional but it seems unexpected. If anyone can
> shed any light on this, I would really appreciate it!

The current behavior of git is that submodule contents aren't updated
when the superproject changes. Running "git submodule update" later
will then update their content to most submodule changes (but e.g. it
won't remove a deleted submodule from the work tree). So yes, this is
expected until recursive submodule update materializes (and even then
I'm not sure how to handle untracked but not ignored files inside a
submodule when stashing will result in the submodule directory to be
removed).

  parent reply	other threads:[~2015-04-06 17:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-06  2:15 Why can't I stash submodule changes? Shane da Silva
2015-04-06 15:14 ` Phillip Susi
2015-04-06 17:58 ` Jens Lehmann [this message]
2015-04-07  5:19   ` Shane da Silva

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5522C92B.6090700@web.de \
    --to=jens.lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=shane@dasilva.io \
    /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.
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 NNTP newsgroup(s).