gpt4 book ai didi

git - 从 git push 远程响应中提取 url

转载 作者:行者123 更新时间:2023-12-04 03:13:47 25 4
gpt4 key购买 nike

当我将更改连同通常的统计信息一起推送到我们的 Bitbucket 服务器时,服务器会响应几行以“remote:”开头的行。其中一行包含一个指向推送分支的差异的 URL,并创建一个 pull 请求。我目前突出显示 URL 并将其复制/粘贴到浏览器窗口中以创建我的 pull 请求,但我希望加快该过程。有没有办法提取 URL 并将其传递给“剪辑”以将其作为 git 别名的一部分保存到剪贴板?

我还考虑尝试使用当前分支名称和远程 URL 的组合重新创建 URL,但是远程 URL 和 pull 请求 URL 之间存在一些差异,因此提取 URL 似乎更容易而不是重新创建 URL。创造它。

Counting objects: 47, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (45/45), done.
Writing objects: 100% (47/47), 12.81 KiB | 0 bytes/s, done.
Total 47 (delta 40), reused 3 (delta 2)
remote:
remote: Create pull request for feature/somefeature:
remote: https://code.ourbitbucketserver.com/projects/myteam/repos/somerepo/compare/commits?sourceBranch=refs/heads/feature/somefeature
remote:
To https://code.ourbitbucketserver.com/scm/myteam/somerepo.git
* [new branch] feature/somefeature -> feature/somefeature
Branch feature/somefeature set up to track remote branch feature/somefeature from origin.

解决方案
bcurrent = "!git rev-parse --abbrev-ref HEAD"
publishold = "!f() { git push -u ${1-origin} $(git bcurrent); }; f"
publishnew = "!f() { git push -u ${1-origin} $(git bcurrent) --progress 2>&1 | awk '/^remote:.*compare/ { system(\"echo \" $2 \" | clip\") } { print }'; }; f"
bcurrentpublishold别名是我开始时的引用。

接受的答案使我朝着正确的方向前进。在我想解释的过程中,我遇到了一些问题。
  • git push通过 stderr 而不是 stdout 输出一些消息(包括 url)。所以我们必须用 2>&1 重定向 stderr .还添加了 --progress标记,因此即使 git 未连接到控制台,它也会输出 stderr,因为我们将输出通过管道传输到 awk。见 git stderr output can't pipe
  • clip命令行不接受参数,输入必须通过管道输入。
  • 由于我的 git 别名是一个 shell 函数,我不得不转义 system 中的双引号。称呼。
  • 最佳答案

    您可以使用 awk在你的别名中。以下将完全打印输出并附加调用 clip以 URL 作为参数:

    echo 'Counting objects: 47, done.
    Delta compression using up to 8 threads.
    Compressing objects: 100% (45/45), done.
    Writing objects: 100% (47/47), 12.81 KiB | 0 bytes/s, done.
    Total 47 (delta 40), reused 3 (delta 2)
    remote:
    remote: Create pull request for feature/somefeature:
    remote: https://code.ourbitbucketserver.com/projects/myteam/repos/somerepo/compare/commits?sourceBranch=refs/heads/feature/somefeature
    remote:
    To https://code.ourbitbucketserver.com/scm/myteam/somerepo.git
    * [new branch] feature/somefeature -> feature/somefeature
    Branch feature/somefeature set up to track remote branch feature/somefeature from origin.' | awk '/^remote:.*compare/ { system("clip " $2) } { print }'

    关于git - 从 git push 远程响应中提取 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42927782/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com