What can cause not staged files to be commited?

Viewed 133

I've edited two files. I want to commit part of the changes in one of the files, so I've added those changes to the staging area. Things looks correct:

$ git status
On branch feature/foo
Your branch is up to date with 'origin/feature/foo'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   src/App/Foo.php

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   docker-compose.yml
        modified:   src/App/Foo.php

However, when I eventually commit, the other file gets included too in the commit!

$ git commit -m Spelling
[feature/foo ad0c758a6] Spelling
 2 files changed, 5 insertions(+), 3 deletions(-)
$ git status
On branch feature/foo
Your branch is ahead of 'origin/feature/foo' by 1 commit.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   src/App/Foo.php

no changes added to commit (use "git add" and/or "git commit -a")

What am I doing wrong?

I'm using git 2.25.1 in Ubuntu 20.04 inside WSL2 on Windows 10 Pro. Files are stored in the Ubuntu filesystem and I run commands in Ubuntu bash.

1 Answers

One way to have automatic actions on git commit is through a hook.

Check if you have any active hooks on your repo :

ls .git/hooks

and see if there is a pre-commit script there.

Related