Search code examples
git

Unexpected "Nothing specified, nothing added" message in Git


Recently, Git (2.46.0, homebrew, macos 14.6.1) has started behaving like this:

$ git add README.md

...

$ git commit -m "Update README file"

Nothing specified, nothing added.
hint: Maybe you wanted to say 'git add .'?
hint: Disable this message with "git config advice.addEmptyPathspec false"
[master 3d0e36e] Update README file
 1 file changed, 27 insertions(+), 22 deletions(-)

$ git log
commit 3d0e36e8c6bb589201dbd9670b5282bb40115b40 (HEAD -> master)
Author: redacted <[email protected]>
Date:   Sat Aug 31 18:24:52 2024 +0100

    Update README file

i.e.:

  • I add a file
  • I write a commit message and it tells me there's nothing to commit
  • It commits the change anyway

The docs imply you would only see that message when running git add:

addEmptyPathspec Shown when the user runs git add without providing the pathspec parameter.


Solution

  • Pretty sure you've got a pre-commit hook trying to do an add, "Nothing specified, nothing added" is an add message, nothing else issues it, I just checked.

    To test this yourself without needing a git grep in the git source, git reset @^ to undo the commit but not the add, then git commit -n (or the long-form spelling --no-verify) to skip your commit hooks.