如何获取通过 git pull 添加到本地存储库的新提交的数量?

发布于 2025-01-12 08:28:26 字数 123 浏览 1 评论 0原文

当我运行 git pull 时,我想知道有多少提交添加到我的本地存储库,最好仅在当前分支上。有没有办法获取这些信息?

git-pull 的手册似乎没有说明任何相关内容,而且我还没有在网上找到任何专门处理此问题的线程。

When I run git pull, I'd like to know how many commits the pull added to my local repository, preferably on the current branch only. Is there a way to get this information ?

The manual for git-pull doesn't seem to indicate anything about this, and I haven't found any thread online specifically dealing with this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

懵少女 2025-01-19 08:28:26

Git pull 不会给你这些信息。

但你可以做的是:

git fetch
git status

On branch master
Your branch is behind 'origin/master' by 11 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

这将为您提供有关将拉取多少提交的信息。

Git pull doesn't give you that information.

But what you can do is:

git fetch
git status

On branch master
Your branch is behind 'origin/master' by 11 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

And this will give you information about how many commits will be pulled.

眼藏柔 2025-01-19 08:28:26

继续@Grzegorz的答案,但完全替代了 git pull ,并且对我的问题有更合适的答案(仅请求新提交的数量),这是我想出的命令

git fetch ; git status -bsu no ; git merge

:输出类似这样的内容:

## master...origin/master [behind 6]
Updating 050a8c7..b8a6c2e
Fast-forward
 2.4/debian-10/Dockerfile | 2 +-
 2.5/debian-10/Dockerfile | 2 +-
 2.6/debian-10/Dockerfile | 2 +-
 README.md                | 6 +++---
 4 files changed, 6 insertions(+), 6 deletions(-)

在括号 [behind 6] 之间的文本中给出新提交的数量,这意味着 6 个新提交已从远程拉取到当前分支。

PS:当然,如果默认情况下使用git pull --rebase,则必须将git merge更改为git rebase

Continuing on @Grzegorz' answer, but with a complete substitute for git pull and more appropriate answer to my question (requesting only the number of new commits), here is the command I came up with:

git fetch ; git status -bsu no ; git merge

Which will output something like this:

## master...origin/master [behind 6]
Updating 050a8c7..b8a6c2e
Fast-forward
 2.4/debian-10/Dockerfile | 2 +-
 2.5/debian-10/Dockerfile | 2 +-
 2.6/debian-10/Dockerfile | 2 +-
 README.md                | 6 +++---
 4 files changed, 6 insertions(+), 6 deletions(-)

giving you the number of new commits in the text between brackets [behind 6] meaning 6 new commits have been pulled to the current branch from the remote.

PS: Of course, if you git pull --rebase by default, you would have to change git merge with git rebase.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文