git push表示“所有最新信息",即使我有局部变化 [英] git push says "everything up-to-date" even though I have local changes

查看:133
本文介绍了git push表示“所有最新信息",即使我有局部变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个远程gitosis服务器和一个本地git存储库,每次我对代码进行重大更改时,我都会将更改也推送到该服务器.

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.

但是今天我发现,即使我进行了一些本地更改并提交到本地存储库,在运行git push origin master时它也会显示一切都是最新的",但是当我使用git clone来检出远程计算机上的文件时服务器,它不包含最新更改.而且我只有一个名为"master"的分支和一个名为"origin"的远程服务器.

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: 这是git在运行ls-remote时显示的内容,我不确定它是否有帮助

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?

如:

表明您的最新提交不是分支头.

indicating that your latest commit is not a branch head.

警告:以下操作会执行 git reset --hard :确保使用 git stash (如果要保存当前修改的文件).

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>


git checkout手册页(强调我的)中所述:


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

较早版本的git不允许这样做,并要求您使用-b选项创建一个临时分支,但是从版本1.5.0开始,上述命令将HEAD与当前分支分离,并且直接指向由标签命名的提交(在上面的示例中为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 your HEAD from the current branch and directly points at the commit named by the tag (v2.6.18 in the example above).

在此状态下,您可以使用所有git命令.
例如,您可以使用git reset --hard $othercommit进一步移动.
您可以进行更改并在分离的HEAD上创建新的提交.
您甚至可以使用git merge $othercommit创建合并.

You can use all git commands while in this state.
You can use git 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 using git merge $othercommit.

任何分支都不会记录HEAD分离时所处的状态(这很自然---您不在任何分支上).
这意味着您可以通过切换回现有分支来放弃临时提交和合并(例如git checkout master),以后的git prunegit gc会对其进行垃圾回收.
如果您错误地执行了此操作,则可以向HEAD的查询日志询问您所在的位置,例如

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 later git prune or git 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆