git 不一致 本地和服务器_Git:无法获得远程和本地/服务器相同

bd96500e110b49cbb3cd949968f18be7.png

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...

解决方案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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值