我已经设置了一个脚本来定期 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/