From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 4272D1F4B4 for ; Sun, 20 Sep 2020 20:52:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726475AbgITUwf (ORCPT ); Sun, 20 Sep 2020 16:52:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgITUwe (ORCPT ); Sun, 20 Sep 2020 16:52:34 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90AF7C061755 for ; Sun, 20 Sep 2020 13:52:34 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id x14so10663962wrl.12 for ; Sun, 20 Sep 2020 13:52:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diamand.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uDaM/DkzTg39L+jSbmZNJggS9EYB+Zdj+Dq81AymA0w=; b=ahpQ5nAVZQQXxHQEjmcRJm4r76nCxoO2hD+ZrVdkO4aoLGvlR7k/XRAXg/Bsc2AW8D GuqUAlKCsSNu6UuRXJA9LSyCmrYhkqjdu6hbx9P1o7wvBAxazcApdRWmH9piLzIEnXtO t6N8XpLWBBf1UozgRL3ZMSDqSr6RwpMc6XeZI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uDaM/DkzTg39L+jSbmZNJggS9EYB+Zdj+Dq81AymA0w=; b=Y2Fw043hsFkiqagCG3ZbdVno98NjQ4K6D6iNXq5H4u6lYrqH2pcrCIE9HCVBIfPlfk h0AKzT9FZah8kcMv5gty10HB4PnH6YRXsGsp/v57soTW3VnDc3rH7bekLm6XQm77Ixk9 dNToCI+Vmq8f1+sI+3jSI7tq1SSt/Akng/zwczw55JJRJJ/OORUmTQ2qKnhLnvH+RmDF qwFlBNKxAXZusJ8MU2khRgiknrBj3ofr7xQvP7oJ6+MX4rPf+K28psLonDTWHXu5Kyy+ 18NpwJIzFskIr+T26oXr/uxA0PpG2j4cFQ0m0K4EX4AIB2dr3xmzzkxNjYL0NtsWwXbo CWJw== X-Gm-Message-State: AOAM533jYinK1+ET75Nj3ESe+NhTv4wcD75CUoQwU/BharFqtOVaHIto tNydMBxGHwSMKS7Fzp4lo/flS0+BzKmQOuD/F7UkZg== X-Google-Smtp-Source: ABdhPJzGELJrP9w4eMNpUN/wNnQ3jcc8ht6TJmM2VChvwIxALUWjF7dLHfQ0AVERkDUkIwBf6NhVZBqp57XVBMgNUAA= X-Received: by 2002:a5d:6912:: with SMTP id t18mr51576030wru.326.1600635153198; Sun, 20 Sep 2020 13:52:33 -0700 (PDT) MIME-Version: 1.0 References: <4eb688f2-0c17-9b85-e60e-f07485895622@gmail.com> In-Reply-To: <4eb688f2-0c17-9b85-e60e-f07485895622@gmail.com> From: Luke Diamand Date: Sun, 20 Sep 2020 21:52:22 +0100 Message-ID: Subject: Re: How to checkout a revision that contains a deleted submodule? To: Kaartic Sivaraam Cc: Git Users , Jens Lehmann Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Sun, 20 Sep 2020 at 19:02, Kaartic Sivaraam wrote: > > On 20/09/20 3:14 pm, Luke Diamand wrote: > > On Sat, 19 Sep 2020 at 10:03, Luke Diamand wrote: > >> > >> Maybe this is a FAQ, but I couldn't figure it out! > >> > >> I have a repo which has a couple of submodules. > >> > >> At some point in the past I deleted one of those submodules: > >> > >> git rm sub2 > >> git add -u > >> git commit -m 'Deleting sub2' > >> git push origin > >> ... > >> ... more commits and pushes... > >> > >> Now I go and clone the head revision. This gives me a clone which has > >> nothing present in .git/modules/sub2. > >> login on some other machine > >> git clone git@my.repo:thing > >> cd thing > >> ls .git/modules > >> > >> > >> So when I go and checkout an old revision where sub2 is still around I get: > >> git checkout oldrevision > >> fatal: not a git repository: sub2/../.git/modules/sub2 > >> > >> What am I doing wrong? > >> What set of commands do I need to use to ensure that this will always > >> do the right thing? > >> > >> Thanks > >> Luke > > > > Replying to myself, adding Jens who added the section below. > > > > This is a known bug: > > > > https://git-scm.com/docs/git-rm > > > >> BUGS > >> ---- > >> Each time a superproject update removes a populated submodule > >> (e.g. when switching between commits before and after the removal) a > >> stale submodule checkout will remain in the old location. Removing the > >> old directory is only safe when it uses a gitfile, as otherwise the > >> history of the submodule will be deleted too. This step will be > >> obsolete when recursive submodule update has been implemented. > > > > I don't think that part of the documentation applies to your case. So, > I also don't think this is a known bug. As a matter of fact, I couldn't > reproduce this with the following: > > > git init checkout-removed-submodule && > cd checkout-removed-submodule/ && > echo "Hello, world" >foo && > git add foo && git commit -m "Initial commit" && > git init ../submodule && > cd ../submodule/ && > echo "Foo bar" >foobar.txt && > git add foobar.txt && git commit -m "Foo bar baz" && > cd ../checkout-removed-submodule/ && > git submodule add ../submodule/ foobar && > git commit -m "Add foobar submodule" && > git rm foobar/ && > git commit -m "Remove foobar submodule" && > git checkout HEAD~ # Checking out the "Add foobar submodule" commit > > I get: > > HEAD is now at 25270d8 Add foobar submodule > > > I also tried with a cloned version of that repository as follows: > git clone /me/checkout-removed-submodule/ cloned-repo && > cd cloned-repo && > git co HEAD~ > > I get: > > HEAD is now at 25270d8 Add foobar submodule > > So, I don't get any errors when I checkout a revision where the deleted > submodule is still around. There might other factors in play such as, > > - the version of Git being used > - whether `--recurse-submodules` was passed to checkout > - the configuration of the submodule in .gitmodules > > It would be great if you could share these and possibly other useful > information to help us identify why you get an error when checking out > the revision. Thanks for taking the time to answer! I will see if I can come up with a test case. Luke