我如何查看我所做的任何尚未推送到远程存储库的本地提交?有时,git状态会显示我的分支是在origin/master之前提交的X,但并不总是这样。

这是我安装Git的bug,还是我遗漏了什么?


当前回答

要查看尚未推送的所有分支上的所有提交,请执行以下操作:

git log --branches --not --remotes

要查看每个分支的最新提交以及分支名称,请执行以下操作:

git log --branches --not --remotes --simplify-by-decoration --decorate --oneline

其他回答

git show

将显示本地提交中的所有差异。

git show --name-only

将显示本地提交id和提交名称。

要查看尚未推送的所有分支上的所有提交,请执行以下操作:

git log --branches --not --remotes

要查看每个分支的最新提交以及分支名称,请执行以下操作:

git log --branches --not --remotes --simplify-by-decoration --decorate --oneline

您可以使用git-log执行此操作:

git log origin/master..

这假设origin是上游远程的名称,master是上游分支的名称。在..之后删除任何修订名称。。暗示HEAD,它列出了尚未推送的新提交。

这不是一个bug。您可能看到的是自动合并失败后的git状态,其中从远程获取更改但尚未合并。

要查看本地回购和远程回购之间的提交,请执行以下操作:

git fetch

这是100%安全的,不会模拟您的工作副本。如果有更改,git状态将显示X在原始/主之前提交。

现在,您可以显示远程而非本地的提交日志:

git log HEAD..origin

如果你有git子模块。。。

无论您是使用gitcherry-v还是gitlogs@{u}-p、 不要忘记通过git子模块foreach--递归“gitlogs@{u}..”。

我使用以下bash脚本来检查所有这些:

    unpushedCommitsCmd="git log @{u}.."; # Source: https://stackoverflow.com/a/8182309

    # check if there are unpushed changes
    if [ -n "$($getGitUnpushedCommits)" ]; then # Check Source: https://stackoverflow.com/a/12137501
        echo "You have unpushed changes.  Push them first!"
        $getGitUnpushedCommits;
        exit 2
    fi

    unpushedInSubmodules="git submodule foreach --recursive --quiet ${unpushedCommitsCmd}"; # Source: https://stackoverflow.com/a/24548122
    # check if there are unpushed changes in submodules
    if [ -n "$($unpushedInSubmodules)" ]; then
        echo "You have unpushed changes in submodules.  Push them first!"
        git submodule foreach --recursive ${unpushedCommitsCmd} # not "--quiet" this time, to display details
        exit 2
    fi