Skip to content

Pre-commit hook includes untracked files in commits #1039

@christolis

Description

@christolis

Describe the bug
From the looks of it, whenever one attempts to commit any changes while having untracked files in their working tree, the pre-commit hook also includes these files in the commit. This is somewhat severe because I accidentally shared some untracked configuration files that included a Discord bot token for my testing bot, which was thankfully revoked by Discord itself as soon as I pushed.

Expected behavior
The pre-commit hooks should not include untracked files.

To Reproduce

  1. Make a new file in the working directory that is not tracked by .gitignore.
  2. Ensure that the file is untracked by using git restore --staged <file_name>.
  3. Change a different file's contents, such as a Java source code file that is tracked.
  4. Add the Java source code file to the index and make a commit from it.
  5. Assuming the pre-commit hook was executed with your commit, you should now see the untracked file included in the commit.

Screenshots
image
image
image

Additional context
macOS version: Sonoma 14.3.1 (23D60)
git version: 2.39.3 (Apple Git-145)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions