From: Alexandr Miloslavskiy <hidden> Date: 2021-08-06 08:29:49
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?
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
From: Alexandr Miloslavskiy <hidden> Date: 2021-08-06 12:24:53
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.
From: Alexandr Miloslavskiy <hidden> Date: 2021-08-06 13:17:39
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.
From: Alexandr Miloslavskiy <hidden> Date: 2021-08-06 18:00:10
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.