I'm trying to create a precommit hook to prevent committing merge conflicts accidentally... basically cancelling the commit when it includes >>>>
. I've found multiple viable-looking approaches, but I am wondering why the "official" approach is not working (trying to use https://stackoverflow.com/a/27150330/752916 which refers to https://github.com/git/git/blob/v2.26.0/templates/hooks--pre-commit.sample#L49). When I execute this command, I am presented with usage information (see below) instead of an error. I expected something like this leftover conflict marker
because I have a test conflict in my codebase. I am not looking for alternatives, those are readily available on SO already. I just want to know why this command doesn't work.
$ git diff-index --check --cached $against --
usage: git diff-index [-m] [--cached] [<common-diff-options>] <tree-ish> [<path>...]
common diff options:
-z output diff-raw with lines terminated with NUL.
-p output patch format.
Debugging info:
$ git --version
git version 2.25.0.windows.1
I tried this in Git Bash and Windows Powershell, same result in both.