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

当前回答

见上面VonC的回答-我需要一个额外的步骤:

$ 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>

我这么做了,但是当我尝试着去推remoterepo master时,它说 "错误:未能推动一些参考。为了防止您丢失历史记录,非快进更新被拒绝,合并远程更改(例如。'git pull'),然后再推。”

所以我做了'git拉remoterepo master',它发现了一个冲突。我再次做了git reset——hard <commit-id>,将冲突文件复制到备份文件夹,git再次拉出remoterepo master,将冲突文件复制回我的项目,git提交,然后git推送remoterepo master,这一次它成功了。

Git不再说“一切都是最新的”,也不再抱怨“快进”。

其他回答

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

git branch -M <desired branch>

这招对我很管用。

从你的git状态来看,你的情况可能和我的不一样。

但无论如何,这是发生在我身上的事情。我遇到了以下错误:

fatal: The remote end hung up unexpectedly
Everything up-to-date

这里更有意义的信息是遥控器挂了。结果是由于超过了http post缓冲区的大小。解决办法是增加

Git配置http。postBuffer 524288000

我犯过的另一个非常简单却又愚蠢的错误:我只是忘记在提交时添加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'