git - 在 Git 状态上选择远程

标签 git

我可以使用 git status 来告诉我是在 Remote 前面还是后面:

git status
On branch master
Your branch is ahead of 'bean/master' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean

哪个适合解析:

needs_push = "Your branch is ahead" in std.out
needs_pull = "Your branch is behind" in std.out

但是,当使用多个 Remote 时,事情就会失败,因为 git status 只显示一个 Remote 的结果(上面示例中的 bean)并且不接受任何参数选择 Remote 。

有什么方法可以指定要显示详细信息的 Remote 吗? 即给定两个 Remote ,我的本地存储库/分支是否需要推送和/或 pull ,如果需要,哪个?通过“需要 pull ”我的意思是远程包含我没有的提交,通过“需要推送”我的意思是我有远程没有的提交。 (即假设没有任何深奥的线性工作流程。)

如果我可以使用 URL 而不是名称会更好,但据我所知,git 只能在调用 git remote update 后描述 Remote 。

最佳答案

方法A

也许更容易(取决于您想要实现的目标):

将输出第一个分支在远程分支之后的提交数

将输出第一个分支在远程分支之前的提交数

使用此命令,您可以列出各种您可能想知道的事情。但是你要明白gitrevisions首先。

$ git rev-list --count <some git revision specification>

方法B

根据您要对这些信息执行的具体操作,以下内容可能会派上用场:

输出看起来像这样:

# branch.oid <hash>
# branch.head example-branch
# branch.upstream origin/example-branch-developer-1
# branch.ab +0 -1

您最感兴趣的最后一行格式如下:

# branch.ab +<ahead> -<behind>

关于git - 在 Git 状态上选择远程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46828384/

相关文章:

php - git update-index --assume-unchanged 文件的 git pull 错误

Git:在提交之前在提交之后创建新分支

git - 推送到远程私有(private)仓库: fatal: repository not found

Git rebase忽略 merge 提交

git - 为什么不建议将 git 存储库放在 Dropbox 文件夹中?

node.js - 我是否提交由 npm 5 创建的 package-lock.json 文件?

git - gpg 无法签署数据致命 : failed to write commit object [Git 2. 10.0]

xcode - 在现有的 Xcode 项目中使用 Git

git - 如何配置 git 在一个 'remote' 中从 http pull 并通过 ssh 推送?

git - 是否可以在不重写历史记录的情况下精简 .git 存储库?