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

当前回答

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

git commit 'My message'

而不是正确的:

git commit -m 'My message'

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

其他回答

我的错误不同于上面提到的所有错误。如果你不知道为什么你会有一个分离的头,那么你可能不会。我正在使用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的默认状态是您正在“master”分支中工作。在很多情况下,您只需要将其作为主要的工作分支(尽管有些人会变得花哨并做其他事情)。

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

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

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

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

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

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

另一种可能是,您的提交不会影响您所推送的目录。在我的例子中,我有一个这样的结构

- .git
- README.md
- client/
 - package.json
 - example.js
- api/
 - requirements.txt
 - example.py

我做出了一个修改README的承诺。然后运行git子树push——prefix client heroku-client master,得到消息Everything - updated

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

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

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

Git push origin master

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

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

git push origin your-new-branch-name

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