gpt4 book ai didi

git - 带有本地插件的 github 页面的干净系统

转载 作者:太空狗 更新时间:2023-10-29 13:48:05 26 4
gpt4 key购买 nike

由于 github 不执行(jekyll 的 safe 选项)插件,我正在尝试开发一种小而干净的方法来将编译后的文件部署到分支 master.

通常的源代码在分支 boilerplate 中,我从那里运行 jekyll 并生成代码,一切正常。

在master分支我只有下面的Makefile

default:
git checkout boilerplate
git subtree split -P _site -b site
git checkout master
git merge -X theirs site
git branch -D site

和文件 .nojekyll(我正在使用 here 中的子树命令)

但是这不起作用。它生成包含所有代码的 site 分支,但是当我 merge 到 master 时,它只说:

Already up-to-date.

如何解决这个问题?

我想要完成的是覆盖 master 中的任何现有文件,但不删除分支 site 中不存在的文件(如前面提到的 Makefile.nojekyll,保存在那里很重要)。

注意:我想从头开始,以便保持对部署过程的控制。我不想 1. 引入新的依赖项 2. 使用其他工具。

最佳答案

正如我在 IRC 上所说,我会使用 git hook(git help hooks)

我黑了this脚本真的很快。将它放在 $GIT_DIR/.git/hooks/ 下。

我将其作为从 $_origbranch 提交的post-commit 钩子(Hook)进行了测试,并在另一个分支 ($_destbranch) 上检查了结果。

它应该可以按您的意愿行事。工作正常,所以我希望它适合您或将其引导到正确的方向。

#!/usr/bin/env bash

# executables prefix
_prefix="/usr/bin"
# git executable
_git="$_prefix/git"

# site generation executable
_generate="$_prefix/jekyll"
# options for the generator
_opts=(--no-safe --no-server --no-auto --kramdown)

# branch from which to generate site
_origbranch="master"
# branch holding the generated site
_destbranch="gh-pages"

# directory holding the generated site -- should be outside this repo
_site="$("$_prefix/mktemp" -d /tmp/_site.XXXXXXXXX)"
# the current branch
_currbranch="$(/bin/grep "^*" < <("$_git" branch) | /bin/cut -d' ' -f2)"

if [[ $_currbranch == $_origbranch ]]; then # we should generate the site
# go to root dir of the repo
cd "$("$_git" rev-parse --show-toplevel)"
# generate the site
"$_generate" ${_opts[@]} . "$_site"
# switch to branch the site will be stored
"$_git" checkout "$_destbranch"
# overwrite existing files
builtin shopt -s dotglob
/bin/cp -rf "$_site"/* .
builtin shopt -u dotglob
# add any new files
"$_git" add .
# commit all changes with a default message
"$_git" commit -a -m "updated site @ $(date +"%F %T")"
# cleanup
/bin/rm -rfv "$_site"
# return
"$_git" checkout "$_origbranch"
fi

玩得开心o/


只是更新说这适用于 bash 和 Linux。它可能也可以用 POSIX sh 编写。另外,我相信 mktemp 只是 GNU-coreutils,因此其他系统可能需要替换它。

注意:这仅在您在 $_origbranch 指定的分支中提交时运行。你当然可以改变它。我相信任何人都可以轻松做到这一点。

关于git - 带有本地插件的 github 页面的干净系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6201339/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com