我有一个远程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

当前回答

我找到了一条捷径。转到你的。git文件夹,打开HEAD文件,把你所在的分支改回master。例如:ref: refs/heads/master

其他回答

另一种需要注意的重要情况是:git的默认状态是您正在“master”分支中工作。在很多情况下,您只需要将其作为主要的工作分支(尽管有些人会变得花哨并做其他事情)。

不管怎样,这只是一个分支。所以我可能会遇到这样的情况:

我的活动分支实际上不是主分支. ...但我习惯执行命令:git push(我之前已经做过git push origin master,所以这是一个快捷方式)。

所以我习惯性地将主分支推到共享回购…对我来说,这可能是一件干净的好事……

但是我已经忘记了我一直在做的改变还没有在主分支!!

因此,每次我尝试git push,当我看到“Everything up to date”时,我都想尖叫,但当然,这不是git的错!它是我的。

因此,我将我的分支合并到master中,然后执行push,一切都恢复正常。

你是在用一个分离的脑袋工作吗?

如:

指示您的最新提交不是分支头。

警告:以下是一个git重置——很难:如果你想保存当前修改的文件,请确保首先使用git stash。

$ git log -1
# note the SHA-1 of latest commit
$ git checkout master
# reset your branch head to your previously detached commit
$ git reset --hard <commit-id>

正如git签出手册页中提到的(重点是我的):

有时能够签出不在分支顶端的提交是有用的。 最明显的例子是在标记的官方发布点检出提交,就像这样:

$ git checkout v2.6.18

Earlier versions of git did not allow this and asked you to create a temporary branch using the -b option, but starting from version 1.5.0, the above command detaches your HEAD from the current branch and directly points at the commit named by the tag (v2.6.18 in the example above). You can use all git commands while in this state. You can use git reset --hard $othercommit to further move around, for example. You can make changes and create a new commit on top of a detached HEAD. You can even create a merge by using git merge $othercommit. The state you are in while your HEAD is detached is not recorded by any branch (which is natural --- you are not on any branch). What this means is that you can discard your temporary commits and merges by switching back to an existing branch (e.g. git checkout master), and a later git prune or git gc would garbage-collect them. If you did this by mistake, you can ask the reflog for HEAD where you were, e.g. $ git log -g -2 HEAD


虽然git push表示“所有内容都是最新的”,但从技术上讲,你仍然可以推送一个分离的HEAD,正如Jonathan Benn在评论中所指出的那样

 git push origin HEAD:main

您必须指定目标分支,因为源不是分支,也没有上游目标分支。

验证您没有篡改远程URL。

I just wanted to also mention that I ran into this after enabling Git as a CVS in a local Jenkins build configuration. It appears that Jenkins checked out the most recent commit of the branch I gave it and also reset my remote to correspond to the paths I gave it to the repo. Had to checkout my feature branch again and fix my origin remote url with 'git remote set-url'. Don't go pointing a build tool to your working directory or you'll have a bad time. My remote was set to a file path to my working directory, so it naturally reported everything up-to-date when I attempted to push changes with the same source and destination.

超级罕见-但仍然:在Windows上,它可能是打包refs有一个带有一个字母大小写的分支(即dev/mybranch),而refs文件夹有另一个大小写(即dev/mybranch)当核心。Ignorecase设置为true。

解决方案是手动从wrapped -refs中删除相关行。没找到更干净的解决办法。

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

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

git push origin your-new-branch-name

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