{"thread":{"id":"61035","subject":"Support with finding git objects","startedAt":"2024-03-01T19:06:32Z","lastAt":"2024-03-04T10:43:48Z","messageCount":2,"participants":["Ayoub, Toufic","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"489756","messageId":"AMXP122MB01810E9B1195953D9AD0C8C48E5E2@AMXP122MB0181.EURP122.PROD.OUTLOOK.COM","threadId":"61035","inReplyTo":null,"subject":"Support with finding git objects","fromName":"Ayoub, Toufic","fromEmail":"toufic.ayoub@philips.com","sentAt":"2024-03-01T19:06:29Z","receivedAt":"2024-03-01T19:06:32Z","isPatch":false,"sender":{"key":"toufic.ayoub@philips.com","avatar":null},"body":"Hello everyone,\n\nHope this message finds you. I need your support regarding an issue my team is facing.\nWe have a code in our SW which shall display the date of the git commit. There is a path in the code that if it is executed on a platform where git is not installed, that this commit date shall be found by looking at:\n1.      Reading from HEAD file the commit hash\n2.      Searching for this commit hash under .git/objects\nThe problem we are facing is that sometimes, when the default master branch is updated with the newest commit, this commit will not be found locally, even after doing git pull and so on...\nThe commit can be found with:\n1.      git log\n2.      git cat-file -t <commit hash> -> it returns \"commit\"\n3.      git reflog\n\nbut the strange thing is that we can neither find it under .git/objects/ nor under .git/objects/pack (although that is the newest commit and shall not be packed).\n\nCan you please provide support by:\n1.      telling me it that is an issue or is it expected?\n2.      If that is expected, where shall we find this commit object to retrieve the commit message and date from it (without running git commands)?\n3.      Or recommending me some other solution\n\nI would appreciate that.\n\nBest regards,\n\nToufic Ayoub\nSoftware Developer\nHemodynamic Algorithms\nHospital Patient Monitoring\nPhilips\n\nPhilips Medizin Systeme Böblingen GmbH, Hewlett-Packard-Strasse 2, 71034 Boeblingen, Germany\nEmail toufic.ayoub@philips.com |www.philips.com/healthcare\nGeschäftsführer: Dr. Dieter Haase (Sprecher), Günter Gegner, Sang Do Kim, Florian Kuhn\nRegistergericht Stuttgart Reg.-Nr. HRB 245187, Sitz der Gesellschaft: Böblingen\n\nSimply switch to printing double-sided and printing less.\n\n\n\n________________________________\nThe information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.\n"},{"id":"489870","messageId":"ZeWjnaZ64DvTRldM@tapette.crustytoothpaste.net","threadId":"61035","inReplyTo":"AMXP122MB01810E9B1195953D9AD0C8C48E5E2@AMXP122MB0181.EURP122.PROD.OUTLOOK.COM","subject":"Re: Support with finding git objects","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2024-03-04T10:34:05Z","receivedAt":"2024-03-04T10:43:48Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2024-03-01 at 19:06:29, Ayoub, Toufic wrote:\n> Hello everyone,\n\nHey,\n\n> Hope this message finds you. I need your support regarding an issue my team is facing.\n> We have a code in our SW which shall display the date of the git commit. There is a path in the code that if it is executed on a platform where git is not installed, that this commit date shall be found by looking at:\n> 1.      Reading from HEAD file the commit hash\n> 2.      Searching for this commit hash under .git/objects\n> The problem we are facing is that sometimes, when the default master branch is updated with the newest commit, this commit will not be found locally, even after doing git pull and so on...\n> The commit can be found with:\n> 1.      git log\n> 2.      git cat-file -t <commit hash> -> it returns \"commit\"\n> 3.      git reflog\n> \n> but the strange thing is that we can neither find it under .git/objects/ nor under .git/objects/pack (although that is the newest commit and shall not be packed).\n\nI think you're maybe making some assumptions about when loose objects\nare and are not created that Git doesn't guarantee.  For example, if\nyou're doing a `git pull` or `git fetch`, it is entirely possible that\nthe objects downloaded remain in a pack.  In fact, by default, Git will\nleave large fetches as packs to avoid an explosion of loose objects.\n\nNote that the name of a pack is based on the hash of the entire pack\ncontents, not based on the items it contains (although obviously those\ninfluence the pack contents).\n\n> Can you please provide support by:\n> 1.      telling me it that is an issue or is it expected?\n\nI believe this is expected.\n\n> 2.      If that is expected, where shall we find this commit object to retrieve the commit message and date from it (without running git commands)?\n\nSorry, but you're going to need to use Git commands to do this.  You\ncould also use libgit2, but that doesn't work with SHA-256 repositories\nor certain other features.\n\n> 3.      Or recommending me some other solution\n\nI assume that you're building this software on a machine that _does_\nhave Git, so you could generate a file during the build process that\nincludes the commit date, commit hash, and any other information you\nwant.  This is easy to do for compiled languages, but it's also possible\nto generate something like a version.rb file for Ruby or the like as\npart of your build process.\n\nIn the interests of reproducible builds, you will of course want to use\nthe commit metadata and not the actual timestamp of building.\n\nIf that doesn't work for you, maybe you could tell us a little bit about\nyour goal with this process and what you're using it for, and we can\nhelp you more then.\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"}]}