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

当前回答

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

其他回答

我犯过的另一个非常简单却又愚蠢的错误:我只是忘记在提交时添加message -m修饰符。所以我写道:

git commit 'My message'

而不是正确的:

git commit -m 'My message'

注意:它不会抛出任何错误!但是你将不能推送你的提交,而总是让Everything更新

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

现在来看:

$ 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 local-branch-name:remote-branch-name

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

在我的例子中,我有2个远程回购。

git remote -v
originhttps https://asim_kt@...
originhttps https://asim_kt@...
origin  ssh:git@bitbucket.org:...
origin  ssh:git@bitbucket.org:...

两次回购都是一样的。一个是https,另一个是ssh。因此,删除不需要的,(在我的情况下,ssh。因为我使用https,因为ssh不能工作!)为我解决了这个问题。

验证您没有篡改远程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.