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

当前回答

我有多个遥控器。除了一个人以外,所有人都正确地推了,所以我知道我没有一个独立的头或提交问题。

结果,我不小心给了两个遥控器相同的URL。复制URL的远程失败,因为我正在推到一个已经被推到的URL !

使用git remote -v显示了我的远程列表和它们的url,在那里我意识到问题。

重置失败的远程到其正确的URL修复了这个问题: Git remote set-url <remote-name> <correct-url>

其他回答

呃. .如果你是一个git新手,你确定你在git push之前有git commit吗?我第一次就犯了这个错误!

另一个可能罕见的情况,但值得一提的是-当你在本地环境中配置了预提交钩子(扫描代码以查找错误,例如Python安全,flake8, black, isort, bandit等),如果其中一个失败了,你的提交也失败了。这在控制台中应该是显而易见的,但是由于来自钩子的错误可能会充斥控制台中,因此您可能没有意识到您的提交将无法工作,直到预提交钩子被配置为忽略问题或问题得到解决。

我的错误不同于上面提到的所有错误。如果你不知道为什么你会有一个分离的头,那么你可能不会。我正在使用git commit和git push进行自动驾驶,还没有读取git commit的输出。结果,这是一条错误消息,因为我忘记了-am。

[colin] ~/github/rentap.js [master] M % git commit 'figured out some more stuff with the forms in views and started figuring out row and mode in models so also made matching routes and controllers'
error: pathspec 'figured out some more stuff with the forms in views and started figuring out row and mode in models so also made matching routes and controllers' did not match any file(s) known to git.
[colin] ~/github/rentap.js [master] M % git push
Enter passphrase for key '/home/colin/.ssh/id_ecdsa': 
Everything up-to-date

通过把-am放在我经常做的地方来修复它:

[colin] ~/github/rentap.js [master] M % git commit -am 'figured out some more stuff with the forms in views and started figuring out row and mode in models so also made matching routes and controllers'

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

如:

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

警告:以下是一个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

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

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

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

git push origin your-new-branch-name

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