How do I properly git stash/pop in pre-commit hooks to get a clean working tree for tests?
问题 I\'m trying to do a pre-commit hook with a bare run of unit tests and I want to make sure my working directory is clean. Compiling takes a long time so I want to take advantage of reusing compiled binaries whenever possible. My script follows examples I\'ve seen online: # Stash changes git stash -q --keep-index # Run tests ... # Restore changes git stash pop -q This causes problems though. Here\'s the repro: Add // Step 1 to a.java git add . Add // Step 2 to a.java git commit git stash -q -