【发布时间】:2015-04-12 13:20:39
【问题描述】:
我查看了here,但我的问题没有得到解答。 我有一个脚本可以使许多文件保持最新。该存储库由许多 bash 和 python 脚本组成。其中一个脚本在每小时 cronjob 上运行,如下所示:
#! /bin/bash
git fetch origin && git reset --hard origin/dev && git clean -f -d
python -m compileall .
# Set permissions
chmod -R 744 *
基本上它会将所有脚本更新为 GitHub 的当前内容。其中一个脚本是守护程序的代码。当 that 发生变化时,我想重新启动守护程序。 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 的分支,但对于 master-branch(尝试定义 DIFFdmn 变量时)失败并显示以下消息:
fatal: bad revision 'master..origin/master'
非常欢迎任何建议。
【问题讨论】: