git - 如何将git merge 失败输出到文件

标签 git logging error-handling merge

我已经设置了一个脚本来定期 rebase 和 merge 子分支的开发分支列表中的更改:

while read -r child
do
  echo "Merging development to $child" 2>&1 >> $HOME/logs/git_rebase.log
  git checkout $child
  git status
  echo "Commencing merge" 2>&1 >> $HOME/logs/git_rebase.log

  if [[ ! $(git merge --progress -m 'merge development to child branch' --strategy-option theirs origin/development_does_not_exst 1>/dev/null 2>error.log) ]]; then
    echo "git merge for $child failed with the following log:"
    echo `git log -1`
  else
    echo "merge successful"
  fi

  #git push
done < "../branchlist.txt"

该项目是多模块的,因此开发中的任何更改都只会影响其中的一个模块。由于我的 merge 策略,我不太担心会出现冲突;对 branchlist.txt 中分支的唯一更改应该是从开发分支引入到父模块的更改。但是,我想知道这是否因任何原因而失败。因此,我想将任何错误输出到 error.log,然后将其内容通过电子邮件发送给我自己。

到目前为止,虽然我的 if 语句似乎可以检测故障(使用不存在的分支进行测试),但我无法将控制台输出重定向到日志文件。有没有人做过类似的事情?

最佳答案

我想到了;使用 >> error.log 似乎是一个非常简单的案例在回声语句中:

while read -r child
do
  echo "Merging development to $child" 2>&1 >> $HOME/logs/git_rebase.log
  git checkout $child
  git status
  echo "Commencing merge" 2>&1 >> $HOME/logs/git_rebase.log

  if [[ ! $(git merge --progress -m 'merge development to child branch' --strategy-option theirs origin/development_does_not_exst 1>/dev/null 2>error.log) ]]; then
    echo "git merge for $child failed with the following log:" >> $HOME/logs/error.log
    echo `git log -1` >> $HOME/logs/error.log
  else
    echo "merge successful" >> $HOME/logs/git_rebase.log
  fi

  #git push
done < "../branchlist.txt"

关于git - 如何将git merge 失败输出到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61328874/

相关文章:

git - 用原始仓库中的内容强制覆盖本地文件?

包含 git 命令的 Bash 脚本与 perl 一起使用时的行为有所不同

git - 只克隆 git 中的稳定分支和另一个分支?

svn - 从 SVN 获取有用的报告 - 非代码文件搞乱了统计数据

git - 如何在 gitlab CI 中对 merge 请求应用 if else 条件?

java - 基于分布式 JMS 的日志记录.. 表现平平?

azure - 使用 Azure Function V2 Durable 函数时,ILogger 不会记录到 Application Insights

xml - Linq-Xml [DirectoryNotFound或NullReferenceException]

php - PHP PEAR Mail->发送成功/失败结果?

mysql - 更新多行 - 生成的 SQL 中有错误?