可以将文件挂在提交中吗?

发布于 2025-01-30 18:47:59 字数 539 浏览 4 评论 0原文

可以将挂钩(与pre-commit.com)添加到提交中吗?

我的用例:我确实在Jupyter笔记本电脑中工作。在提交时,我想生成 git-add 是提交中任何ipynb文件的HTML版本。

例如,提交挂钩类似:

- repo: local
  hooks:
    - id: nb-as-html
      name: nb-as-html
      stages: [commit]
      language: system
      verbose: false
      pass_filenames: false
      always_run: true
      entry: find devtools \( -name \*.ipynb -not -name \*checkpoint.ipynb \) -type f -exec jupyter nbconvert --to HTML {} \; 

并以某种方式将文件添加到提交中。

我该怎么做?还是不打算为此预先承诺?

Can pre-commit hooks (with pre-commit.com) add files to a commit?

My use case: I do work in jupyter notebooks. On commit, I want to generate and git-add an html version of any ipynb files in the commit.

Eg a commit hook like:

- repo: local
  hooks:
    - id: nb-as-html
      name: nb-as-html
      stages: [commit]
      language: system
      verbose: false
      pass_filenames: false
      always_run: true
      entry: find devtools \( -name \*.ipynb -not -name \*checkpoint.ipynb \) -type f -exec jupyter nbconvert --to HTML {} \; 

and add the file somehow to the commit.

How do I do this? Or is pre-commit not intended for this?

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

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

发布评论

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

评论(1

兮子 2025-02-06 18:47:59

可能的可以在pre-commit挂钩中添加文件,但不建议这样做。 GIT开发人员通常会解决此工作流程中提出的问题,但是他们并不乐意如此,这不是受到鼓励的事情。此外,用户不会期望您这样做,并且可能不满意您这样做。由于克隆存储库时(因为这将允许执行任意代码)时,挂钩不会克隆,因此您也不能假设其他贡献者会运行它们。

此外,您应该避免将生成的文件完全放在存储库中。这往往会膨胀存储库,并在融合或rebase沿线发生时引起冲突。您最好将此文件生成CI并将其上传到其他地方。

It is possible to add files in a pre-commit hook, but it is not recommended to do so. The Git developers will usually fix issues that come up with this workflow, but they don't do so gladly and it's not something that is encouraged. In addition, the user will not have expected you to do this and may not be pleased that you have done so. Since hooks aren't cloned when you clone the repository (since that would allow executing arbitrary code), you also can't assume other contributors will run them.

In addition, you should avoid committing generated files to the repository altogether. That tends to bloat the repository and cause conflicts when merges or rebases happen down the line. You'd be better off generating this file in CI and uploading it somewhere else.

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