threads / bug / 52456

Bug? git commit fileA tries to delete fileB and other oddities

Subject: Bug? git commit fileA tries to delete fileB and other oddities

## tl;dr

5 messages between Dec 14, 2019 and Dec 17, 2019.

replies: 4people: 3as markdown or json

Mikael Simonsson· Dec 14, 2019, 10:39 UTC · lore
Hi,
I have the following problems with a local repository:
* git commit fileA tries to delete fileX (fileX still exists).
* git restore --staged fileX doesn't work, the file remains staged.
* A commit from a few days back deleted 2 random files that I haven't
touched or staged in months and pulled in staged changes I didn't ask
for.
git version: 2.24.0 and 2.24.1 (OS: FreeBSD 12)

How can this happen? The repository has a local remote (on the same filesystem) that is pushed to only. I tarred the project and copied it to a Mac with git 2.23.0 and the problem persists.

For example (I've only changed the filenames):

% git status On branch master Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   fileA
        modified:   fileB
        modified:   fileC
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        ...
% git commit fileA

# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch master # Your branch is up to date with 'origin/master'. # # Changes to be committed: # deleted: fileX # modified: fileA # # Changes not staged for commit:

% git stash Saved working directory and index state WIP on master: 488e7081 ...

% git status On branch master Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    fileX
Untracked files:
% git restore --staged fileX

% git status On branch master Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    fileX
Untracked files:
  (use "git add <file>..." to include in what will be committed)

Thanks, Mikael

Johannes Schindelin· Dec 15, 2019, 21:09 UTC · re: Mikael Simonsson · lore

Re: Bug? git commit fileA tries to delete fileB and other oddities

Hi Mikael,
On Sat, 14 Dec 2019, Mikael Simonsson wrote:
Show 15 quoted lines
> I have the following problems with a local repository:
>
> * git commit fileA tries to delete fileX (fileX still exists).
>
> * git restore --staged fileX doesn't work, the file remains staged.
>
> * A commit from a few days back deleted 2 random files that I haven't
> touched or staged in months and pulled in staged changes I didn't ask
> for.
>
> git version: 2.24.0 and 2.24.1 (OS: FreeBSD 12)
>
> How can this happen? The repository has a local remote (on the same
> filesystem) that is pushed to only. I tarred the project and copied it
> to a Mac with git 2.23.0 and the problem persists.

It would be good if you could come up with a minimal list of commands to recreate that problem. That way, we can turn it into a regression test and fix the problem.

Ciao, Johannes

Show 67 quoted lines
>
> For example (I've only changed the filenames):
>
> % git status
> On branch master
> Your branch is up to date with 'origin/master'.
>
> Changes to be committed:
>   (use "git restore --staged <file>..." to unstage)
>         modified:   fileA
>         modified:   fileB
>         modified:   fileC
>
> Changes not staged for commit:
>   (use "git add/rm <file>..." to update what will be committed)
>   (use "git restore <file>..." to discard changes in working directory)
>         ...
>
>
> % git commit fileA
>
> # Please enter the commit message for your changes. Lines starting
> # with '#' will be ignored, and an empty message aborts the commit.
> #
> # On branch master
> # Your branch is up to date with 'origin/master'.
> #
> # Changes to be committed:
> #       deleted:    fileX
> #       modified:   fileA
> #
> # Changes not staged for commit:
>
>
> % git stash
> Saved working directory and index state WIP on master: 488e7081 ...
>
>
> % git status
> On branch master
> Your branch is up to date with 'origin/master'.
>
> Changes to be committed:
>   (use "git restore --staged <file>..." to unstage)
>         deleted:    fileX
>
> Untracked files:
>
>
> % git restore --staged fileX
>
>
> % git status
> On branch master
> Your branch is up to date with 'origin/master'.
>
> Changes to be committed:
>   (use "git restore --staged <file>..." to unstage)
>         deleted:    fileX
>
> Untracked files:
>   (use "git add <file>..." to include in what will be committed)
>
>
> Thanks,
> Mikael
>
Mikael Simonsson· Dec 16, 2019, 09:50 UTC · re: Johannes Schindelin · lore

Re: Bug? git commit fileA tries to delete fileB and other oddities

Hi Johannes,
I will try to recreate the problem with a new repository.
So far I think I've narrowed it down to a bug introduced in git 2.20.0.

Not buggy: 1.9.5 2.7.1 2.11.0 2.15.0 2.18.0 2.19.0 2.19.2 2.19.3

Buggy: 2.20.0 2.21.1 2.23.0 (Mac) 2.24.0 2.24.1

The buggy versions all try to delete fileX when running "git commit fileA":
% git commit fileA

# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch master # Your branch is up to date with 'origin/master'. # # Changes to be committed: # deleted: fileX # modified: fileA # # Changes not staged for commit:

Kind regards, Mikael

On Sun, Dec 15, 2019 at 9:10 PM Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:

Show 95 quoted lines
>
> Hi Mikael,
>
> On Sat, 14 Dec 2019, Mikael Simonsson wrote:
>
> > I have the following problems with a local repository:
> >
> > * git commit fileA tries to delete fileX (fileX still exists).
> >
> > * git restore --staged fileX doesn't work, the file remains staged.
> >
> > * A commit from a few days back deleted 2 random files that I haven't
> > touched or staged in months and pulled in staged changes I didn't ask
> > for.
> >
> > git version: 2.24.0 and 2.24.1 (OS: FreeBSD 12)
> >
> > How can this happen? The repository has a local remote (on the same
> > filesystem) that is pushed to only. I tarred the project and copied it
> > to a Mac with git 2.23.0 and the problem persists.
>
> It would be good if you could come up with a minimal list of commands to
> recreate that problem. That way, we can turn it into a regression test and
> fix the problem.
>
> Ciao,
> Johannes
>
> >
> > For example (I've only changed the filenames):
> >
> > % git status
> > On branch master
> > Your branch is up to date with 'origin/master'.
> >
> > Changes to be committed:
> >   (use "git restore --staged <file>..." to unstage)
> >         modified:   fileA
> >         modified:   fileB
> >         modified:   fileC
> >
> > Changes not staged for commit:
> >   (use "git add/rm <file>..." to update what will be committed)
> >   (use "git restore <file>..." to discard changes in working directory)
> >         ...
> >
> >
> > % git commit fileA
> >
> > # Please enter the commit message for your changes. Lines starting
> > # with '#' will be ignored, and an empty message aborts the commit.
> > #
> > # On branch master
> > # Your branch is up to date with 'origin/master'.
> > #
> > # Changes to be committed:
> > #       deleted:    fileX
> > #       modified:   fileA
> > #
> > # Changes not staged for commit:
> >
> >
> > % git stash
> > Saved working directory and index state WIP on master: 488e7081 ...
> >
> >
> > % git status
> > On branch master
> > Your branch is up to date with 'origin/master'.
> >
> > Changes to be committed:
> >   (use "git restore --staged <file>..." to unstage)
> >         deleted:    fileX
> >
> > Untracked files:
> >
> >
> > % git restore --staged fileX
> >
> >
> > % git status
> > On branch master
> > Your branch is up to date with 'origin/master'.
> >
> > Changes to be committed:
> >   (use "git restore --staged <file>..." to unstage)
> >         deleted:    fileX
> >
> > Untracked files:
> >   (use "git add <file>..." to include in what will be committed)
> >
> >
> > Thanks,
> > Mikael
> >
Jeff King· Dec 17, 2019, 07:33 UTC · re: Mikael Simonsson · lore

Re: Bug? git commit fileA tries to delete fileB and other oddities

On Mon, Dec 16, 2019 at 09:50:33AM +0000, Mikael Simonsson wrote:
Show 6 quoted lines
> I will try to recreate the problem with a new repository.
> 
> So far I think I've narrowed it down to a bug introduced in git 2.20.0.
> 
> Not buggy:
> [...]

If you can build Git from source, you might try using "git bisect" to find the exact commit where the problem starts.

Show 15 quoted lines
> The buggy versions all try to delete fileX when running "git commit fileA":
> 
> % git commit fileA
> 
> # Please enter the commit message for your changes. Lines starting
> # with '#' will be ignored, and an empty message aborts the commit.
> #
> # On branch master
> # Your branch is up to date with 'origin/master'.
> #
> # Changes to be committed:
> #       deleted:    fileX
> #       modified:   fileA
> #
> # Changes not staged for commit:

Is there anything about "fileX" and "fileA"'s names that might be relevant? E.g., might they case-fold to the same name or something?

-Peff
Mikael Simonsson· Dec 17, 2019, 11:04 UTC · re: Jeff King · lore

Re: Bug? git commit fileA tries to delete fileB and other oddities

git bisect made that pretty easy, thanks. It looks like it started with this commit:

"unpack-trees: optimize walking same trees with cache-tree" https://github.com/git/git/commit/b4da37380b7774248086f42bcd59397a44e1ac79

(I ran git bisect between tags v2.19.2 and v2.20.0.)

Testing the commit in question: % git checkout b4da37380b7774248086f42bcd59397a44e1ac79 % gmake -j 6 NO_OPENSSL=YesPlease NO_PERL=YesPlease NO_TCLTK=YesPlease NO_GETTEXT=YesPlease NO_EXPAT=YesPlease all

% ~/tmp/git-source/git version git version 2.18.0.751.gb4da37380b

% ~/tmp/git-source/git commit null_terminated.hh

# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch master # Your branch is up to date with 'origin/master'. # # Changes to be committed: # deleted: algo/find.hh # new file: app/.reserved # deleted: ascii/contains_icase.hh # deleted: ascii/contains_icase.test.cc # modified: null_terminated.hh # # Changes not staged for commit: Aborting commit due to empty commit message.

Note that the latest version behaves differently (it tries to delete another file):

% git version git version 2.24.1

% git commit null_terminated.hh

# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch master # Your branch is up to date with 'origin/master'. # # Changes to be committed: # deleted: defer.hh # modified: null_terminated.hh Aborting commit due to empty commit message.

The commit before "unpack-trees: optimize walking same trees with cache-tree" works as it should: % git checkout b4da37380b7774248086f42bcd59397a44e1ac79^ % gmake -j 6 NO_OPENSSL=YesPlease NO_PERL=YesPlease NO_TCLTK=YesPlease NO_GETTEXT=YesPlease NO_EXPAT=YesPlease all

% ~/tmp/git-source/git version git version 2.18.0.750.g0d1ed5963d

% ~/tmp/git-source/git commit null_terminated.hh

# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch master # Your branch is up to date with 'origin/master'. # # Changes to be committed: # modified: null_terminated.hh # # Changes not staged for commit: Aborting commit due to empty commit message.

Here's my local commit from about a week ago when the problems started.

I'm sure I ran "git commit readme.md" because I had several files staged. The commit pulled in 3 staged files (I think there were more) and deleted 3 files that 100% weren't staged.

% git show --numstat 7d5d43d849f1391b3cc11f12e037b8cb5174e3a3
commit 7d5d43d849f1391b3cc11f12e037b8cb5174e3a3
Author: Mikael Simonsson <m@mikaelsimonsson.com>
Date:   Sun Dec 8 10:38:38 2019 +0000
    Add short info and requirements for ranges

56 0 algo/find.hh 0 1 app/.reserved 16 0 ascii/contains_icase.hh 28 0 ascii/contains_icase.test.cc 0 41 bench/bench.hh 0 41 debug.hh 76 0 readme.md

-Mikael
On Tue, Dec 17, 2019 at 7:33 AM Jeff King <peff@peff.net> wrote:
Show 33 quoted lines
>
> On Mon, Dec 16, 2019 at 09:50:33AM +0000, Mikael Simonsson wrote:
>
> > I will try to recreate the problem with a new repository.
> >
> > So far I think I've narrowed it down to a bug introduced in git 2.20.0.
> >
> > Not buggy:
> > [...]
>
> If you can build Git from source, you might try using "git bisect" to
> find the exact commit where the problem starts.
>
> > The buggy versions all try to delete fileX when running "git commit fileA":
> >
> > % git commit fileA
> >
> > # Please enter the commit message for your changes. Lines starting
> > # with '#' will be ignored, and an empty message aborts the commit.
> > #
> > # On branch master
> > # Your branch is up to date with 'origin/master'.
> > #
> > # Changes to be committed:
> > #       deleted:    fileX
> > #       modified:   fileA
> > #
> > # Changes not staged for commit:
>
> Is there anything about "fileX" and "fileA"'s names that might be
> relevant? E.g., might they case-fold to the same name or something?
>
> -Peff

← back to recent threads