{"thread":{"id":"56226","subject":"[BUG] Amending a shallow clone -> orphan branch","startedAt":"2021-08-06T08:29:49Z","lastAt":"2021-08-06T18:00:10Z","messageCount":5,"participants":["Alexandr Miloslavskiy","Bagas Sanjaya"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"432155","messageId":"64760969-1ead-2bfb-6f98-1161d385c0ca@syntevo.com","threadId":"56226","inReplyTo":null,"subject":"[BUG] Amending a shallow clone -> orphan branch","fromName":"Alexandr Miloslavskiy","fromEmail":"alexandr.miloslavskiy@syntevo.com","sentAt":"2021-08-06T00:04:46Z","receivedAt":"2021-08-06T08:29:49Z","isPatch":false,"sender":{"key":"alexandr.miloslavskiy@syntevo.com","avatar":null},"body":"Consider the following steps :\n\ngit clone --depth 1 --single-branch --branch master \nhttps://github.com/git/git\ncd git\n >1.txt\ngit add 1.txt\ngit commit --amend\n\nThis results in an orphaned branch, where a single commit contains \nentire tree.\n\nI understand that this is a bug, because certainly git knew shallow \ncommit's parents and could reuse that when amending?\n"},{"id":"432171","messageId":"b3083a15-f2da-0eae-b07b-8a641c613906@gmail.com","threadId":"56226","inReplyTo":"64760969-1ead-2bfb-6f98-1161d385c0ca@syntevo.com","subject":"Re: [BUG] Amending a shallow clone -> orphan branch","fromName":"Bagas Sanjaya","fromEmail":"bagasdotme@gmail.com","sentAt":"2021-08-06T12:21:24Z","receivedAt":"2021-08-06T12:21:30Z","isPatch":false,"sender":{"key":"bagasdotme@gmail.com","avatar":"https://avatars.githubusercontent.com/u/40219486?v=4"},"body":"Hi Alexandr, welcome to Git mailing list!\n\nOn 06/08/21 07.04, Alexandr Miloslavskiy wrote:\n> Consider the following steps :\n> \n> git clone --depth 1 --single-branch --branch master \n> https://github.com/git/git\n> cd git\n>  >1.txt\n> git add 1.txt\n> git commit --amend\n> \n> This results in an orphaned branch, where a single commit contains \n> entire tree.\n> \n> I understand that this is a bug, because certainly git knew shallow \n> commit's parents and could reuse that when amending?\n\nI tested that, and below is `git status` after the test (using Git 2.32.0):\n\n> On branch master\n> Your branch and 'origin/master' have diverged,\n> and have 1 and 1 different commits each, respectively.\n>   (use \"git pull\" to merge the remote branch into yours)\n> \n> nothing to commit, working tree clean\n\nSo you're amending merge commit by adding dummy file, so that your \n`master` branch becomes divergent against origin. That dummy file isn't \ncontained in any commits that are included with that merge commit.\n\n-- \nAn old man doll... just what I always wanted! - Clara\n"},{"id":"432172","messageId":"4d242c96-77e4-e59d-a7a3-c108164ba819@syntevo.com","threadId":"56226","inReplyTo":"b3083a15-f2da-0eae-b07b-8a641c613906@gmail.com","subject":"Re: [BUG] Amending a shallow clone -> orphan branch","fromName":"Alexandr Miloslavskiy","fromEmail":"alexandr.miloslavskiy@syntevo.com","sentAt":"2021-08-06T12:24:49Z","receivedAt":"2021-08-06T12:24:53Z","isPatch":false,"sender":{"key":"alexandr.miloslavskiy@syntevo.com","avatar":null},"body":"Bagas,\n\nThanks for testing.\n\n > I tested that, and below is `git status` after the test (using Git \n2.32.0):\n >\n >> On branch master\n >> Your branch and 'origin/master' have diverged,\n >> and have 1 and 1 different commits each, respectively.\n >>   (use \"git pull\" to merge the remote branch into yours)\n >>\n >> nothing to commit, working tree clean\n >\n > So you're amending merge commit by adding dummy file, so that your\n > `master` branch becomes divergent against origin. That dummy file isn't\n > contained in any commits that are included with that merge commit.\n\nWhat you probably didn't notice is that the new commit has no parents, \nthat is, it formed a new orphaned branch. The expected behavior is \namending the top commit and keeping it connected to the previous branch.\n"},{"id":"432173","messageId":"20d768d5-2fe2-5540-b7e7-2174db7c80cf@syntevo.com","threadId":"56226","inReplyTo":"b3083a15-f2da-0eae-b07b-8a641c613906@gmail.com","subject":"Re: [BUG] Amending a shallow clone -> orphan branch","fromName":"Alexandr Miloslavskiy","fromEmail":"alexandr.miloslavskiy@syntevo.com","sentAt":"2021-08-06T13:16:57Z","receivedAt":"2021-08-06T13:17:39Z","isPatch":false,"sender":{"key":"alexandr.miloslavskiy@syntevo.com","avatar":null},"body":"A bit more details:\n\n$ git clone --depth 1 --single-branch --branch master \nhttps://github.com/git/git\n$ cd git\n\nHere, a shallow clone is made with just 1 commit.\n\n$ git show -s --pretty=%P HEAD\n\nOutputs nothing; that's already a small bug.\nSurely the commit has parents!\n\n$ git cat-file -p HEAD | grep parent\n\nOK, that's better, finally the true parents are shown.\n\n$ >1.txt\n$ git add 1.txt\n$ git commit --amend\n\nHere, the top (and only in our clone) commit is amended.\n\n$ git cat-file -p HEAD | grep parent\n\nNothing! This is the bug I'm reporting: amending the commit orphaned it.\n\nTo give a bit more background: I have a heavy-weight repo which I was \ntesting on different machines. Since it's heavy, I decided to shallow \nclone just 1 commit. Upon testing on some machine, I found a small bug \nand amended a fix. Then I force-pushed. I expected the branch to be amended.\n\nInstead, what I got was an orphaned branch, disconnected from all repo's \nbranches, containing all files at once! Clearly not the best thing.\n"},{"id":"432192","messageId":"fbec1ce8-a1ec-b504-72a7-2f96b646127b@syntevo.com","threadId":"56226","inReplyTo":"b3083a15-f2da-0eae-b07b-8a641c613906@gmail.com","subject":"Re: [BUG] Amending a shallow clone -> orphan branch","fromName":"Alexandr Miloslavskiy","fromEmail":"alexandr.miloslavskiy@syntevo.com","sentAt":"2021-08-06T12:27:18Z","receivedAt":"2021-08-06T18:00:10Z","isPatch":false,"sender":{"key":"alexandr.miloslavskiy@syntevo.com","avatar":null},"body":"On 06.08.2021 15:21, Bagas Sanjaya wrote:\n> So you're amending merge commit by adding dummy file, so that your \n> `master` branch becomes divergent against origin. That dummy file isn't \n> contained in any commits that are included with that merge commit.\n\nNote, the problem isn't about merge commits, it happens for regular \ncommits as well. Maybe I should have picked a different repo for \nexample. Still, the problem with losing all parents is the same \nregardless of merge/regular commit.\n"}]}