在预先承诺的钩子内执行提交

发布于 2025-02-10 06:00:51 字数 254 浏览 0 评论 0原文

我使用此预钩脚本是因为我运行了一个任务编辑一些类,然后我会自动添加所有编辑的文件并提交它们,但结果是提交已完成,然后添加了文件,但不承诺。似乎在提交之后而不是之前添加了它们。

脚本是:

#!/bin/bash 
pwd
cd application 
echo "Running Lint and Spotless" 
bash gradlew lint spotlessApply
git add *

我该怎么办?

I'm using this pre-hook script because I run a task editing some classes, then I would automatically add all the edited files and commit them, but the result is that the commit is done and then the files are added but not committed. It seems like they are added after the commit and not before it.

The script is this:

#!/bin/bash 
pwd
cd application 
echo "Running Lint and Spotless" 
bash gradlew lint spotlessApply
git add *

How could I do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沙沙粒小 2025-02-17 06:00:51

git-add(1)更改索引。您不应该更改索引
预设脚本。它可能起作用,但这是不确定的行为。

请参阅

fyi,我们试图不进行额外的重新阅读,因为
钩被设计为允许用户验证的机制,但是
不正确,是什么。由于系统最初是
设计,正确使用git的用户将 正在修改
指数。因为这是修改钩子中的索引的错误,所以(1)
重新阅读索引,以防用户犯这样的错误是
浪费资源,以及(2)检查索引以确保其确实如此
再次调用钩子之前和之后不变也是浪费
资源。

在某些情况下我们重新阅读索引可能是一个错误,
这增加了混乱,但没有增加其他。

git-add(1) changes the index. You’re not supposed to change the index in
the pre-commit script. It might work but it is undefined behavior.

See:

FYI, we tried not to do the extra re-reading, because pre-commit
hook was designed to be a mechanism to allow users to validate, but
not correct, what gets committed. As the system originally was
designed, users who correctly use Git would not be modifying the
index. Because it is an error to modify the index in the hook, (1)
re-reading the index just in case the user commits such a mistake is
waste of resources, and (2) checking the index to make sure it did
not change before and after invoking the hook, again, is also waste
of resources.

It may have been a mistake that we re-read the index in some case,
which adds to the confusion, but not others.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文