git - git pull 后本地分支位于 master 之前

标签 git

我正在一个没有我的 git 凭证的远程服务器上工作,我想从 master pull 。我没有本地提交,我只想更新 native 上的本地存储库以匹配远程存储库(来源)。使用this answer我成功更新了存储库:

my_repo$ git pull https://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2bfab8da7a1b7a092b5bba6baa7b0fcb1bdbf" rel="noreferrer noopener nofollow">[email protected]</a>/my_repo
Password for 'https://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f4998dab81879186b4939d809c8196da979b99" rel="noreferrer noopener nofollow">[email protected]</a>': 
<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://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="711c082e04021403311618051904135f121e1c" rel="noreferrer noopener nofollow">[email protected]</a>/my_repo
Password for 'https://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f89581a78d8b9d8ab89f918c908d9ad69b9795" rel="noreferrer noopener nofollow">[email protected]</a>': 
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://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f79a8ea882849285b7909e839f8295d994989a" rel="noreferrer noopener nofollow">[email protected]</a>/my_repo
Password for 'https://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="412c381e34322433012628352934236f222e2c" rel="noreferrer noopener nofollow">[email protected]</a>': 
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

有人对如何解决这个问题有任何建议吗?关于这是如何发生的以及我将来如何避免这种情况有什么想法吗?

谢谢!

最佳答案

您的来源/主人已过时。

从 URL 中提取数据是一次性的。它不会更新 origin/master。

origin 是与特定 URL 关联的远程存储库的名称。 origin/master 是您最后一次在 origin 上看到 master 分支。 origin/master 只会更新为 git fetchgit pull从原点。这并没有发生。

相反,您通过从某个不同的 URL pull 来更新 master。它可能与 origin 是同一个存储库,但 Git 不知道这一点。您可以通过使用 git remote set-url origin https://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c011533191f091e2c0b051804190e420f0301" rel="noreferrer noopener nofollow">[email protected]</a>/my_repo 更改原始 url 来解决此问题。然后git fetch origin .

参见Remote Branches在 Pro Git 中。

关于git - git pull 后本地分支位于 master 之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62929384/

相关文章:

git - .git 目录是否包含远程密码或 SSH key ?

git - 警告 : You ran 'git add' with neither '-A (--all)' or '--ignore-removal'

git - 添加本地存储库 Github Desktop 整个用户文件

git color.ui 在 Ubuntu 14.10 上不起作用

git - git配置文件可以使用if else语句吗?

Git - 从服务器端 Hook ,是否可以控制客户端可以获取哪些分支

angular - 在 node_modules 下的文件中所做的更改

Xcode 源代码管理 - git add

git - 在 Bamboo 上获取提交文件列表

java - Jgit遍历特定分支的提交内容