我如何查看我所做的任何尚未推送到远程存储库的本地提交?有时,git状态会显示我的分支是在origin/master之前提交的X,但并不总是这样。
这是我安装Git的bug,还是我遗漏了什么?
我如何查看我所做的任何尚未推送到远程存储库的本地提交?有时,git状态会显示我的分支是在origin/master之前提交的X,但并不总是这样。
这是我安装Git的bug,还是我遗漏了什么?
当前回答
如果你有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
其他回答
这是我的可移植解决方案(shell脚本也适用于Windows,无需额外安装),它显示了所有分支与原始分支的区别:git fetch log
示例输出:
==== branch [behind 1]
> commit 652b883 (origin/branch)
| Author: BimbaLaszlo <bimbalaszlo@gmail.com>
| Date: 2016-03-10 09:11:11 +0100
|
| Commit on remote
|
o commit 2304667 (branch)
Author: BimbaLaszlo <bimbalaszlo@gmail.com>
Date: 2015-08-28 13:21:13 +0200
Commit on local
==== master [ahead 1]
< commit 280ccf8 (master)
| Author: BimbaLaszlo <bimbalaszlo@gmail.com>
| Date: 2016-03-25 21:42:55 +0100
|
| Commit on local
|
o commit 2369465 (origin/master, origin/HEAD)
Author: BimbaLaszlo <bimbalaszlo@gmail.com>
Date: 2016-03-10 09:02:52 +0100
Commit on remote
==== test [ahead 1, behind 1]
< commit 83a3161 (test)
| Author: BimbaLaszlo <bimbalaszlo@gmail.com>
| Date: 2016-03-25 22:50:00 +0100
|
| Diverged from remote
|
| > commit 4aafec7 (origin/test)
|/ Author: BimbaLaszlo <bimbalaszlo@gmail.com>
| Date: 2016-03-14 10:34:28 +0100
|
| Pushed remote
|
o commit 0fccef3
Author: BimbaLaszlo <bimbalaszlo@gmail.com>
Date: 2015-09-03 10:33:39 +0200
Last common commit
可以使用为日志传递的参数,例如--oneline或--patch。
我使用以下别名仅获取已提交但尚未推送(针对当前分支)的文件列表(以及状态)
git config --global alias.unpushed \
"diff origin/$(git name-rev --name-only HEAD)..HEAD --name-status"
那么只需执行以下操作:
git unpushed
git cherry -v
摘自:Git:查看所有未推送的提交或不在其他分支中的提交。
我以前做过一次提交,没有推送到任何分支,也没有远程或本地。只是承诺。其他答案对我没有任何作用,但有:
git reflog
在那里我找到了我的承诺。
这给出了origin/master和HEAD之间所有提交的日志:
git log origin/master..HEAD
当HEAD位于主分支上时,这将提供未推送提交的日志。
同样,要查看差异:
git diff origin/master..HEAD