所以我想编写一个脚本,自动将我的所有更改上传到 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
}