我如何查看我所做的任何尚未推送到远程存储库的本地提交?有时,git状态会显示我的分支是在origin/master之前提交的X,但并不总是这样。
这是我安装Git的bug,还是我遗漏了什么?
我如何查看我所做的任何尚未推送到远程存储库的本地提交?有时,git状态会显示我的分支是在origin/master之前提交的X,但并不总是这样。
这是我安装Git的bug,还是我遗漏了什么?
当前回答
如上所述:
git diff origin/master。。头部
但如果您使用的是gitgui
打开gui界面后,选择“Repository”->在“Visualize History”下
注意:有些人喜欢使用CMDPrompt/Terminal,而有些人则喜欢使用GitGUI(为了简单起见)
其他回答
这给出了origin/master和HEAD之间所有提交的日志:
git log origin/master..HEAD
当HEAD位于主分支上时,这将提供未推送提交的日志。
同样,要查看差异:
git diff origin/master..HEAD
要查看尚未推送的所有分支上的所有提交,请执行以下操作:
git log --branches --not --remotes
要查看每个分支的最新提交以及分支名称,请执行以下操作:
git log --branches --not --remotes --simplify-by-decoration --decorate --oneline
如果你有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
显示本地但非上游的所有提交:
git log @{u}..
@{u} 或@{upstream}表示当前分支的上游分支(有关详细信息,请参阅git-rev-parse-help或git-help修订版)。
git cherry -v
摘自:Git:查看所有未推送的提交或不在其他分支中的提交。