git 您的分支领先于 X 提交的“origin/master”。如何找到 X 提交?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14154524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:58:49  来源:igfitidea点击:

Your branch is ahead of 'origin/master' by X commits. How to find the X commits?

gitgit-commitgit-log

提问by Habeeb Perwad

I was checking the X commits using the following command:

我正在使用以下命令检查 X 提交:

git log --author=<my-name> -<X>

But the problem is that I accidentally pulled code from another repository and added the commits from the repository to my local git repository.

但问题是我不小心从另一个存储库中提取了代码,并将该存储库中的提交添加到了我的本地 git 存储库中。

So I cannot use the above command since the new commits contains some other authors.

所以我不能使用上面的命令,因为新提交包含一些其他作者。

回答by tobiasbayer

The command

命令

git log origin/master..master

shows the commits that are on masterbut not on origin/master.

显示在 onmaster但不在 on的提交origin/master

回答by David Culp

I made an alias for this command that lists the commits that have not been pushed.

我为这个命令创建了一个别名,列出了尚未推送的提交。

git log --branches --not --remotes --decorate --oneline

git log --branches --not --remotes --decorate --oneline

which is a variation of a command cxreg posted in Viewing Unpushed Git Commits.

这是查看未推送的 Git 提交中发布的命令 cxreg 的变体。

Lots of other useful ways to parse the commit tree in that post as well.

还有很多其他有用的方法来解析该帖子中的提交树。

回答by LopSae

The treeish..treeishnotation works exactly to see the commits that are present in the second reference, but not in the first one. From the git log help:

treeish..treeish符号完全适用于查看第二个引用中存在的提交,但不是第一个引用中的提交。从 git log 帮助:

A regular D..M computes the set of commits that are ancestors of M, but excludes the ones that are ancestors of D. This is useful to see what happened to the history leading to M since D, in the sense that "what does M have that did not exist in D".

常规 D..M 计算作为 M 祖先的提交集,但排除作为 D 祖先的提交。这有助于查看自 D 以来导致 M 的历史发生了什么,从某种意义上说,“ M 有在 D 中不存在的”。

Using this with either git logor git showyou can output a list that contains a single line for each commit pressent in the D..Mdifference:

使用它git log或者git show你可以输出一个列表,其中包含每个提交D..M差异的单行:

git show -s --oneline branch..HEAD

or

或者

git log --oneline branch..HEAD

Pair that with a word count and you can output exactly the number of commits you are looking for:

将其与字数配对,您可以准确输出您正在寻找的提交数:

git log --oneline branch..HEAD | wc -l

回答by user1834095

This question has be answered already in another post:

这个问题已经在另一篇文章中回答了:

git log origin/master..HEAD

(see Viewing Unpushed Git Commits)

(请参阅查看未推送的 Git 提交

回答by amorfis

I use this:

我用这个:

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

It shows commits as a graph, with all the branches and their names.

它将提交显示为一个图表,包含所有分支及其名称。

My advice is to create alias for it in ~/.gitconfig

我的建议是在 ~/.gitconfig 中为它创建别名