1

I've got a library checked out as a git submodule in my project and I often make changes in the lib. Every time I commit that change the subsequent git status in the parent repo shows that the submodule has changed. I also use __git_ps1 and so the parent dir prompt shows that there are uncommitted changes.

parent-project (master *) $ git diff
diff --git a/my-submodule b/my-submodule
index 5eb2e9f..fd40630 160000
--- a/my-submodule
+++ b/my-submodule
@@ -1 +1 @@
-Subproject commit 5eb2e9fdcb85ab5a1f57e622b17cc76e5af749b7
+Subproject commit fd406308851b5521980f4578960c428200c66371

I know of two options:

  1. git commit submodule from the parent which creates unnecessary commits, or
  2. remove and re-add the submodule which seems like an overkill.

Is there any way to tell the parent repo Update the submodule ref to the latest master and move on? I don't want to refer to a specific git revision, just to the head of master or whatever branch I choose.

Thanks!

I-P-X
  • 113
  • 5
  • *I often make changes in the lib* is the lib had to be tracked? if not, perhaps using gitignore can help. – Bagus Tesa Oct 02 '19 at 03:41
  • @BagusTesa Hmm, that doesn't seem to help, just tried. First `git submodule add` complains that it's in `.gitignore`, but that can be forced. But even then the submodule commits still make the parent project dirty :( – I-P-X Oct 02 '19 at 03:54

1 Answers1

4

Is there any way to tell the parent repo Update the submodule ref to the latest master

Yes, with the --remote option:

git submodule update --remote

and move on?

Well,... that would still change the submodule SHA1 tree, so you would still need to make a commit, but you can make said commit whenever you have made your own changes in the parent repository.

Maybe locally you could ignore that with:

cd /parent/repo
git update-index --assume-unchanged -- submoduleFolder # no trailing slash
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • *you would still need to make a commit* .. that's what I'd like to avoid. Instead of referring to a particular submodule commit id I'd like to refer to the submodule's master. Or ignore any changes in the submodule sha id (unfortunately `.gitignore` doesn't seem to help here). – I-P-X Oct 02 '19 at 04:41
  • @I-P-X See "True anture oof submodules": https://stackoverflow.com/a/1979194/6309. A submodule is *always* a SHA1 reference plus a remote URL. I have included in the answer a way to ignore it locally. – VonC Oct 02 '19 at 04:43
  • Thanks, `git update-index --assume-unchanged` seems to do the trick :) – I-P-X Oct 06 '19 at 23:38