我已经在预提交 Hook 中安装了 mvn java-formatter:format
任务。此任务将格式化 java 源代码。
pushd src/ > /dev/null
mvn java-formatter:format
RETVAL=$?
if (($RETVAL == 1)); then
exit 1
fi
popd > /dev/null
我需要附加新格式化的源文件来提交。我该怎么做?
最佳答案
pre-commit hook应该能够包含一个 git add
,以修改即将提交的索引。
参见示例“git pre-commit
hook, add file into index”。
尝试 git add -A :/.
(参见“Add as if from the root folder of the repository”)
如果您只需要添加已经暂存的文件,那么您需要:
- 或者add files per pattern
- 或过滤nly the staged files ,如
git add $(git diff --name-only --cached)
.
关于git - 在预提交 Hook 期间再次暂存文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31532143/