2017-05-14 55 views
1

我试图从我的Git工作区推到Github,但我添加和提交的更改似乎没有上传。似乎在“(无分支)”,然后失去了我的变化

然后,做一个“混帐分支”我得到的东西是这样的:

git branch 
* (no branch) 
    master 

愚蠢,我以为我可以重新进入主与

git checkout master 

,现在我的改变似乎去了。我的主分支大约三天。似乎没有办法切换回这个(没有分支)。

我检查了这个问题Git : seemed to be in “(no branch)” and then lost my changes答案建议做一个git reflog show然后结帐。我想,我得到这个:

$ git reflog 
    0f27ae7 [email protected]{1}: checkout: moving from HEAD to master 
    7b8ee7b [email protected]{2}: commit: 14/05/2017 3:33pm 
    ff60409 [email protected]{3}: commit: 14/05/2017 3:33pm 
    0f27ae7 [email protected]{4}: checkout: moving from master to 0f27ae7236aabbe8cccfba82e201e36368a05054 
    0f27ae7 [email protected]{5}: commit: 11/05/2017 2:33pm 
    3e4c616 [email protected]{6}: merge origin/master: Fast-forward 
    1e79818 [email protected]{7}: commit: 10/5//2017 UI 

我试着做一结帐从0f27ae7236aabbe8cccfba82e201e36368a05054但我的变化是不回来了。我想要的是恢复我在(无分支)(承诺:14/05/2017 3:33 pm)作出的最后提交。

这里是git branch -a结果:

$ git branch -a 
* (HEAD detached from 0f27ae7) 
    UI_linking 
    master 
    remotes/ado/newBranch 
    remotes/origin/UI_linking 
    remotes/origin/frogs1 
    remotes/origin/master 
    remotes/origin/newBranch 
    remotes/origin/newMas 

是我的变化失去了什么?还是有办法恢复它们?

+0

你可以显示git branch -a吗? – DreamInBox

+0

我将它添加到问题中。 –

回答

0

您可以恢复您的状态git checkout 7b8ee7b其中7b8ee7b是在您的reflog中的[email protected]{2}下的哈希值 - 您在切换到主站之前的哈希值。

发生了什么:由于某种原因,您从主分支切换到0f27ae7236aabbe8cccfba82e201e36368a05054,并以“分离头部”状态结束。你做了一些提交,但那些不在任何分支上。这些提交仍然存在,您可以在reflog中看到它们。

虽然0f27ae7236aabbe8cccfba82e201e36368a05054是您的主人指出的,但当您切换到散列时,您不会切换到指向该提交的任何分支。

0

从输出git reflog我会说你的变化是在承诺7b8ee7b[email protected]{2})。

以下命令:

git branch lost 7b8ee7b 
git checkout lost 

应建立在上述一个新的分支(名为lost)提交,然后检查出来。

然后,你可以这样做:

git rebase master 
git checkout master 
git merge --ff lost 

移动你恢复的master部门高层的两次提交,并使其显示为master分支历史的一部分。

如果一切都看起来不错,那么你可以运行git branch -d lost删除lost分支。

0

原因是:你推动你的分支没有宣布一些警告,但你忽略了他们的分支。现在,这段代码被分离到HEAD。所以你的新修改代码将在HEAD〜上。您可以在重新记录看到:

0f27ae7 HEAD @ {4}:结帐:从主移动到0f27ae7236aabbe8cccfba82e201e36368a05054

的方式把它找回来:

  1. 你获取了你的混帐来源:

git fetch来源

  • 结帐为HEAD
  • git的结帐遥控器/来源/主

  • 最后,合并0f27ae7 HEAD @ {1} to master
  • git merge HEAD @ {1}

    现在,你已经掌握了你的代码。

    Regards,

    相关问题