Search code examples
gitmacosmacos-high-sierra

Git on MacOS restoring file after commit when doing a git rm


Running MacOs High Sierra 10.13.4 and git version 2.17.0.

Here's my workflow:

  • git rm ./some/file.out
  • Run git status see that the delete for ./some/file.out is waiting to be committed
  • Check ls ./some/ and see the file has been deleted
  • Run git commit and see message one file was deleted

However:

  • If I then run git status I see the file still there but untracked.
  • When run git clean -df on the untracked file it gets removed and doesn't return.

I've also tried

  • Delete the file with non-git rm ./some/file.out
  • Run git add . then git commit and see file deleted message
  • Run git status and shows file still present, but untracked

It seems this just started happening recently.

Here's my git config:

credential.helper=osxkeychain
core.hookspath=/Users/myname/.git_hooks
core.excludesfile=/Users/myname/.gitignore
user.email=myname@somewhere.com
color.ui=true
color.branch=true
color.status=true
color.diff=true
color.interactive=true
color.grep=true
color.pager=true
color.decorate=true
color.showbranch=true
alias.pt=!git push -u origin `git rev-parse --abbrev-ref HEAD`
alias.co=checkout
alias.cob=checkout -B
alias.b=branch
alias.bd=branch -D

What could potential be going on--specifically, has anyone else seen something like this and found it to be git related?

Just deleting files (non-git repo files) in the terminal does not have this behavior.


Solution

  • Poked around my ~/.git_hooks. Looks like a script being called in my ~/.git_hooks/pre-commit.d folder is to blame.

    Not sure what exactly the script is doing (or was supposed to do), but when I remove the script the git rm && git commit functionality works as expected--no more files risen from the dead!