git push 说“一切都是最新的";即使我有本地更改 [英] git push says "everything up-to-date" even though I have local changes
问题描述
我有一个远程 gitosis 服务器和一个本地 git 存储库,每次我对代码进行重大更改时,我也会将更改推送到该服务器.
但今天我发现即使我有一些本地更改并提交到本地存储库,当运行 git push origin master
时,它显示所有内容都是最新的",但是当我使用 git clone
以检出远程服务器上的文件,它不包含最新的更改.而且我只有一个名为master"的分支和一个名为origin"的远程服务器.
附注:这是 git 在运行 ls-remote
时显示的内容,我不确定它是否有帮助
$ git ls-remote origindf80d0c64b8e2c160d3d9b106b30aee9540b6ece HEADdf80d0c64b8e2c160d3d9b106b30aee9540b6ece refs/heads/master$ git ls-remote .49c2cb46b9e798247898afdb079e76e40c9f77ea 头df80d0c64b8e2c160d3d9b106b30aee9540b6ece refs/heads/masterdf80d0c64b8e2c160d3d9b106b30aee9540b6ece refs/remotes/origin/master3a04c3ea9b81252b0626b760f0a7766b81652c0c refs/tags/stage3
您是否正在使用 :确保使用 git stash
如果你想保存当前修改的文件.
$ git log -1# 注意最新提交的 SHA-1$ git checkout master# 将你的分支头重置为你之前分离的提交$ git reset --hard
<小时>
如git checkout
手册页 中所述(强调我的):
有时能够检出不在您的一个分支顶端的提交很有用.
最明显的例子是在标记的官方发布点检查提交,如下所示:
$ git checkout v2.6.18
<块引用>
早期版本的 git 不允许这样做,并要求您使用 -b
选项创建一个临时分支,但从 1.5.0 版本开始,上述命令将分离您的 HEAD
从当前分支直接指向标记命名的提交(v2.6.18
在上面的例子中).
您可以在此状态下使用所有 git 命令.
例如,您可以使用 git reset --hard $othercommit
进一步移动.
您可以在分离的 HEAD 之上进行更改并创建新提交.
您甚至可以使用 git merge $othercommit
创建合并.
当你的 HEAD 被分离时你所处的状态没有被任何分支记录(这很自然——你不在任何分支上).
这意味着您可以通过切换回现有分支(例如git checkout master
)和稍后的git prune
或 git gc
将垃圾收集它们.
如果你做错了,你可以向 reflog 查询 HEAD 你所在的位置,例如
$ git log -g -2 HEAD
I have a remote gitosis server and a local git repository, and each time I make a big change in my code, I'll push the changes to that server too.
But today I find that even though I have some local changes and commit to local repository, when running git push origin master
it says 'Everything up-to-date', but when I use git clone
to checkout files on the remote server, it doesn't contain latest changes. And I have only one branch named "master" and one remote server named "origin".
PS:
This is what git displays when running ls-remote
, I'm not sure whether it helps
$ 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
Are you working with a detached head by any chance?
As in:
indicating that your latest commit is not a branch head.
Warning: the following does a git reset --hard
: make sure to use git stash
first if you want to save your currently modified files.
$ 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>
As mentioned in the git checkout
man page (emphasis mine):
It is sometimes useful to be able to checkout a commit that is not at the tip of one of your branches.
The most obvious example is to check out the commit at a tagged official release point, like this:
$ 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 yourHEAD
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 usegit 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 usinggit 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 latergit prune
orgit 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 说“一切都是最新的";即使我有本地更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!