【发布时间】:2020-11-05 19:24:26
【问题描述】:
我正在一个没有我的 git 凭据的远程服务器上工作,我想从 master 中提取。我没有本地提交,我只想更新这台机器上的本地存储库以匹配远程存储库(来源)。使用this answer 我设法更新了存储库:
my_repo$ git pull https://my_user@github.com/my_repo
Password for 'https://my_user@github.com':
<some updates....>
确实,在此操作之后,本地存储库已更新为包含所有提交完全,就像在远程存储库上一样。
但是,由于某种原因,我无法理解,本地存储库变得领先 master,我找不到修复它的方法。这怎么可能???
my_repo$ git status
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
my_repo$ git push https://my_user@github.com/my_repo
Password for 'https://my_user@github.com':
Everything up-to-date
my_repo$ git status
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
my_repo$ git pull https://my_user@github.com/my_repo
Password for 'https://my_user@github.com':
From https://github.com/my_repo
* branch HEAD -> FETCH_HEAD
Already up to date.
另外,当我使用git log 时,我看到了这个奇怪的结果,这对应于我的分支领先于master,但不对应于“现实”:
my_repo$ git log --pretty=oneline
09ee1f2 (HEAD -> master) Latest commit on master
b6433fb Another commit from master
31da031 Another commit from master
85b95ae (origin/master, origin/HEAD) Another commit from master which was the head before pulled
有人对如何解决这个问题有任何建议吗?有什么想法是如何发生的以及我将来如何避免这种情况?
谢谢!
【问题讨论】:
-
你是在推到你要拉的同一个地方吗?
git remote -vv的输出是什么? -
是的@WilliamPursell,它是同一个仓库。
git remote -vv给出的输出是origin https://github.com/my_repo.git (fetch) \n origin https://github.com/my_repo.git (push),和我的个人电脑上的输出完全一样 -
让我们来看看小事:当你开始工作时,你的 repo 已经在 85b95ae 上,你创建了三个本地提交,你拉了(没有什么可以拉的),你的主人领先。会是这样吗?我会说是的,因为“已经是最新的”。在拉取消息中。
-
@DaemonPainter 实际上我没有进行本地提交。这就是奥秘。现在“领先于 master”的 3 个新提交是我从 原始 master 中提取的提交。我在我的个人电脑上进行了这些提交......:|
-
也许edit() 你的问题要更加强调这一点。有多少台机器参与其中?我现在要说三个:远程、本地和您的个人。此外,您说 85b95ae 是拉动前的头部,进一步确认您的本地人在那里。但是,以防万一,进入远程并检查哪个是 HEAD 提交。请打印 SHA
标签: git