我有一个远程gitosis服务器和一个本地git存储库,每次我在代码中做大的更改时,我也会将更改推到该服务器。

但是今天我发现,即使我有一些本地更改并提交到本地存储库,当运行git push origin master时,它说“一切都是最新的”,但当我使用git clone在远程服务器上签出文件时,它不包含最新的更改。我只有一个名为“master”的分支机构和一个名为“origin”的远程服务器。

PS: 这是git在运行ls-remote时显示的内容,我不确定它是否有帮助

$ git ls-remote origin
df80d0c64b8e2c160d3d9b106b30aee9540b6ece        HEAD
df80d0c64b8e2c160d3d9b106b30aee9540b6ece        refs/heads/master
$ git ls-remote .
49c2cb46b9e798247898afdb079e76e40c9f77ea        HEAD
df80d0c64b8e2c160d3d9b106b30aee9540b6ece        refs/heads/master
df80d0c64b8e2c160d3d9b106b30aee9540b6ece        refs/remotes/origin/master
3a04c3ea9b81252b0626b760f0a7766b81652c0c        refs/tags/stage3

当前回答

我也有同样的问题。在我的例子中,这是因为必须为同一个遥控器命名。它创建了标准的“起源”,但我已经使用“github”作为我的遥控器很长一段时间了,所以它也在那里。只要我移除了“origin”遥控器,错误就消失了。

其他回答

当我在Github上合并一个分支并继续在本地开发时,我自己也遇到了这种情况。我的解决办法与其他人的建议略有不同。

首先,我从我的旧本地分支(我不能推)上分支了一个新的本地分支。然后我将新的本地分支推送到原始服务器(Github)。即。

$ git checkout -b newlocalbranch oldlocalbranch
$ git push origin newlocalbranch

这得到的变化显示在Github上,虽然在newlocalbranch而不是oldlocalbranch。

另一种可能是您在.gitignore文件中命名了一个被排除的目录。这样新的提交就不会被推送。我碰巧命名了一个目录来忽略“search”,但那也是我源代码树中的一个目录。

我的问题是本地分支与远程分支的名称不同。我可以通过以下方法来推动:

$ git push origin local-branch-name:remote-branch-name

(来源:https://penandpants.com/2013/02/07/git-pushing-to-a-remote-branch-with-a-different-name/)

这里,我的解决方案与上面的不同。我还没有弄清楚这个问题是怎么发生的,但我解决了它。有点出乎意料。

现在来看:

$ git push origin use_local_cache_v1 Everything up-to-date $ git status On branch test Your branch is ahead of 'origin/use_local_cache_v1' by 4 commits. (use "git push" to publish your local commits) ...... $ git push fatal: The upstream branch of your current branch does not match the name of your current branch. To push to the upstream branch on the remote, use git push origin HEAD:use_local_cache_v1 To push to the branch of the same name on the remote, use git push origin test $ git push origin HEAD:use_local_cache_v1 Total 0 (delta 0), reused 0 (delta 0) remote:

对我有效的命令是

$git push origin HEAD:use_local_cache

(希望你们能尽快走出困境)

也许你想在当地开一家新分公司?

必须显式地推送一个新的本地分支:

git push origin your-new-branch-name

这是关于少年犯的一件事…你克隆一个回购,创建一个分支,提交一些更改,推送…“一切都是最新的”。我理解为什么会发生这种情况,但这种工作流程对新人非常不友好。