gpt4 book ai didi

git - 如果特定文件发生更改,我如何自动收到警告?

转载 作者:IT王子 更新时间:2023-10-29 01:28:43 25 4
gpt4 key购买 nike

我有一个 php 项目,当我从另一个存储库中 pull 并且 composer.lock 文件发生更改时,我应该运行 composer.phar install --dev。 git如何自动警告我/询问我是否要运行此命令?我想某种 Hook 可以解决问题,但我如何才能仅获取有关 pull 入之前和之后发生变化的信息?

最佳答案

这取决于你在 pull 时使用的选项:

无选项:运行 git fetch 和 git merge

你可以自己写post-merge git hook :

This hook is invoked by git merge, which happens when a git pull is done on a local repository. The hook takes a single parameter, a status flag specifying whether or not the merge being done was a squash merge. This hook cannot affect the outcome of git merge and is not executed, if the merge failed due to conflicts.

这个钩子(Hook)应该适合你(将其保存为可执行文件 .git/hooks/post-merge):

#!/bin/sh

CHANGED=`git diff HEAD@{1} --stat -- $GIT_DIR/../composer.lock | wc -l`
if [ $CHANGED -gt 0 ];
then
echo "composer.lock has changed!"
composer.phar install --dev
fi

--rebase : git fetch 和 git rebase 运行

你可以自己写post-checkout git hook :

This hook is invoked when a git checkout is run after having updated the worktree. The hook is given three parameters: the ref of the previous HEAD, the ref of the new HEAD and a flag indicating whether the checkout was a branch checkout or a file checkout

这个钩子(Hook)应该适合你(将其保存为可执行文件 .git/hooks/post-checkout):

#!/bin/sh

CHANGED=`git diff $1 $2 --stat -- $GIT_DIR/../composer.lock | wc -l`
if [ $CHANGED -gt 0 ];
then
echo "composer.lock has changed!"
composer.phar install --dev
fi

更新

这里是 my personal set of git hooks .

关于git - 如果特定文件发生更改,我如何自动收到警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16840184/

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