git错误地指出我在1次提交之前先于原点/主号 [英] git erroneously states I'm ahead of origin/master by 1 commit

查看:118
本文介绍了git错误地指出我在1次提交之前先于原点/主号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有两个特定回购克隆被检出。

  git log 
commit e06424b5 ...
...
commit 557a0eb8 .. 。

在两者中都显示相同的结果,顶部使用相同的散列。

  git remote show origin 

两者相同

  git分支
* master

现在有些区别。

来自'good'克隆:

  git log origin / master .. 
commit e06424b5 ...

git show-ref HEAD
e06424b5 ... refs / remotes / origin / HEAD

#分支master
无需提交(工作目录干净)

从'坏'克隆:

  git log origin / master .. 
commit 557a0eb8 ...

git show-ref HEAD
557a0eb8 ... refs / remotes / origin / HEAD

git status
#在分支大师
#你的分支领先于'origin / master'b y 1提交。

这是不同的[更正:早些时候我报告过这个输出是一样的]。 show-ref似乎表明这个签出是在后面的一个提交,而状态表示它在前面。但是 git reset --hard e06424b5 没有任何变化。



当我问'坏'克隆它认为需要什么被推送:

  git diff --stat origin / master 

它显示了e06424b5提交文件的一部分,但实际上这个结账的唯一原因就是这些文件,因为我把它们拉出来了。



任何人都知道如何让结帐认识到它没有任何东西可以推送?



  git log --graph --decorate --oneline 
* e06424b(HEAD,master)
* 557a0eb(origin / master,origin / HEAD)

git rev-parse origin / master
557a0eb

git rev-parse HEAD
557a0eb(前面的散列)
e06424b(正确的,最近的散列)


解决方案

考虑到你的意见,它似乎我实际上是在'分离头部'模式下工作。



问题是,您的初始文章意味着分支指向某个特定的地方如果你真的发布了任何你运行的git命令的输出,这将会变得更加清晰,在这种情况下,git reset --hard就是你想要解决的问题。



但事实上,HEAD似乎只是指向某个你不希望的地方,git checkout是你用来修复HEAD指向的命令。我假设可能有东西阻止结帐工作,这就是为什么我加了--force。



警告:使用git checkout和 - 强制参数可能会终止任何未提交的更改或类似事情。

  git checkout --force master 

假设您有一个主分支,它就是您想要签出的分支,并且实际上实际上是跟踪原点/主人,这应该让你摆脱你发现的泡菜。


[edit: added command outputs as requested, and reorganized for clarity] I've got two clones of a particular repo checked out.

git log
commit e06424b5...
...
commit 557a0eb8...

shows the same thing in both, with same hash at the top.

git remote show origin

same in both

git branch
* master

still same in both

Now some differences.

From the 'good' clone:

git log origin/master..
commit e06424b5...

git show-ref HEAD
e06424b5... refs/remotes/origin/HEAD

# On branch master
nothing to commit (working directory clean)

From the 'bad' clone:

git log origin/master..
commit 557a0eb8...

git show-ref HEAD
557a0eb8... refs/remotes/origin/HEAD

git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.

This is different [correction: earlier I reported that this output was the same]. show-ref seems to indicate that this checkout is one commit behind, while status says it is ahead. But git reset --hard e06424b5 changes nothing.

When I ask the 'bad' clone what it thinks needs to be pushed:

git diff --stat origin/master

it shows the files that were part of the e06424b5 commit, but in fact the only reason this checkout even has those files is because I pulled them.

Anyone know how to make the checkout realize that there's nothing for it to push?

[edit: here are some additional commands and their outputs from the 'bad' clone...]

git log --graph --decorate --oneline    
* e06424b (HEAD, master)
* 557a0eb (origin/master, origin/HEAD) 

git rev-parse origin/master
557a0eb

git rev-parse HEAD
557a0eb (the previous hash)
e06424b (the correct, most recent hash)

解决方案

Considering your comments, it seems to me that you are actually working in a 'detached head' mode.

The problem, is that your initial post implies that a branch is pointing to a specific place that you don't want it to (This would be much more clear if you actually posted any of the output of the git commands you had run) in which case git reset --hard is what you would expect to do to fix this.

But in fact it seems that HEAD is just pointing to somewhere you expect it to not be, git checkout is the command you use to fix where HEAD is pointing to. I'm assuming that there may be something blocking the checkout from working, which is why I've added --force.

WARNING: using git checkout with the --force parameter may kill any uncommitted changes you have, or things of the like.

git checkout --force master

Assuming you have a master branch, it's the one you want to checkout, and that it is in fact actually tracking origin/master, this should get you out of the pickle you have found yourself in.

这篇关于git错误地指出我在1次提交之前先于原点/主号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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