git 本地仓库从远程获取最新提交但未能记录它

git local repo got the latest commit from remote but failed to record it

在一台机器上 git 日志显示它没有从远程仓库获取最新提交(在 运行 git 拉取之后)

git log --oneline -n 3 origin/develop
5a8e6eb xxx
7547c8a xxx
53294b6 xxx

在另一台机器上,正确的那台,它获得最新的提交 4b45d4b

git log --oneline -n 4 origin/develop
4b45d4b (origin/gq_dev, origin/develop) xxx
5a8e6eb (tag: dev_12) xxx
7547c8a xxx
53294b6 (origin/zsf) xxx

有问题的机器上奇怪的是,我的人告诉我他实际上使用 git pull origin pull 从 origin 获取最新的提交 4b45d4b。因此,当 运行 git 状态时,它会显示 "Your branch is ahead of 'origin/develop' by 1 commit."

git status
# On branch develop
# Your branch is ahead of 'origin/develop' by 1 commit.
...

git show
commit 4b45d4bfff7c54169fea7343c5b4f020be556d0a

这是怎么回事,我该如何解决?

--------更新------------

我不小心修复了它,不知道为什么,所以我给任何人添加了对 .git/logs/refs/remotes/origin/develop 文件的写权限

原来是

ls .git/logs/refs/remotes/origin/develop
-rw-rw-r-- 1 gongqiang     gongqiang      2103 Jan 30 19:07 develop

添加写入权限后 运行 git 再次拉取问题已解决!但是我还是不知道为什么。

----- 更新 2 ------

我从 VonC 那里得到的答案对这个问题有所启发,但仍有一些问题没有得到解答。

  1. ls .git/logs/refs/remotes/origin/develop 只显示 gongqiang 这个人原来有写权限(b/c 是他 运行 git 查看 develop 分支)。 运行 git 拉取最新提交 4b45d4b 也是他。
  2. 在我 运行 git status 说 "Your branch is ahead of 'origin/develop' by 1 commit" 之后我检查了这个文件。它没有记录最新的拉动。但是因为正是这个人拥有该文件,并且 git 拉取了 运行。为什么git记录失败?
  3. 我更改此文件以向任何人写入权限,然后 运行 git 再次拉动以修复它。但我真的怀疑这是 "correct" 修复。

从这里提出的另一个问题是,因为这是一个分支,会有更多人git拉(集成分支做测试)。使用 sudo git pull 还是更改写权限 let other 运行 git pull 没有 sudo

更好?

----更新 3 -----

我接受了 VonC 的回答,他在提交 https://serverfault.com/questions/26954/how-do-i-share-a-git-repository-with-multiple-users-on-a-machine/27040#27040 中提供的 link 很有用。

但我还需要指出,可能不可能(或不值得)找出为什么拥有 .git/logs/refs/remotes/origin/develop 的人在他 运行git拉.

所以我在这里学到的一个教训是,当发现git status说了一些奇怪的事情时,请与.git/logs/refs/remotes/origin/develop/branch核实

可能是以前有运行 (as in here) a git pull root,改变了一些文件的permission/ownership。

为了确保在连贯的存储库上工作,只需再次克隆它,然后检查 git log --oneline -n 3 origin/develop 执行 return 预期提交的克隆。

. But I wanted to know why git status said "your branch is ahead of 'origin/develop' by 1 commit." while we used git pull to get that commit from origin

我想权限问题(已修复)阻止了 Git 记录 origin/develop 的最新 SHA1。
但是:仍然获取了最新的提交,并且您的 develop 分支仍然被快速转发到所述最新的 SHA1 (4b45d4b)

因为本地分支指向 4b45d4b,但是 .git/logs/refs/remotes/origin/develop 仍然引用之前的提交(因为它没有正确更新),你会得到

# Your branch is ahead of 'origin/develop' by 1 commit.

Another question raised from here is since this is a branch that more one person will git pull (the integration branch to do test).
Is it better to use sudo git pull or change the write permission let other can just run git pull

作为 explained here,您可以:

  • 要么更改组的权限,然后将用户的 umask 更改为 002,以便创建具有组可写权限的新文件。
  • 或为群组设置扩展 ACL,以便群组成员可以 read/write/access 任何已经存在的文件。