【问题标题】:How can I automate copy operations before Git commits?如何在 Git 提交之前自动执行复制操作?
【发布时间】:2022-06-15 22:27:31
【问题描述】:

背景:我想创建一个 Jekyll 协作博客。我创建了一个子树来将它的协作部分与站点的其余部分隔离开来。但是,当这些进入 _posts 时,Jekyll 呈现站点时会忽略其中的任何 blob。

现在,我要做的是将特定文件夹 (_posts/assets/) 中的所有内容复制到 assets/,以便 Jekyll 可以在渲染站点后使用这些文件。

我正在使用 Gitlab 来托管 Jekyll,所以我需要在 推送到 Gitlab 之前进行此操作,所以我现在通过 do 手动执行此操作

cp -R _posts/assets/* assets
git add -A
git commit "New files for articles"

我可以把它放在预提交钩子上,这样我就可以自动化这个过程吗?有什么建议吗?

【问题讨论】:

  • 看看githooks,可以让脚本在推送结束前自动运行

标签: git gitlab jekyll githooks


【解决方案1】:

看看你可以使用的 git 钩子:

$ cd ~/project_name
$ ls -1 .git/hooks/
applypatch-msg.sample
commit-msg.sample
fsmonitor-watchman.sample
post-update.sample
pre-applypatch.sample
pre-commit.sample
pre-merge-commit.sample
prepare-commit-msg.sample
pre-push.sample
pre-rebase.sample
pre-receive.sample
update.sample

您是说要执行预推送脚本(在推送到 GitLab 之前)。所以,创建一个pre-push git hook 脚本,并使其可执行。

$ touch .git/hooks/pre-push
$ chmod +x .git/hooks/pre-push

然后,将您的命令放入该文件中。

.git/hooks/pre-push:

#!/bin/sh

cp -R _posts/assets/* assets
git add -A
git commit "New files for articles"

【讨论】:

    猜你喜欢
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 2020-03-13
    • 1970-01-01
    • 2010-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多