![仅获取 stdout 和 stderr,而不实际运行命令](https://linux22.com/image/1021947/%E4%BB%85%E8%8E%B7%E5%8F%96%20stdout%20%E5%92%8C%20stderr%EF%BC%8C%E8%80%8C%E4%B8%8D%E5%AE%9E%E9%99%85%E8%BF%90%E8%A1%8C%E5%91%BD%E4%BB%A4.png)
所以我想编写一个脚本,自动将我的所有更改上传到 github。我管理了所有事情,除了一件事。我想从 github 命令中记录 stdout 和 stderr,而无需实际添加、提交或将文件推送到 github。我想在输出写入日志文件后执行此操作。代码如下:
function fnSave {
fnLogWriter "" 1
fnLogWriter "git add stdout:"
git add -A >> ${myLogFileWithPath} 2>&1
fnLogWriter "" 1
fnLogWriter "git commit stdout:"
git commit -m ${myCommitMessage} >> ${myLogFileWithPath} 2>&1
fnLogWriter "" 1
fnLogWriter "git push stdout:"
git push -u origin ${myCurrentBranch} >> ${myLogFileWithPath} 2>&1
}
不用担心 fnLogWriter,这是一个自定义函数。路径正确,一切正常。文件创建时,git -add 下面的日志文本在文件中,但由于先上传,其余部分不在 github 上
答案1
所有的 git 命令都有一个--dry-run
选项,因此您只能获得这样的输出:
function fnSave {
fnLogWriter "" 1
fnLogWriter "git add stdout:"
git add --dry-run -A >> ${myLogFileWithPath} 2>&1
fnLogWriter "" 1
fnLogWriter "git commit stdout:"
git commit --dry-run -m ${myCommitMessage} >> ${myLogFileWithPath} 2>&1
fnLogWriter "" 1
fnLogWriter "git push stdout:"
git push --dry-run -u origin ${myCurrentBranch} >> ${myLogFileWithPath} 2>&1
}