{"thread":{"id":"62355","subject":"Why is pushing to stash not allowed without an initial commit?","startedAt":"2024-10-17T15:21:34Z","lastAt":"2024-10-17T20:50:52Z","messageCount":3,"participants":["Abhijeet Sonar","Taylor Blau","Sergey Organov"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"505371","messageId":"bab5a7a9-f006-4a1f-ae38-2dec817c5a82@gmail.com","threadId":"62355","inReplyTo":null,"subject":"Why is pushing to stash not allowed without an initial commit?","fromName":"Abhijeet Sonar","fromEmail":"abhijeet.nkt@gmail.com","sentAt":"2024-10-17T15:21:29Z","receivedAt":"2024-10-17T15:21:34Z","isPatch":false,"sender":{"key":"abhijeet.nkt@gmail.com","avatar":"https://avatars.githubusercontent.com/u/40241646?v=4"},"body":"I recently ran `git stash push` in a newly initialized repository.\n\n```\n$ git init\nInitialized empty Git repository in <redacted>/.git/\n$ touch a b\n$ git add a\n$ git stash push a\nYou do not have the initial commit yet\n```\n\n\nOn the other hand, with an initial commit:\n\n```\n$ git init\nInitialized empty Git repository in <redacted>/.git/\n$ touch a b\n$ git add a\n$ git commit -m a\n[master (root-commit) 3bf80c1] a\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 a\n$ git add b\n$ git stash\nSaved working directory and index state WIP on master: 3bf80c1 a\n$ git log --oneline --graph --all\n*   293076b (refs/stash) WIP on master: 3bf80c1 a\n|\\  \n| * 64140e0 index on master: 3bf80c1 a\n|/  \n* 3bf80c1 (HEAD -> master) a\n```\n\nI see that the stash commit has two parents: the initial commit and the\ncommit that actually holds the files that were stashed.\n\nIf git were to allow a stash entry with no initial commit, it would have to\ncreate a stash commit with only one parent (i.e. the commit labeled with\n'index on <branch>'). I wonder if there is a reason this would be bad and\ntherefore not allowed?\n\nThanks.\n\n"},{"id":"505386","messageId":"ZxFe/cEI0SzFMSi0@nand.local","threadId":"62355","inReplyTo":"bab5a7a9-f006-4a1f-ae38-2dec817c5a82@gmail.com","subject":"Re: Why is pushing to stash not allowed without an initial commit?","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-17T19:01:17Z","receivedAt":"2024-10-17T19:01:21Z","isPatch":false,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Thu, Oct 17, 2024 at 08:51:29PM +0530, Abhijeet Sonar wrote:\n> I see that the stash commit has two parents: the initial commit and the\n> commit that actually holds the files that were stashed.\n>\n> If git were to allow a stash entry with no initial commit, it would have to\n> create a stash commit with only one parent (i.e. the commit labeled with\n> 'index on <branch>'). I wonder if there is a reason this would be bad and\n> therefore not allowed?\n\nRight, each stash entry has two parents:\n\n  - The first parent is the state of HEAD in your repository when you\n    created the stash entry,\n\n  - The second parent is the state of the index at the same point\n\nSo there would be no reasonable value to substitute in for the first\nparent in the case where your repository does not yet have any commits.\n\nAs a concept, stashing without any commits in your repository doesn't\nseem fundamentally flawed, but it would make interpreting other stash\nentries substantially more awkward. The current model ensures that if\nyou look at any stash entry S, then S^1 is the state of HEAD when S was\ncreated, and S^2 is likewise the state of the index.\n\nThat changes if you don't have a commit to store in S^1, since now the\ninterpretation of S^1 depends on how many parents S has to begin with.\n\nThanks,\nTaylor\n"},{"id":"505391","messageId":"87msj2a1xy.fsf@osv.gnss.ru","threadId":"62355","inReplyTo":"ZxFe/cEI0SzFMSi0@nand.local","subject":"Re: Why is pushing to stash not allowed without an initial commit?","fromName":"Sergey Organov","fromEmail":"sorganov@gmail.com","sentAt":"2024-10-17T20:50:49Z","receivedAt":"2024-10-17T20:50:52Z","isPatch":false,"sender":{"key":"sorganov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8501568?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> On Thu, Oct 17, 2024 at 08:51:29PM +0530, Abhijeet Sonar wrote:\n>> I see that the stash commit has two parents: the initial commit and the\n>> commit that actually holds the files that were stashed.\n>>\n>> If git were to allow a stash entry with no initial commit, it would have to\n>> create a stash commit with only one parent (i.e. the commit labeled with\n>> 'index on <branch>'). I wonder if there is a reason this would be bad and\n>> therefore not allowed?\n>\n> Right, each stash entry has two parents:\n>\n>   - The first parent is the state of HEAD in your repository when you\n>     created the stash entry,\n>\n>   - The second parent is the state of the index at the same point\n>\n> So there would be no reasonable value to substitute in for the first\n> parent in the case where your repository does not yet have any\n> commits.\n\nI still wonder why Git has no concept of the ultimate null-commit from\nwhich all the Git world descends? Looks like it'd help to have one to\nhandle such corner cases gracefully. Was it just an oversight of\noriginal design that isn't worth fixing already?\n\n-- \nSergey\n"}]}