* Why is pushing to stash not allowed without an initial commit?
@ 2024-10-17 15:21 Abhijeet Sonar
2024-10-17 19:01 ` Taylor Blau
0 siblings, 1 reply; 3+ messages in thread
From: Abhijeet Sonar @ 2024-10-17 15:21 UTC (permalink / raw)
To: git
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Why is pushing to stash not allowed without an initial commit?
2024-10-17 15:21 Why is pushing to stash not allowed without an initial commit? Abhijeet Sonar
@ 2024-10-17 19:01 ` Taylor Blau
2024-10-17 20:50 ` Sergey Organov
0 siblings, 1 reply; 3+ messages in thread
From: Taylor Blau @ 2024-10-17 19:01 UTC (permalink / raw)
To: Abhijeet Sonar; +Cc: git
On Thu, Oct 17, 2024 at 08:51:29PM +0530, Abhijeet Sonar wrote:
> 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?
Right, each stash entry has two parents:
- The first parent is the state of HEAD in your repository when you
created the stash entry,
- The second parent is the state of the index at the same point
So there would be no reasonable value to substitute in for the first
parent in the case where your repository does not yet have any commits.
As a concept, stashing without any commits in your repository doesn't
seem fundamentally flawed, but it would make interpreting other stash
entries substantially more awkward. The current model ensures that if
you look at any stash entry S, then S^1 is the state of HEAD when S was
created, and S^2 is likewise the state of the index.
That changes if you don't have a commit to store in S^1, since now the
interpretation of S^1 depends on how many parents S has to begin with.
Thanks,
Taylor
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Why is pushing to stash not allowed without an initial commit?
2024-10-17 19:01 ` Taylor Blau
@ 2024-10-17 20:50 ` Sergey Organov
0 siblings, 0 replies; 3+ messages in thread
From: Sergey Organov @ 2024-10-17 20:50 UTC (permalink / raw)
To: Taylor Blau; +Cc: Abhijeet Sonar, git
Taylor Blau <me@ttaylorr.com> writes:
> On Thu, Oct 17, 2024 at 08:51:29PM +0530, Abhijeet Sonar wrote:
>> 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?
>
> Right, each stash entry has two parents:
>
> - The first parent is the state of HEAD in your repository when you
> created the stash entry,
>
> - The second parent is the state of the index at the same point
>
> So there would be no reasonable value to substitute in for the first
> parent in the case where your repository does not yet have any
> commits.
I still wonder why Git has no concept of the ultimate null-commit from
which all the Git world descends? Looks like it'd help to have one to
handle such corner cases gracefully. Was it just an oversight of
original design that isn't worth fixing already?
--
Sergey
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-17 20:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-17 15:21 Why is pushing to stash not allowed without an initial commit? Abhijeet Sonar
2024-10-17 19:01 ` Taylor Blau
2024-10-17 20:50 ` Sergey Organov
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).