git fetch : 输出有更新

git fetch : output that there was an update

更新时的预期行为如下(恕我直言):

$ git fetch -p
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From AAA
   a061e40..2058467  develop    -> origin/develop

这对我在项目 A 中有效。从相同的 git 主机、相同的本地系统、不同的项目(例如,项目 B)获取数据,git fetch 没有输出。我认为它在某个时间点发生了变化,但我无法弄清楚原因是什么。

项目 B,git fetch 输出:

$ git checkout develop
Switched to branch 'develop'
Your branch is up-to-date with 'origin/develop'.
$ git fetch -pv
From BBB
 = [up to date]      develop                       -> origin/develop
$ git status
On branch develop
Your branch is behind 'origin/develop' by 2 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

项目 A 配置:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    precomposeunicode = true
[remote "origin"]
    url = AAA
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "develop"]
    remote = origin
    merge = refs/heads/develop

$ git branch -vv
* develop    a061e40 [origin/develop: behind 1]

项目 B 配置:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    precomposeunicode = true
[remote "origin"]
    url = BBB
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "develop"]
    remote = origin
    merge = refs/heads/develop

$ git branch -vv
* develop                       7d1afd6 [origin/develop: behind 2]

如何将项目 B 中 git fetch 的行为改回项目 A 中的行为?

您可以使用 .git\refs\remotes\origin\develop 查看您当前的开发分支提交 ID。

如果两次提交相同,则说明您的本地开发分支确实是最新的。

如果两个提交不同,你可以使用git log --oneline --decorate --graph --all检查developorigin/develop是否指向相同的提交id。或者您可以使用 git branch -D developgit checkout develop,然后在远程仓库上进行更改,然后再次执行 git fetch