在git子模块中显示未推送的提交 [英] Display unpushed commits in git submodules

查看:103
本文介绍了在git子模块中显示未推送的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道周围已经有一些问题,例如这一个.就我而言:

I know there is some questions already around there as this one. In my case:

假设我有一个带有子模块SR2的仓库R1.

Let's say I have a repo R1 with a submodule SR2.

  1. 我在SR2中执行子模块提交.
  2. 我在R1中提交子模块更新
  3. 我在R1中推送子模块更新
  4. 我忘记推送SR2

然后克隆存储库R1的任何人都会得到引用不是树错误,因为显然子模块提交修订版仅在本地可用.

Then anyone who will clone repository R1 will get a reference is not a tree error, because obviously the submodule commit revision is only available locally currently.

如果我随后在R1存储库中键入 git status ,则不会警告我子模块位于远程存储库之前.

If I then type git status in R1 repository, nothing warns me about the fact that my submodule is ahead of the remote repository.

是否有任何递归检索状态的方法?

If there any way to retrieve status recursively?

推荐答案

您可以尝试 git子模块foreach 命令:

You can try a git submodule foreach command:

git submodule foreach --recursive 'git status  && echo'

此答案中,您还有其他命令可以显示子模块的状态,以了解正在进行的更改.

You have other commands to show you the status of submodules in this answer, for changes in progress.

OP Cqnqrd 提到为了具有更好的可读性,我将其调整为以下别名:

To have better readability, I tweaked it a bit to the following alias:

多行:

gss_command='git -c color.status=always status -s | \
             sed "s/^\(.*\)/\t\1/g" && git branch -v | \
             grep -E "ahead|behind" | \
             sed -r "s/[ *]\s(\S*).*(\[(ahead|behind).+?\]).*/\t\1 \2/g"' 

alias gs="git rev-parse --show-toplevel && \
          $gss_command && \
          git submodule foreach --recursive '$gss_command'"

单线:

gss_command='git -c color.status=always status -s | sed "s/^\(.*\)/\t\1/g" && git branch -v | grep -E "ahead|behind" | sed -r "s/[ *]\s(\S*).*(\[(ahead|behind).+?\]).*/\t\1 \2/g"' 

alias gs="git rev-parse --show-toplevel && $gss_command && git submodule foreach --recursive '$gss_command'"

这篇关于在git子模块中显示未推送的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆