问题
git status
on the server returns:
On branch develop
Your branch is ahead of 'origin/develop' by 14 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
My goal is to get the git branch on gitlab.com and on the server synchronized. When I look at the difference between the two, the commits that it states that remote on the server is ahead, are commits I believe are actually there on gitlab.com.
I did the following on the server:
git status
returns "Your branch is ahead of 'origin/develop' by 14 commits."git reset --soft HEAD~1
git status
now returns "branch is up-to-date with origin/develop. Changes to be committed:" and then a list with changes.git reset --hard
git status
now returns "branch is up-to-date with origin/develop. Nothing to commit."git log
is missing the latest commits and therefore essentially disagrees with step 5.git pull origin develop
This pulls various changes (how is that possible since step 5 returns "up-to-date"...?).git status
returns the original message "ahead of 'origin/develop' by 14 commits" and I'm back where I started.
I don't understand this. How can the server return to being ahead of gitlab.com (step 8) after pulling from gitlab...? I removed all changes on the server and just did a pull...
回答1:
- git status returns "Your branch is ahead of 'origin/develop' by 14 commits."
This does not mean that your branch is ahead of the remote (origin). origin/develop
is a local branch. It is a remote tracking branch, but it is not updated automatically. The way to update it is to say git fetch
— something that you never report having said.
- git reset --soft HEAD~1
- git status now returns "branch is up-to-date with origin/develop. Changes to be committed:" and then a list with changes.
- git reset --hard
- git status now returns "branch is up-to-date with origin/develop. Nothing to commit."
- git log is missing the latest commits and therefore essentially disagrees with step 5.
I don't know why you did any of that. You chopped off a bunch of commits from develop
. Why would you deliberately lame your local branch?
Also, you are wrong about 6: having lamed develop
, you have caused it to agree with origin/develop
, which is still sitting there unchanged. They are absolutely in agreement.
- git pull origin develop This pulls various changes (how is that possible since step 5 returns "up-to-date"...?).
It's possible because, once you have lamed develop
, the remote is ahead of you. So you pull from the remote, and now your develop
gets the commits from the remote that you just chopped off it.
- git status returns the original message "ahead of 'origin/develop' by 14 commits" and I'm back where I started.
Because you still have not updated origin/develop
by saying git fetch
.
So basically you've gone around in circles because (a) you don't know what origin/develop
is and (b) you keep not updating origin/develop
. Update it! Say git fetch
, and you will then discover through git status
what the actual situation is. I suspect that you will find that you are completely up to date and all is well.
来源:https://stackoverflow.com/questions/61732555/git-unable-to-get-remote-and-local-server-the-same