* [BUG] Amending a shallow clone -> orphan branch
@ 2021-08-06 0:04 Alexandr Miloslavskiy
2021-08-06 12:21 ` Bagas Sanjaya
0 siblings, 1 reply; 5+ messages in thread
From: Alexandr Miloslavskiy @ 2021-08-06 0:04 UTC (permalink / raw)
To: git
Consider the following steps :
git clone --depth 1 --single-branch --branch master
https://github.com/git/git
cd git
>1.txt
git add 1.txt
git commit --amend
This results in an orphaned branch, where a single commit contains
entire tree.
I understand that this is a bug, because certainly git knew shallow
commit's parents and could reuse that when amending?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG] Amending a shallow clone -> orphan branch
2021-08-06 0:04 [BUG] Amending a shallow clone -> orphan branch Alexandr Miloslavskiy
@ 2021-08-06 12:21 ` Bagas Sanjaya
2021-08-06 12:24 ` Alexandr Miloslavskiy
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Bagas Sanjaya @ 2021-08-06 12:21 UTC (permalink / raw)
To: Alexandr Miloslavskiy, git
Hi Alexandr, welcome to Git mailing list!
On 06/08/21 07.04, Alexandr Miloslavskiy wrote:
> Consider the following steps :
>
> git clone --depth 1 --single-branch --branch master
> https://github.com/git/git
> cd git
> >1.txt
> git add 1.txt
> git commit --amend
>
> This results in an orphaned branch, where a single commit contains
> entire tree.
>
> I understand that this is a bug, because certainly git knew shallow
> commit's parents and could reuse that when amending?
I tested that, and below is `git status` after the test (using Git 2.32.0):
> On branch master
> Your branch and 'origin/master' have diverged,
> and have 1 and 1 different commits each, respectively.
> (use "git pull" to merge the remote branch into yours)
>
> nothing to commit, working tree clean
So you're amending merge commit by adding dummy file, so that your
`master` branch becomes divergent against origin. That dummy file isn't
contained in any commits that are included with that merge commit.
--
An old man doll... just what I always wanted! - Clara
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG] Amending a shallow clone -> orphan branch
2021-08-06 12:21 ` Bagas Sanjaya
@ 2021-08-06 12:24 ` Alexandr Miloslavskiy
2021-08-06 12:27 ` Alexandr Miloslavskiy
2021-08-06 13:16 ` Alexandr Miloslavskiy
2 siblings, 0 replies; 5+ messages in thread
From: Alexandr Miloslavskiy @ 2021-08-06 12:24 UTC (permalink / raw)
To: Bagas Sanjaya, git
Bagas,
Thanks for testing.
> I tested that, and below is `git status` after the test (using Git
2.32.0):
>
>> On branch master
>> Your branch and 'origin/master' have diverged,
>> and have 1 and 1 different commits each, respectively.
>> (use "git pull" to merge the remote branch into yours)
>>
>> nothing to commit, working tree clean
>
> So you're amending merge commit by adding dummy file, so that your
> `master` branch becomes divergent against origin. That dummy file isn't
> contained in any commits that are included with that merge commit.
What you probably didn't notice is that the new commit has no parents,
that is, it formed a new orphaned branch. The expected behavior is
amending the top commit and keeping it connected to the previous branch.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG] Amending a shallow clone -> orphan branch
2021-08-06 12:21 ` Bagas Sanjaya
2021-08-06 12:24 ` Alexandr Miloslavskiy
@ 2021-08-06 12:27 ` Alexandr Miloslavskiy
2021-08-06 13:16 ` Alexandr Miloslavskiy
2 siblings, 0 replies; 5+ messages in thread
From: Alexandr Miloslavskiy @ 2021-08-06 12:27 UTC (permalink / raw)
To: Bagas Sanjaya, git
On 06.08.2021 15:21, Bagas Sanjaya wrote:
> So you're amending merge commit by adding dummy file, so that your
> `master` branch becomes divergent against origin. That dummy file isn't
> contained in any commits that are included with that merge commit.
Note, the problem isn't about merge commits, it happens for regular
commits as well. Maybe I should have picked a different repo for
example. Still, the problem with losing all parents is the same
regardless of merge/regular commit.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [BUG] Amending a shallow clone -> orphan branch
2021-08-06 12:21 ` Bagas Sanjaya
2021-08-06 12:24 ` Alexandr Miloslavskiy
2021-08-06 12:27 ` Alexandr Miloslavskiy
@ 2021-08-06 13:16 ` Alexandr Miloslavskiy
2 siblings, 0 replies; 5+ messages in thread
From: Alexandr Miloslavskiy @ 2021-08-06 13:16 UTC (permalink / raw)
To: Bagas Sanjaya, git
A bit more details:
$ git clone --depth 1 --single-branch --branch master
https://github.com/git/git
$ cd git
Here, a shallow clone is made with just 1 commit.
$ git show -s --pretty=%P HEAD
Outputs nothing; that's already a small bug.
Surely the commit has parents!
$ git cat-file -p HEAD | grep parent
OK, that's better, finally the true parents are shown.
$ >1.txt
$ git add 1.txt
$ git commit --amend
Here, the top (and only in our clone) commit is amended.
$ git cat-file -p HEAD | grep parent
Nothing! This is the bug I'm reporting: amending the commit orphaned it.
To give a bit more background: I have a heavy-weight repo which I was
testing on different machines. Since it's heavy, I decided to shallow
clone just 1 commit. Upon testing on some machine, I found a small bug
and amended a fix. Then I force-pushed. I expected the branch to be amended.
Instead, what I got was an orphaned branch, disconnected from all repo's
branches, containing all files at once! Clearly not the best thing.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-08-06 18:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06 0:04 [BUG] Amending a shallow clone -> orphan branch Alexandr Miloslavskiy
2021-08-06 12:21 ` Bagas Sanjaya
2021-08-06 12:24 ` Alexandr Miloslavskiy
2021-08-06 12:27 ` Alexandr Miloslavskiy
2021-08-06 13:16 ` Alexandr Miloslavskiy
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.