我有一个远程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等),如果其中一个失败了,你的提交也失败了。这在控制台中应该是显而易见的,但是由于来自钩子的错误可能会充斥控制台中,因此您可能没有意识到您的提交将无法工作,直到预提交钩子被配置为忽略问题或问题得到解决。

其他回答

在我的例子中,问题的原因是我在git bash中的符号链接文件夹中执行git推/拉命令! 我在一个git项目中的符号链接文件夹中指向另一个git项目,git的pull/push命令正在回答Everything - latest。 当我将(cd)移动到实际文件夹的路径(不是通过符号链接)时,git的推/拉命令起作用了。

我今天遇到了这个问题,它和其他答案没有任何关系。以下是我所做的以及我是如何解决它的:

我的一个仓库最近移动了,但我有一个本地副本。我从我的本地“主”分支分支出去,并做了一些更改——然后我记得存储库已经移动了。我使用git remote set- URL origin https://<my_new_repository_url>来设置新的URL,但是当我推它时,它只会说“一切都是最新的”,而不是推我的新分支到master。

我最终通过重新基于origin/master,然后使用显式分支名称来解决它,就像这样:

$ git rebase <my_branch> origin/master
$ git push origin <my_branch>

我希望这能帮助任何有我同样问题的人!

我们需要添加文件,并提交已经更改/添加的文件 执行以下命令

Git添加。或者git add nameoffile #,它将添加项目中现有的文件

Git commit -m "first commit" #提交项目中的所有文件

Git push origin master

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

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

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

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

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