git - 如何将git合并失败输出到文件
问题描述
我已经设置了一个脚本来定期 rebase 和合并子分支的开发分支列表中的更改:
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"
该项目是多模块的,因此开发中的任何更改都只会影响其中的一个模块。由于我的合并策略,我不太担心会出现冲突;对 branchlist.txt 中分支的唯一更改应该是从开发分支引入到父模块的更改。但是,我想知道这是否因任何原因而失败。因此,我想将任何错误输出到 error.log,然后将其内容通过电子邮件发送给我自己。
到目前为止,虽然我的 if 语句似乎可以检测故障(使用不存在的分支进行测试),但我无法将控制台输出重定向到日志文件。有没有人做过类似的事情?
解决方案
我想到了; >> error.log
在 echo 语句中使用似乎是一个非常简单的例子:
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"
推荐阅读
- javascript - 如何在 Visual Studio Code 的 Javascript 中查看集合的内容?
- python - 如何在一个循环中创建多个类?
- spring-boot - HTTP get 请求是否使空闲会话处于活动状态?
- java - Selenium testing in a continuous integration pipeline
- java - still Unable to start the daemon process
- java - 如何使用 Javamail 仅检索 40-50 封电子邮件,例如 Gmail?
- c# - 为什么 Linq to Entities 不能将此调用转换为 SQL?
- c# - WPF 的 MVVM 模式:模型与视图模型
- sapui5 - 从一点到另一点的折线图绘制区域不连接使用的 sapui5 vizfram
- vb.net - 解密 AES 时出错。输入数据不是一个完整的块。VB.net