更改存在于被跟踪的分支的上游,但是当我输入git status时,它表明我的本地分支是最新的。这是新的行为,我改变了配置设置,还是有什么错误?

ubuntu@host:/my/repo# git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean


ubuntu@host:/my/repo# git pull
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 11 (delta 6), reused 0 (delta 0)
Unpacking objects: 100% (11/11), done.
From bitbucket.org:my/repo
   1234567..abcdefg  master     -> origin/master
Updating 1234567..abcdefg
Fast-forward
 file1        |  1 -
 file2        | 43 +++++++++++++++++++++++++++++++++++++++++++
 file3        | 21 ++++++++++++---------
 file4        | 21 ++++++++++++---------
 4 files changed, 67 insertions(+), 19 deletions(-)
 create mode 100644 file5

当前回答

我也遇到过类似的问题,我在网上到处搜索解决方案,并试图遵循它们。没有一个对我有效。这些是我针对这个问题采取的步骤。

创建新的repo并将现有代码再次推到新的repo

如果您的存储库中已经有. Git /文件夹,则Git init不会初始化。所以,就你的情况来说,做

(1) rm -rf .git/

2)滚英寸

(3) git远程添加origin https://repository.remote.url

(4) git commit -m“提交信息”

(5) git push -f origin master

请注意,所有git配置,如该存储库的远程存储库,都将在步骤1中清除。因此,您必须重新设置所有远程存储库url。

另外,注意第5步中的-f:远程已经有n次提交的一些代码库,您试图将所有这些更改都提交到一次提交中。因此,强制将更改推到远程是必要的。

其他回答

我也遇到过类似的问题,我在网上到处搜索解决方案,并试图遵循它们。没有一个对我有效。这些是我针对这个问题采取的步骤。

创建新的repo并将现有代码再次推到新的repo

如果您的存储库中已经有. Git /文件夹,则Git init不会初始化。所以,就你的情况来说,做

(1) rm -rf .git/

2)滚英寸

(3) git远程添加origin https://repository.remote.url

(4) git commit -m“提交信息”

(5) git push -f origin master

请注意,所有git配置,如该存储库的远程存储库,都将在步骤1中清除。因此,您必须重新设置所有远程存储库url。

另外,注意第5步中的-f:远程已经有n次提交的一些代码库,您试图将所有这些更改都提交到一次提交中。因此,强制将更改推到远程是必要的。

这是因为您的本地回购还没有与上游遥控器进行检查。为了让它像你期望的那样工作,使用git fetch,然后再次运行git status。

状态告诉你的是,你在名为origin/master的ref后面,它是本地repo中的一个本地ref。在本例中,ref恰好跟踪某个名为origin的远程分支,但是状态并没有告诉您关于远程分支的任何信息。它告诉您有关ref的信息,这只是存储在本地文件系统上的一个提交ID(在这种情况下,它通常在本地repo中的一个名为.git/refs/remotes/origin/master的文件中)。

Git pull做了两个操作;首先,它执行一个git取回来更新远程repo中的提交(更新本地repo中的origin/master ref),然后它执行一个git合并来将这些提交合并到当前分支中。

在你执行取回步骤之前(无论是通过它自己还是通过git pull),你的本地回购无法知道上游是否有额外的提交,git状态只查看你的本地origin/master ref。

当git状态显示为“最新”时,它意味着“与当前分支跟踪的分支一起最新”,在这种情况下意味着“与称为origin/master的本地引用一起最新”。这只等同于“与上次取回的上游状态相一致”,而与“与上游的最新活动状态相一致”是不同的。

Why does it work this way? Well the fetch step is a potentially slow and expensive network operation. The design of Git (and other distributed version control systems) is to avoid network operations when unnecessary, and is a completely different model to the typical client-server system many people are used to (although as pointed out in the comments below, Git's concept of a "remote tracking branch" that causes confusion here is not shared by all DVCSs). It's entirely possible to use Git offline, with no connection to a centralized server, and the output of git status reflects this.

在Git中创建和切换分支(以及检查它们的状态)应该是轻量级的,而不是对集中式系统执行缓慢的网络操作。在设计Git和Git状态输出时,我们假设用户能够理解这一点(如果您已经知道Git是如何工作的,那么太多Git特性才有意义)。随着越来越多不熟悉DVCS的用户采用Git,这种假设并不总是有效的。

“origin/master”指指向分支“origin/master”HEAD提交的引用。 引用是Git对象的一个人类友好的别名,通常是提交对象。 "origin/master"引用仅在git推送到远程(http://git-scm.com/book/en/v2/Git-Internals-Git-References#Remotes)时才会更新。

在项目的根目录中运行:

cat .git/refs/remotes/origin/master

将显示的提交ID与:

cat .git/refs/heads/master

它们应该是相同的,这就是为什么Git说master与origin/master是最新的。

当你奔跑

git fetch origin master

在。Git /objects文件夹下检索新的Git对象。 Git更新了。Git /FETCH_HEAD,现在,它指向所取分支的最新提交。

因此,要查看当前本地分支与从上游获取的分支之间的差异,可以运行

git diff HEAD FETCH_HEAD

导致我这个错误的原因是在错误的文件夹中做git状态…检查这个。