git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Why is pushing to stash not allowed without an initial commit?

From
Abhijeet Sonar <abhijeet.nkt@gmail.com>
Date
Oct 17, 2024, 15:21 UTC
Message-ID
<bab5a7a9-f006-4a1f-ae38-2dec817c5a82@gmail.com>
I recently ran `git stash push` in a newly initialized repository.

``` $ git init Initialized empty Git repository in <redacted>/.git/ $ touch a b $ git add a $ git stash push a You do not have the initial commit yet ```

On the other hand, with an initial commit:
```
$ git init
Initialized empty Git repository in <redacted>/.git/
$ touch a b
$ git add a
$ git commit -m a
[master (root-commit) 3bf80c1] a
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a
$ git add b
$ git stash
Saved working directory and index state WIP on master: 3bf80c1 a
$ git log --oneline --graph --all
*   293076b (refs/stash) WIP on master: 3bf80c1 a
|\  
| * 64140e0 index on master: 3bf80c1 a
|/  
* 3bf80c1 (HEAD -> master) a
```

I see that the stash commit has two parents: the initial commit and the commit that actually holds the files that were stashed.

If git were to allow a stash entry with no initial commit, it would have to create a stash commit with only one parent (i.e. the commit labeled with 'index on <branch>'). I wonder if there is a reason this would be bad and therefore not allowed?

Thanks.
Next: Taylor Blau
Message 1 of 3 in “Why is pushing to stash not allowed without an initial commit?”
  1. Abhijeet SonarOct 17, 2024
  2. Taylor BlauOct 17, 2024
  3. Sergey OrganovOct 17, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.