{"thread":{"id":"54080","subject":"git submodule status never says “old commits”","startedAt":"2020-08-21T12:15:10Z","lastAt":"2020-10-12T13:39:21Z","messageCount":3,"participants":["Ulrich HERRMANN","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"404134","messageId":"VE1PR10MB3374796F04367FA5DE25F921945B0@VE1PR10MB3374.EURPRD10.PROD.OUTLOOK.COM","threadId":"54080","inReplyTo":"VE1PR10MB33746C60D550BB11162F5E24945B0@VE1PR10MB3374.EURPRD10.PROD.OUTLOOK.COM","subject":"git submodule status never says “old commits”","fromName":"Ulrich HERRMANN","fromEmail":"ulrich.herrmann@st.com","sentAt":"2020-08-21T12:14:58Z","receivedAt":"2020-08-21T12:15:10Z","isPatch":false,"sender":{"key":"ulrich.herrmann@st.com","avatar":null},"body":"Hi all,\n\nI am now a user of git-submodules for quite some time. However I still haven’t figured out how to get better status/diff information. When the submodule is at a different version it always gives me \"new commits\" but never \"old commits\" even though I have checked out an older version inside the submodule. git diff gives me two different hashes which also don't give any directly readable information.  Git could check the ancestry graph to figure the relation of the two commits: child/parent, parent/child, common ancestor, etc.\nOr is there a feature / command line switch of git which I am missing?\n\nBest Regards, Ulrich\n"},{"id":"404247","messageId":"20200822015402.GY8085@camp.crustytoothpaste.net","threadId":"54080","inReplyTo":"VE1PR10MB3374796F04367FA5DE25F921945B0@VE1PR10MB3374.EURPRD10.PROD.OUTLOOK.COM","subject":"Re: git submodule status never says “old commits”","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-08-22T01:54:02Z","receivedAt":"2020-08-22T01:54:47Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-08-21 at 12:14:58, Ulrich HERRMANN wrote:\n> Hi all,\n> \n> I am now a user of git-submodules for quite some time. However I still\n> haven’t figured out how to get better status/diff information. When\n> the submodule is at a different version it always gives me \"new\n> commits\" but never \"old commits\" even though I have checked out an\n> older version inside the submodule. git diff gives me two different\n> hashes which also don't give any directly readable information.  Git\n> could check the ancestry graph to figure the relation of the two\n> commits: child/parent, parent/child, common ancestor, etc.\n> Or is there a feature / command line switch of git which I am missing?\n\nYou may be interested in the status.submoduleSummary option, which if\nenabled will show a summary of what's changed in the submodule.  If you\ndon't want to set that setting, the command \"git submodule summary\" can\nalso be used.\n\nFor git diff, there's the --submodule option, which can be used to\ncontrol what information is shown in the diff, and the diff.submodule\noption controls the default.\n\nAs for just knowing whether the revision checked out is ahead or behind\nthe committed revision, I don't think there's an option for that.  Most\nnotably, it need not be either: the two commits could be on two\ndifferent branches with some shared history or even on two commits that\ndon't share any history at all.  So there's not necessarily any answer\nthat's correct there at all.\n\nYou could script some of this with an alias or script by doing something\nlike this:\n\n  #!/bin/sh -e\n\n  # old value\n  A=$(git rev-parse --verify $1)\n  # new value\n  B=$(git rev-parse --verify $2)\n  MB=$(git merge-base $A $B || true)\n\n  if [ -z \"$MB\" ]\n  then\n    echo \"No common ancestors\"\n  elif [ \"$A\" = \"$MB\" ]\n  then\n    echo \"New commits\"\n  elif [ \"$B\" = \"$MB\" ]\n  then\n    echo \"Old commits\"\n  else\n    echo \"Common ancestor\"\n  fi\n-- \nbrian m. carlson: Houston, Texas, US\n"},{"id":"407335","messageId":"VE1PR10MB337438892373C3BA86D879D394070@VE1PR10MB3374.EURPRD10.PROD.OUTLOOK.COM","threadId":"54080","inReplyTo":"20200822015402.GY8085@camp.crustytoothpaste.net","subject":"RE: git submodule status never says “old commits”","fromName":"Ulrich HERRMANN","fromEmail":"ulrich.herrmann@st.com","sentAt":"2020-10-12T13:38:42Z","receivedAt":"2020-10-12T13:39:21Z","isPatch":false,"sender":{"key":"ulrich.herrmann@st.com","avatar":null},"body":"Hi Brian,\n\nthank you for this answer. I had missed the summary/--submodule option. They seem to be pretty usable.\n\nBest Regards, Ulrich\n\n-----Original Message-----\nFrom: brian m. carlson <sandals@crustytoothpaste.net> \nSent: Saturday, 22 August 2020 03:54\nTo: Ulrich HERRMANN <ulrich.herrmann@st.com>\nCc: git@vger.kernel.org\nSubject: Re: git submodule status never says “old commits”\n\nOn 2020-08-21 at 12:14:58, Ulrich HERRMANN wrote:\n> Hi all,\n> \n> I am now a user of git-submodules for quite some time. However I still \n> haven’t figured out how to get better status/diff information. When \n> the submodule is at a different version it always gives me \"new \n> commits\" but never \"old commits\" even though I have checked out an \n> older version inside the submodule. git diff gives me two different \n> hashes which also don't give any directly readable information.  Git \n> could check the ancestry graph to figure the relation of the two\n> commits: child/parent, parent/child, common ancestor, etc.\n> Or is there a feature / command line switch of git which I am missing?\n\nYou may be interested in the status.submoduleSummary option, which if enabled will show a summary of what's changed in the submodule.  If you don't want to set that setting, the command \"git submodule summary\" can also be used.\n\nFor git diff, there's the --submodule option, which can be used to control what information is shown in the diff, and the diff.submodule option controls the default.\n\nAs for just knowing whether the revision checked out is ahead or behind the committed revision, I don't think there's an option for that.  Most notably, it need not be either: the two commits could be on two different branches with some shared history or even on two commits that don't share any history at all.  So there's not necessarily any answer that's correct there at all.\n\nYou could script some of this with an alias or script by doing something like this:\n\n  #!/bin/sh -e\n\n  # old value\n  A=$(git rev-parse --verify $1)\n  # new value\n  B=$(git rev-parse --verify $2)\n  MB=$(git merge-base $A $B || true)\n\n  if [ -z \"$MB\" ]\n  then\n    echo \"No common ancestors\"\n  elif [ \"$A\" = \"$MB\" ]\n  then\n    echo \"New commits\"\n  elif [ \"$B\" = \"$MB\" ]\n  then\n    echo \"Old commits\"\n  else\n    echo \"Common ancestor\"\n  fi\n--\nbrian m. carlson: Houston, Texas, US\n"}]}