{"thread":{"id":"62983","subject":"Deleting first commits; maintaining last commits","startedAt":"2025-02-20T22:53:27Z","lastAt":"2025-02-21T22:42:17Z","messageCount":6,"participants":["Jamenson Espindula","brian m. carlson","Konstantin Ryabitsev","Emily Shaffer","Elijah Newren"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"512785","messageId":"CAOW_YOkX8K=7i7w9c5oH5Cfia0kCzwC3=ok5E=eUwYgpcOKTRQ@mail.gmail.com","threadId":"62983","inReplyTo":null,"subject":"Deleting first commits; maintaining last commits","fromName":"Jamenson Espindula","fromEmail":"jafesp@gmail.com","sentAt":"2025-02-20T22:53:06Z","receivedAt":"2025-02-20T22:53:27Z","isPatch":false,"sender":{"key":"jafesp@gmail.com","avatar":null},"body":"Hi all.\n\nMy Git repository on GitHub <https://github.com/espindula/br-blfs> has\nabout 23,500 commits. However, there are several old (before Feb, 28\n2022) commits I would like to delete and maintain the newer ones\n(after Feb, 28 2022). So, Is there any Git command (or combined\ncommands) I could use?\n\nAny help will be appreciated.\n\nThank you in advance.\n\nJamenson Ferreira Espindula de Almeida Melo\nJaboatão dos Guararapes, Pernambuco, Brazil\nGNU/Linux user #166197; LFS ID 24492\nKey fingerprint: 234D 1914 4224 7C53 BD13 6855 2AE0 25C0 08A8 6180\n"},{"id":"512786","messageId":"Z7fGQalzCg_Fx-ub@tapette.crustytoothpaste.net","threadId":"62983","inReplyTo":"CAOW_YOkX8K=7i7w9c5oH5Cfia0kCzwC3=ok5E=eUwYgpcOKTRQ@mail.gmail.com","subject":"Re: Deleting first commits; maintaining last commits","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2025-02-21T00:18:09Z","receivedAt":"2025-02-21T00:18:18Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2025-02-20 at 22:53:06, Jamenson Espindula wrote:\n> Hi all.\n\nHi,\n\n> My Git repository on GitHub <https://github.com/espindula/br-blfs> has\n> about 23,500 commits. However, there are several old (before Feb, 28\n> 2022) commits I would like to delete and maintain the newer ones\n> (after Feb, 28 2022). So, Is there any Git command (or combined\n> commands) I could use?\n\nNo, Git doesn't offer such a thing.  Due to the use of cryptographic\nhashes used, it would be impossible to verify the integrity of the\nrepository if it could just be truncated like that.  In addition, the\ngoal of Git as a version control system is to track history, not to\ndestroy it.\n\nHowever, if the concern is size and not something else (like removing\npersonal information), then you could use a shallow clone to just\ndownload a certain number of revisions and work on that.  The full\nhistory would remain on the server, and you could still push newer\nchanges, but the size on your local machine would be smaller.  If you\nneed more history, you could use a partial clone instead if you're\nwilling to be online to work.\n\nI'll note that 23,500 commits is not that many.  Git itself has 76,212\ncommits in my local copy, Linux has over 1,335,000, and I routinely work\non a work project with over 500,000.  Git should scale much farther than\nthat provided you don't have a really misshapen repository.\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"},{"id":"512830","messageId":"20250221-intrepid-furry-wapiti-eebff0@lemur","threadId":"62983","inReplyTo":"Z7fGQalzCg_Fx-ub@tapette.crustytoothpaste.net","subject":"Re: Deleting first commits; maintaining last commits","fromName":"Konstantin Ryabitsev","fromEmail":"konstantin@linuxfoundation.org","sentAt":"2025-02-21T15:17:49Z","receivedAt":"2025-02-21T15:17:52Z","isPatch":false,"sender":{"key":"konstantin@linuxfoundation.org","avatar":"https://gravatar.com/avatar/7cb8827c6de56e1bd2dea16508c6708aa43feed3bf3813bcdacecdf96ceadd79?d=mp&s=160"},"body":"On Fri, Feb 21, 2025 at 12:18:09AM +0000, brian m. carlson wrote:\n> > My Git repository on GitHub <https://github.com/espindula/br-blfs> has\n> > about 23,500 commits. However, there are several old (before Feb, 28\n> > 2022) commits I would like to delete and maintain the newer ones\n> > (after Feb, 28 2022). So, Is there any Git command (or combined\n> > commands) I could use?\n> \n> No, Git doesn't offer such a thing.  Due to the use of cryptographic\n> hashes used, it would be impossible to verify the integrity of the\n> repository if it could just be truncated like that.  In addition, the\n> goal of Git as a version control system is to track history, not to\n> destroy it.\n> \n> However, if the concern is size and not something else (like removing\n> personal information), then you could use a shallow clone to just\n> download a certain number of revisions and work on that.  The full\n> history would remain on the server, and you could still push newer\n> changes, but the size on your local machine would be smaller.  If you\n> need more history, you could use a partial clone instead if you're\n> willing to be online to work.\n\nAnother approach is to create a new repository and use a graft/replacement\ncommit to indicate that history continues in a different repository, right? I\ndo sometimes wish this was a bit easier/more accessible to perform, because\nthat would allow creating \"epochs\" for very large repos. Unfortunately,\nshallow clones tend to be very heavy on the server-side.\n\n-K\n"},{"id":"512833","messageId":"CAJoAoZmsLu8DukvMugU6z6C=gKFP=dwDhZAT=_jE6h+dO9V55A@mail.gmail.com","threadId":"62983","inReplyTo":"20250221-intrepid-furry-wapiti-eebff0@lemur","subject":"Re: Deleting first commits; maintaining last commits","fromName":"Emily Shaffer","fromEmail":"nasamuffin@google.com","sentAt":"2025-02-21T16:05:59Z","receivedAt":"2025-02-21T16:06:12Z","isPatch":false,"sender":{"key":"nasamuffin@google.com","avatar":"https://avatars.githubusercontent.com/u/1606826?v=4"},"body":"On Fri, Feb 21, 2025 at 7:18 AM Konstantin Ryabitsev\n<konstantin@linuxfoundation.org> wrote:\n>\n> On Fri, Feb 21, 2025 at 12:18:09AM +0000, brian m. carlson wrote:\n> > > My Git repository on GitHub <https://github.com/espindula/br-blfs> has\n> > > about 23,500 commits. However, there are several old (before Feb, 28\n> > > 2022) commits I would like to delete and maintain the newer ones\n> > > (after Feb, 28 2022). So, Is there any Git command (or combined\n> > > commands) I could use?\n> >\n> > No, Git doesn't offer such a thing.  Due to the use of cryptographic\n> > hashes used, it would be impossible to verify the integrity of the\n> > repository if it could just be truncated like that.  In addition, the\n> > goal of Git as a version control system is to track history, not to\n> > destroy it.\n> >\n> > However, if the concern is size and not something else (like removing\n> > personal information), then you could use a shallow clone to just\n> > download a certain number of revisions and work on that.  The full\n> > history would remain on the server, and you could still push newer\n> > changes, but the size on your local machine would be smaller.  If you\n> > need more history, you could use a partial clone instead if you're\n> > willing to be online to work.\n>\n> Another approach is to create a new repository and use a graft/replacement\n> commit to indicate that history continues in a different repository, right? I\n> do sometimes wish this was a bit easier/more accessible to perform, because\n> that would allow creating \"epochs\" for very large repos. Unfortunately,\n> shallow clones tend to be very heavy on the server-side.\n\nFor hosts which support it - which I believe includes GitHub - partial\nclone is generally easier on the server and a little bit less\nbug-prone than shallow clone.\n\n>\n> -K\n>\n"},{"id":"512862","messageId":"CABPp-BG7eLXtHk-r3svmaipOrMjM8oOEUEJ9CRjBUjUQjKC6sA@mail.gmail.com","threadId":"62983","inReplyTo":"20250221-intrepid-furry-wapiti-eebff0@lemur","subject":"Re: Deleting first commits; maintaining last commits","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2025-02-21T21:50:06Z","receivedAt":"2025-02-21T21:50:18Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Fri, Feb 21, 2025 at 7:18 AM Konstantin Ryabitsev\n<konstantin@linuxfoundation.org> wrote:\n>\n> On Fri, Feb 21, 2025 at 12:18:09AM +0000, brian m. carlson wrote:\n> > > My Git repository on GitHub <https://github.com/espindula/br-blfs> has\n> > > about 23,500 commits. However, there are several old (before Feb, 28\n> > > 2022) commits I would like to delete and maintain the newer ones\n> > > (after Feb, 28 2022). So, Is there any Git command (or combined\n> > > commands) I could use?\n> >\n> > No, Git doesn't offer such a thing.  Due to the use of cryptographic\n> > hashes used, it would be impossible to verify the integrity of the\n> > repository if it could just be truncated like that.  In addition, the\n> > goal of Git as a version control system is to track history, not to\n> > destroy it.\n> >\n> > However, if the concern is size and not something else (like removing\n> > personal information), then you could use a shallow clone to just\n> > download a certain number of revisions and work on that.  The full\n> > history would remain on the server, and you could still push newer\n> > changes, but the size on your local machine would be smaller.  If you\n> > need more history, you could use a partial clone instead if you're\n> > willing to be online to work.\n>\n> Another approach is to create a new repository and use a graft/replacement\n> commit to indicate that history continues in a different repository, right? I\n> do sometimes wish this was a bit easier/more accessible to perform, because\n> that would allow creating \"epochs\" for very large repos. Unfortunately,\n> shallow clones tend to be very heavy on the server-side.\n\nI'm totally in support of the \"friends don't let friends use\nshallow-clones\" point of view, even if I've had rather less success\nthan I would have liked at promoting it.  But throwing shade at\nshallow clones is just an impulse, not the real reason I'm responding\nhere.\n\nYes, if you're willing to rewrite history, invalidating all hashes and\nrewriting the recent-enough-ones-that-you-still-want-to-keep, you can\ngo that route too.  In fact, doing so is as easy as creating a replace\nref graft (or grafts) which make the oldest commit(s) you want to keep\nlook parentless, and then rewriting history to make that graft\npermanent and remove the graft.  (Afterwards, you can make a separate\ngraft from that new root commit to the original real commit if you\nwant.)\n\nIt turns out this is an example from user filed issues that comes up\noccasionally in git-filter-repo.  While it's an example I documented\nwith the commands to run, just so I can link to it if it's asked\nagain, I really don't like the strategy of destroying history,\nespecially since most users who ask for this kind of capability\n(Konstantin, you're a notable exception here) don't understand the\npoints that brian brought up in his first paragraph.  And I make sure\nto say as much right before I provide the example in my docs.  But,\nyes, this is a possibility for those that don't mind destroying\nhistory.\n"},{"id":"512865","messageId":"Z7kBRYcxu3jgOTmZ@tapette.crustytoothpaste.net","threadId":"62983","inReplyTo":"CAJoAoZmsLu8DukvMugU6z6C=gKFP=dwDhZAT=_jE6h+dO9V55A@mail.gmail.com","subject":"Re: Deleting first commits; maintaining last commits","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2025-02-21T22:42:13Z","receivedAt":"2025-02-21T22:42:17Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2025-02-21 at 16:05:59, Emily Shaffer wrote:\n> For hosts which support it - which I believe includes GitHub - partial\n> clone is generally easier on the server and a little bit less\n> bug-prone than shallow clone.\n\nThe really expensive thing is fetching into a shallow clone.  A simple\nshallow clone itself is not very expensive, and at $DAYJOB we encourage\nlarge-scale users (such as CI systems) to use shallow clones for that\nreason, since they're cheaper to serve than full clones, provided that\nthey never fetch into them.\n\nNow, I agree that the particular use case here is probably going to be\nfetching into a shallow clone, and that's okay if it's one particular\nuser doing that occasionally, which it sounds like it is.  It's\ndefinitely a problem if it's thousands of CI jobs, though.\n\nIt may be that a partial clone does perform better overall, but it has\nthe downside that it effectively requires you to be online during usage,\nwhereas a shallow clone does not.  Whether that is a problem depends on\nyour use case: for work, I am effectively always online, so that's not a\nproblem, but for personal work, I want to be able to work on an\nairplane (where there may be no Internet and the Wi-Fi, if any, is very\nslow), in a hotel room with bad connectivity, or even on a retreat in\nthe middle of nowhere without Internet at all.\n\nSo that's why I mentioned both: both options have some upsides and some\ndownsides, and there's no one-size-fits-all solution.\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"}]}