简体   繁体   English

git pull 后 master 之前的本地分支

[英]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 fetchgit 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:我是如何解决的:

  1. Revert "local" commits using this wonderful website:使用这个精彩的网站恢复“本地”提交:

     git reset --hard @{u}
  2. 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
  3. 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.

相关问题 Git-创建本地分支后拉原点主机 - Git - pull origin master after creating local branch 为什么合并后本地 master 分支比远程 master 领先一个? - Why is the local master branch one ahead of remote master after merge? 在拉取请求之后,“您的分支比 'origin/master' 领先 N 次提交” - After Pull Request, “Your branch is ahead of 'origin/master' by N commits” 在本地 GIT 上,当本地 master 领先或与 origin/master 相比位于单独的分支时,如何将 master 与 origin/master 合并? - On local GIT, how to merge master with origin/master when local master is ahead or on separate branch compared to origin/master? 精通Git,如何将更改放入新的本地分支机构? - Git ahead of master, how to put the changes into a new local branch? Git 将 origin/master 分支拉到 local/master,当在 local/develop - Git pull origin/master branch to local/master, when in local/develop Git分支领先于原点/主节点 - Git branch is ahead of origin/master 在git revert之后将当前分支置于master之前 - Putting the current branch ahead of master after git revert 为什么在git审核后我的分支机构领先于原产地/母公司? - Why my branch is ahead of origin/master after git review? 在本地分支中没有合并的本地分支中的Git pull master - Git pull master in local branch which is not merge in master
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM