git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Abhijeet Sonar <abhijeet.nkt@gmail.com>
To: git@vger.kernel.org
Subject: Why is pushing to stash not allowed without an initial commit?
Date: Thu, 17 Oct 2024 20:51:29 +0530	[thread overview]
Message-ID: <bab5a7a9-f006-4a1f-ae38-2dec817c5a82@gmail.com> (raw)

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.


             reply	other threads:[~2024-10-17 15:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17 15:21 Abhijeet Sonar [this message]
2024-10-17 19:01 ` Why is pushing to stash not allowed without an initial commit? Taylor Blau
2024-10-17 20:50   ` Sergey Organov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bab5a7a9-f006-4a1f-ae38-2dec817c5a82@gmail.com \
    --to=abhijeet.nkt@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).