0

I am working with git a repository that has submodules. How can I checkout to a previous commit and update the submodules (only those that need rollback update) ? The intent of this is to save time on git submodule update --init --recursive.

Why is git submodule update not automatic on git checkout? does not answer the particular part of the question, which is to update the submodules that are not up to date with the previous commit and not to update the submodules that are up to date with the previous commit. git submodule update --init --recursive clones all the submodules and it is not the expected result.

KaHinCostner
  • 167
  • 3
  • 17
  • Possible duplicate of [Why is git submodule update not automatic on git checkout?](https://stackoverflow.com/questions/1899792/why-is-git-submodule-update-not-automatic-on-git-checkout) – Tim Henigan Oct 09 '19 at 16:41
  • 1
    Don't use `--init`, that's the part that tells it to do the clone. – jthill Oct 09 '19 at 17:46
  • @TimHenigan I updated my question. I didn't find an answer in your link – KaHinCostner Oct 09 '19 at 18:37

1 Answers1

1

Doesn't seem to me you can save much time here, submodule update to the already-checked-out commit is a plenty-fast no-op for me, but you could try whether

git checkout oldercommit

git submodule foreach -q '
        now=`git -C $toplevel rev-parse :$sm_path`
        test $now = `git rev-parse @` || git checkout $now
    '

runs noticeably faster for you.

jthill
  • 55,082
  • 5
  • 77
  • 137