【问题标题】:Local and remote are identical. Then I pull from remote, and local is one commit ahead. What?本地和远程是相同的。然后我从远程拉,本地是一个提交。什么?
【发布时间】:2015-07-12 10:58:41
【问题描述】:

我偶尔会被 git 的行为所困扰。据我了解我在下面做了什么,我在远程存储库上获取了当前版本的“公共”分支,并用它替换了我拥有的所有东西。我正在做的任何事情都不应该在那里。

然后我再次从远程存储库中提取“公共”。瞧!现在我在本地提前提交。

你能告诉我发生了什么吗?

[edit] 人们非常恰当地问我使用的是什么版本的 git。 2.1.4 我在下面的代码部分添加了一个 git --version。

rhedin@RHEDIN1-T430 ~/gogo/portal/gogo_flightTracker (public)
$ git status
# On branch public
# Your branch is ahead of 'origin/public' by 1 commit.
#
nothing to commit (working directory clean)

rhedin@RHEDIN1-T430 ~/gogo/portal/gogo_flightTracker (public)
$ git reset --hard origin/public
HEAD is now at 30cdb42 Remove O/D from window display if 640px window.innerWidth or less

rhedin@RHEDIN1-T430 ~/gogo/portal/gogo_flightTracker (public)
$ git status
# On branch public
nothing to commit (working directory clean)

rhedin@RHEDIN1-T430 ~/gogo/portal/gogo_flightTracker (public)
$ git pull origin public
\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" get: -c: line 0: syntax error near unexpected token `('
\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" get: -c: line 0: `\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" get'
Username for 'https://github.com':
Password for 'https://rickhedin@github.com':
\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" store: -c: line 0: syntax error near unexpected token `('
\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" store: -c: line 0: `\"C:/Program Files (x86)/GitExtensions/GitCredentialWinStore/git-credential-winstore.exe\" store'
From https://github.com/gogoit/gogo_flightTracker
* branch            public     -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Fast-forwarded public to 2e65060cef06715081e54f776e0f7269e8d65ba7.

rhedin@RHEDIN1-T430 ~/gogo/portal/gogo_flightTracker (public)
$ git status
# On branch public
# Your branch is ahead of 'origin/public' by 1 commit.
#
nothing to commit (working directory clean)

rhedin@RHEDIN1-T430 ~/gogo/portal/gogo_flightTracker (public)
$

rhedin@RHEDIN1-T430 /cygdrive/c/work/150502
$ git --version
git version 2.1.4

【问题讨论】:

标签: git


【解决方案1】:

git-pull - 从另一个存储库或本地分支获取并集成

简单来说, git pull 执行 git fetch 后跟 git merge

您可以随时通过git fetch 更新refs/remotes/<remote>/ 下的远程跟踪分支。此操作永远不会更改您在refs/heads 下的任何本地分支,并且无需更改您的工作副本即可安全地执行此操作。我什至听说有人在后台定期运行git fetch(尽管我不建议这样做)。

git pull 是您可以使用其远程版本更新本地分支的方法,同时更新您的其他远程跟踪分支。

场景:

假设存在以下历史并且当前分支是“master”:

 A---B---C master on origin
     /
    D---E---F---G master
    ^
    origin/master in your repository

然后“git pull”将从远程master 分支获取并重放更改,因为它从本地主分支(即E)分离,直到其当前提交(C)在主分支之上并记录结果在一个新的提交中,连同两个父提交的名称和来自用户描述更改的日志消息。

  A---B---C origin/master
 /         \
D---E---F---G---H master

Git 文档:

git-pull

git-fetch

git-merge

【讨论】:

  • 这一切都正确且有道理,除了,他显然已经完成了一次提取(通过拉取),然后是 git reset --hard 以使他自己的分支与原点匹配.然后他又做了一个pull,它又做了一个fetch,它应该是一个空操作,然后是另一个merge,它也应该是一个空操作。不过,这假设 git 版本 >= 1.8.4。
  • CloudFreezer 的回答非常详细和清晰,我赞成。 (我认为在您的最后一张图中,您打算 D 从 B 分支,C 分支到 H,而不是 G。)但是,我认为 Torek 的评论是正确的。我使我的分支与远程存储库中的分支相同,然后执行一系列无操作。结果应该与远程存储库相同。
  • 我的 git 版本是 2.1.4 。
猜你喜欢
  • 2013-05-17
  • 1970-01-01
  • 2016-01-25
  • 2019-08-25
  • 1970-01-01
  • 2018-09-19
  • 2011-05-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多