On one machine git log show it does not get the latest commits from remote repo (after run git pull)
git log --oneline -n 3 origin/develop
5a8e6eb xxx
7547c8a xxx
53294b6 xxx
On another machine, the correct one, it gets the latest commit 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
What strange on the problematic machine is that, my guy told my he actually used git pull origin pull
to get the latest commit 4b45d4b from origin. So when run git status it then shew "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
So what did that happen and how do I fix it?
------- update -----------
I accidentally fixed it without knowing why, so I added write permission to anyone to .git/logs/refs/remotes/origin/develop file
Originally it was
ls .git/logs/refs/remotes/origin/develop
-rw-rw-r-- 1 gongqiang gongqiang 2103 Jan 30 19:07 develop
After adding write permission and run git pull again the problem fixed! But I still don't know why.
----- update 2 ------
The answer I got from VonC cast some light on the issue but there are still questions left unanswered.
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 run git pull
without sudo
---- update 3 -----
I accepted VonC answer and the link he provided in commits https://serverfault.com/questions/26954/how-do-i-share-a-git-repository-with-multiple-users-on-a-machine/27040#27040 is useful.
But I also needed to point out that it is probably impossible (or not worth the effort) to find out why the guy who owned .git/logs/refs/remotes/origin/develop
failed to let git update it when he run git pull.
So a lesson I learned here is when finding git status
said something strange, check with .git/logs/refs/remotes/origin/develop/branch
to verify
It could be a case of having run (as in here) a git pull
as root in the past, changing the permission/ownership of some files.
To be sure to work on a coherent repo, simply clone it again, and check in that clone that git log --oneline -n 3 origin/develop
does return the expected commits.
. 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
I suppose the permission issue (that you fixed) prevented Git to record the latest SHA1 for origin/develop
.
But: that latest commit was still fetched, and your develop
branch was still fast-forwarded to said latest SHA1 (4b45d4b)
Since the local branch points to 4b45d4b, but .git/logs/refs/remotes/origin/develop
still reference the previous commit (because it was not updated properly), you would get
# 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 usesudo git pull
or change the write permission let other can just rungit pull
As explained here, you can:
umask
for the users to 002
, so that new files get created with group-writable permissions.