[英]Local branch ahead of master after git pull
I am working on a remote server that does not have my git credentials, and I want to pull from master.我正在一个没有我的 git 凭据的远程服务器上工作,我想从 master 中提取。 I have no local commits, I just want to update the local repository on this machine to match the remote repository (origin).
我没有本地提交,我只想更新这台机器上的本地存储库以匹配远程存储库(来源)。 Using this answer I managed to update the repository:
使用这个答案,我设法更新了存储库:
my_repo$ git pull https://my_user@github.com/my_repo
Password for 'https://my_user@github.com':
<some updates....>
Indeed, after this action, the local repository was updated to include all the commits exactly as on the remote repository.实际上,在此操作之后,本地存储库已更新为包含与远程存储库完全相同的所有提交。
But, for some reason I cannot fathom, the local repository became ahead of master, and I can't find a way to fix it.但是,由于某种原因,我无法理解,本地存储库变得领先于 master,我找不到修复它的方法。 How is that possible???
这怎么可能???
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.
Also, when I use git log
I see this strange outcome, that corresponds to my branch being ahead of master, but does not correspond to "reality":另外,当我使用
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
Anyone has any advice on how to fix this?有人对如何解决这个问题有任何建议吗? And any thoughts on how this happened and how I can avoid this in the future?
以及关于这是如何发生的以及我将来如何避免这种情况的任何想法?
Thanks!谢谢!
Your origin/master is out of date.您的来源/主人已过时。
Pulling from a URL is a one-off.从 URL 拉出是一次性的。 It does not update origin/master.
它不会更新原点/主控。
origin is your name for a remote repository associated with a particular URL. origin 是与特定 URL 关联的远程存储库的名称。 origin/master is the last time you saw the master branch on origin.
origin/master 是您最后一次在 origin 上看到 master 分支。 origin/master will only be updated with a
git fetch
or git pull
from origin. origin/master 只会使用
git fetch
或git pull
from origin 进行更新。 This hasn't happened.这还没有发生。
Instead, you've updated master by pulling from some different URL.相反,您已经通过从一些不同的 URL 中提取来更新 master。 It might be the same repository as origin, but Git does not know that.
它可能与原始存储库相同,但 Git 不知道这一点。 You can fix that by changing the origin url with
git remote set-url origin https://my_user@github.com/my_repo
.您可以通过使用
git remote set-url origin https://my_user@github.com/my_repo
更改原点 url 来解决此问题。 Then git fetch origin
.然后
git fetch origin
。
See Remote Branches in Pro Git.请参阅 Pro Git 中的远程分支。
Thanks to @Schwern's answer , I was able to understand the problem.感谢@Schwern 的回答,我能够理解这个问题。
How I solved it:我是如何解决的:
Revert "local" commits using this wonderful website:使用这个精彩的网站恢复“本地”提交:
git reset --hard @{u}
Make sure there are no existing credentials on this repository on this machine by removing credentials from gitconfig
:通过从
gitconfig
中删除凭据,确保此计算机上的此存储库中没有现有凭据:
sudo subl ~/.gitconfig // or any other text editing instead of subl
Pull "regularly", that is, without specifying my credentials: “定期”拉动,即不指定我的凭据:
my_repo$ git pull Username for 'https//github.com': my_user Password for 'https://my_user@github.com': <updates...>
And now everything is fine...现在一切都很好...
Thanks again @Schwern for explaining the problem!再次感谢@Schwern 解释问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.