【问题标题】:How to store all the lines of a output of git push command for bitbucket如何存储bitbucket的git push命令输出的所有行
【发布时间】:2025-12-17 05:10:02
【问题描述】:
git push -u origin <branch>

当您为 bitbucket 运行此命令时,它会为您提供类似的输出,

Counting objects:
remote:
remote: Create pull request for <branch>
remote: https://bitbucket.com/...

但是当我尝试将该输出存储在变量中并打印该变量时,它会给我这样的输出,

a=$(git push -q -u origin <branch>)
echo $a
Branch <branch> set up to track remote branch <branch> from origin.

我想存储上面的输出,或者我只想将拉取请求 URL 存储到一个变量中。

拉取请求 URL 是首选选项。 谢谢

【问题讨论】:

  • 小提示:它是 bitbucket.org。 Bitbucket.com 只是重定向。

标签: git shell bitbucket


【解决方案1】:

您可以将git 输出存储到文件中:

git push -u origin mybranch &> /tmp/git-push-origin-mybranch.txt

然后将内容存储到变量中

git_result=$(cat /tmp/git-push-origin-mybranch.txt)

【讨论】:

  • 有没有办法只得到那个网址? @gogaz