Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 用于检查git提交是否是一天中的第一次提交的脚本_Linux_Git_Shell_Travis Ci - Fatal编程技术网

Linux 用于检查git提交是否是一天中的第一次提交的脚本

Linux 用于检查git提交是否是一天中的第一次提交的脚本,linux,git,shell,travis-ci,Linux,Git,Shell,Travis Ci,任务如下: 在构建服务器(travis ci)上,我想检查推送是否是白天的第一次 如果是,将主分支复制到另一个分支(每日快照) 致意在构建脚本结束时,您可以将日期转储到文件中。一开始,你可以比较一下。它可能看起来像: currentDate=$(date +%D) isFirstBuildOfTheDay=true if [ -e last_date_build.txt ]; then if [ $currentDate = $(cat last_date_build.txt) ];

任务如下:

  • 在构建服务器(travis ci)上,我想检查推送是否是白天的第一次
  • 如果是,将主分支复制到另一个分支(每日快照)

致意

在构建脚本结束时,您可以将日期转储到文件中。一开始,你可以比较一下。它可能看起来像:

currentDate=$(date +%D)
isFirstBuildOfTheDay=true

if [ -e last_date_build.txt ]; then
  if [ $currentDate = $(cat last_date_build.txt) ]; then
      isFirstBuildOfTheDay=false
  fi
fi

if $isFirstBuildOfTheDay; then
   #Take a daily snapshot
fi

#Perform the actual build

echo $currentDate > last_date_build.txt

编辑以将注释考虑在内:

如果你不能保存文件,那么把这个日期记录在标签上怎么样

例如:

currentDate=$(date +%F)
dailyTag=daily_$currentDate
if ! git rev-parse $tag >/dev/null 2>&1; then
  #Take a daily snapshot
  git tag $dailyTag
  git push --tags
fi

不管是否有新的提交,为什么不只添加一个夜间标记呢?两者都不是很有用,因为Git可以轻松地恢复到任何时间点。我需要及时将提交更改推送到该标记,我只有一个在提交时触发的构建服务器,没有cron:/Track您的post receive hook中的日期?感谢您的建议,但我无法转储文件--vm已被销毁。。。我需要处理提交日志。我更新了我的答案,提出了另一个没有更好的解决方案!我可以在提交描述中使用日期吗?我不想垃圾发送我们的标签,但想不出一个简单的方法来做,特别是因为每个构建应该能够完成最后一个提交构建。我的解决方案建议使用文件或标签。我不知道如何用commit description清晰地完成它,但可能是因为我在这里缺乏想象力。我以类似“git log--since=today.midnight | grep commit | wc-l”的内容结束,如果是“1”,我就开始推送