【问题标题】:How I can save git commit messages to the file?如何将 git commit 消息保存到文件中?
【发布时间】:2013-12-16 07:02:26
【问题描述】:

想要提交、修复错误并将更改发送到 GIT 存储库,但消息数超过了 Unix 命令行中显示的行数,因此我无法读取错误消息。如何将 GIT 提交消息保存到文件或增加 Unix 命令行上显示的行数?

似乎在这个 GIT 构建中使用了钩子,它显示如下消息:

/usr/local/scripts/act check test-file --file-www/htdocs/doms/netflow/scripts/read.php --verbose
Logging output to toLogs
[ OK ]   php lint for /www/htdocs/doms/netflow/scripts/read.php - no errors
[ OK ]   code-wrangler audit-php for /www/htdocs/doms/netflow/scripts/read.php - no errors
[ OK ]   No Errors Detected

谢谢。

【问题讨论】:

  • “提交消息”是什么意思?你在用git log吗?如果是这样,您可以使用j 向下滚动,也可以使用git log > log.txt 将其输出到文件
  • 我更新了我的问题,很抱歉没有一次性提供所有信息。

标签: git unix


【解决方案1】:

要为 git 命令重定向 stdout 和 stderr,您可以这样做:

git commit -m "your message" 2>&1 | cat >> log &

(如“Trying to redirect 'git gc' output”中的建议)
或者:

script -q -c 'git commit -m "your message"' > log
script -q -c 'git commit -m "your message"' | sed 's/\r.*//g' > log

您可以尝试停用寻呼机以确保获得完整的日志

 git --no-pager log --decorate=short --pretty=oneline > alog.txt
 # or
 GIT_PAGER="cut -c 1-${COLUMNS-80}" git log

在“How to make git log not prompt to continue?”查看更多信息

(这与您可以为长行设置的寻呼机设置不同,如“git diff - handling long lines?”)

【讨论】:

  • 感谢您的回答! --no-pager 不工作,但我认为这是意料之中的,因为我使用git commit,而不是git log
  • @SergeyNovikov 好吧,那更多的是重定向问题。我已经编辑了我的答案。
猜你喜欢
  • 2019-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-17
  • 1970-01-01
  • 2013-01-22
  • 2020-06-20
相关资源
最近更新 更多