git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Atharva Raykar <raykar.ath@gmail.com>
To: Rostislav Krasny <rosti.bsd@gmail.com>
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>, git@vger.kernel.org
Subject: Why do submodules detach HEAD? (was Re: Incorrect and inconsistent End-Of-Line characters in .gitmodules ...)
Date: Wed, 21 Jul 2021 12:56:14 +0530	[thread overview]
Message-ID: <46F5B91F-4DBE-4F34-9395-7CC808FAC359@gmail.com> (raw)
In-Reply-To: <CANt7McHrYhSe3JsS8UKX8NgsUajwxQY4h9KTtXkEXdd0Be_+yw@mail.gmail.com>

On 18-Jul-2021, at 02:52, Rostislav Krasny <rosti.bsd@gmail.com> wrote:
> 
> 
> [...]
> I would like to take this opportunity to ask: why cloning a repository
> that contains submodules sets this repository branch to its default
> (master, main, whatever) but all submodules are set into a detached
> HEAD mode instead of their default branches? This is actually the
> reason I started to check what happens with the .gitmodules file. What
> is the point in such an inconsistent behavior? There are a lot of
> questions about that in Google and it seems most of the users expect
> different behavior.

Submodules are cloned along with the parent repository only when
'submodule.recurse' is set to true, which I assume is the case for
your configuration.

A git clone that recurses submodules is equivalent to running
'git submodule update --init --recursive' right after the parent
project has been cloned.

The default mode for the update command is to checkout to the
revision that the parent project expects the submodule to be in, ie,
it checks out to the commit hash directly, and detaches the HEAD.

Why not checkout to a branch? This is because branches may change
which commits they point to.

For example, if you had a submodule 'foo'. I go into the 'foo'
folder and amend the last commit.

Now if I run 'submodule update' in the parent repository. If it had
checked out to the branch instead of the revision, I would be on a
different commit in 'foo' than the one that was registered by the
parent repo!

We want to have idempotence, ie, for a particular revision that is
registered by our parent project, we want 'update' to give the same
outcome every time, and not be dependent on whatever the state of the
branch is. This way we ensure that for a particular commit in the
parent project, the submodules will be in the same state for every
system in the world, after an 'update' is run.

I hope that makes sense.

(Anyone more knowledgeable than me in submodules, feel free to add
to what I am saying and correct me if I made an error!)

---
Atharva Raykar
ಅಥರ್ವ ರಾಯ್ಕರ್
अथर्व रायकर


  reply	other threads:[~2021-07-21  7:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15 21:55 Incorrect and inconsistent End-Of-Line characters in .gitmodules after "git submodule set-branch --branch <branch_name>" Rostislav Krasny
2021-07-16 19:38 ` brian m. carlson
2021-07-17 21:22   ` Rostislav Krasny
2021-07-21  7:26     ` Atharva Raykar [this message]
2021-07-21 22:42       ` Why do submodules detach HEAD? (was Re: Incorrect and inconsistent End-Of-Line characters in .gitmodules ...) Philippe Blain
2021-08-05 13:59       ` Rostislav Krasny
2021-08-05 18:38         ` Atharva Raykar
2021-07-17 17:05 ` Incorrect and inconsistent End-Of-Line characters in .gitmodules after "git submodule set-branch --branch <branch_name>" Torsten =?unknown-8bit?Q?B=C3=B6gershausen?=
2021-07-17 22:42   ` Rostislav Krasny
2021-07-18  5:32     ` Torsten =?unknown-8bit?Q?B=C3=B6gershausen?=

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=46F5B91F-4DBE-4F34-9395-7CC808FAC359@gmail.com \
    --to=raykar.ath@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=rosti.bsd@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    /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).