我看了here但我的问题没有得到解答。 我有一个脚本可以保持许多文件是最新的。存储库由许多bash和python脚本组成。其中一个脚本运行在每小时的cronjob,看起来像这样:检测Git中文件的更改
#! /bin/bash
git fetch origin && git reset --hard origin/dev && git clean -f -d
python -m compileall .
# Set permissions
chmod -R 744 *
本质上,它更新所有脚本的GitHub的当前内容。其中一个脚本是守护进程的代码。当那更改我想重新启动守护进程。 git
命令的输出中没有关于哪些文件被更改的线索。那么,我该怎么做?
使事情复杂化,我认为python -m compileall
使git
认为所有的文件已经改变。但我发现this question似乎工作。
[编辑]附加奖金的问题添加: 基于由@下文给出的答案behzad.nouri我已修改代码从而:
#! /bin/bash
branch=$(cat ~/bin/gitbin.branch)
git fetch origin && \
DIFFdmn=$(git --no-pager diff --name-only $branch..origin/$branch -- ./testdaemon/daemon.py) && \
DIFFlib=$(git --no-pager diff --name-only $branch..origin/$branch -- ./testdaemon/libdaemon.py) && \
git reset --hard origin/dev && git clean -f -d
python -m compileall .
# Set permissions
chmod -R 744 *
if [[ -n "$DIFFdmn" ]]; then
logger -t 02-update-scripts "daemon has changed"
./testdaemon/daemon.py restart
fi
if [[ -n "$DIFFlib" ]]; then
logger -t 02-update-scripts "daemonlib has changed"
./testdaemon/daemon.py restart
fi
其中~/bin/gitbin.branch
应包含分支到同步的名称。这适用于所谓dev
分支,但(试图定义DIFFdmn
变量时),该消息为master
分枝失败:
fatal: bad revision 'master..origin/master'
任何建议都非常欢迎。
谢谢。这似乎工作。我会在'git reset'之前插入'DIFF = ...'。这样我可以检测到文件更改并在编译后重新启动守护进程。 – Mausy5043
但是,似乎这不适用于master-branch(用'master..origin/master'替换'dev..origin/dev'。对于这种情况的任何建议? – Mausy5043