[英]Get first not pushed commit message
How can I get first not pushed git commit message on a branch ? 我如何才能首先获得未在分支上推送的git commit消息?
Suppose I have 3 commits on a branch "new_branch" 假设我在分支“ new_branch”上进行了3次提交
third_commit
second_commit
first_commit
I want to execute one git command to return only the first commit message not the commit id. 我想执行一个git命令,仅返回第一个提交消息,而不返回提交ID。 Thanks
谢谢
If new_branch
ist checked out and the remote branch is marked as the upstream branch of new_branch
(either because you got it from the remote or it as marked with --set-upstream
when pushing) this should work for you: 如果
new_branch
ist已签出,并且远程分支被标记为new_branch
的上游分支(或者因为您是从远程获得的,或者是在推送时标有--set-upstream
标记),那么这将为您工作:
git show --quiet --pretty=%B $(git rev-list @{u}..HEAD | tail -n 1)`
@{u}
references the upstream branch, so rev-list will give you all commits in your local branch, that are not in the remote branch. @{u}
引用上游分支,因此rev-list将为您提供本地分支中所有不在远程分支中的提交。 tail -n 1
gives you only the lowest (=earliest) of those. tail -n 1
仅给您最低的(=最早的)。 git show
would show that commit, where --quiet
hides the diff and --pretty=%B
only prints the commit message of that commit. git show
将显示该提交,其中--quiet
隐藏差异,而--pretty=%B
仅打印该提交的提交消息。
If new_branch
is not checked out you can replace HEAD
with new_branch
and @{u}
with the reference to the remote branch (eg origin/new_branch
). 如果未检出
new_branch
则可以用对远程分支的引用(例如origin/new_branch
)将HEAD
替换为new_branch
和@{u}
。 The later one would also help, if the upstream of new_branch
is not configured. 如果未配置
new_branch
的上游,则后一种方法也将有所帮助。
git reflog
will show all the commit name. git reflog
将显示所有提交名称。 see the git page 看到git页面
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.