git分支搞乱了
我的 git 存储库发生了严重问题。我之前有2个分支,昨晚写完代码忘记push到github了。今天早上我使用另一台机器并尝试分叉一个新分支并将它们推上(代码存储在保管箱中,因此我使用哪台机器并不重要),然后 git 给了我错误说:“权限被拒绝”。然后我意识到我没有使用我的 labtop,所以我打开了我的 labtop 并尝试进入我刚刚创建的分支。但似乎我不能这样做,更糟糕的是,我在另一台机器上提交的所有代码都消失了!我使用 gitbranch 来查看分支列表,现在它就像:
centeredForm (shang's conflicted copy 2011-08-08)
* centeredform
master
refinement
其中第一个“centeredForm”是我在另一台计算机上创建的分支,“centeredform”是我后来在我的 labtop 上创建的分支。我的代码消失了吗?或者有什么办法可以恢复到以前的状态吗?
I have a serious issue happened to my git repository. I had 2 branches previously, and I wrote codes last night and forgot to push to the github. This morning I used the other machine and tried fork a new branch and push them up(the codes are stored in dropbox so it doesn't matter which machine I'm using), then git gave me error say: "permission denied". Then I realized that I'm not using my labtop, so I opened up my labtop and tried to get into the branch I just created. But then it seems like I cannot do that, and what was worse, all the codes that I committed on the other machine are gone! I use git branch
to see the branch listing and now it's like:
centeredForm (shang's conflicted copy 2011-08-08)
* centeredform
master
refinement
where the first "centeredForm" is the branch I created on the other machine, and "centeredform" is the branch I created on my labtop afterwards. Are my codes gone? Or is there a way to restore to previous status?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它被提交了,那么它就不会丢失。总有历史记录:
然后您可以获取上次提交的 SHA,并撤消任何混乱:
重要:首先备份所有内容。
reset --hard
将删除所有未提交的更改。If it was commited, then it's not lost. There's always the history:
Then you can grab the SHA of your last commit, and undo any mess:
IMPORTANT: Backup everyhing first. The
reset --hard
will delete all non-commited changes.查看提交是否仍然存在,并且 dropbox 没有“放错”它。使用 git rev-parsebranchYouLost 。这将查找该分支的提交。
。
从你的错误消息的外观来看,我假设这会告诉你这是一个无效的对象 在这种情况下,Dropbox 似乎丢失了您的分支的尖端。
尝试找到一些丢失的提交的另一种选择是使用 git reflog 并尝试查看其中一个是否包含您想要的提交。您可以使用 git cat-file -p HEAD@{n} 来获取日志消息并查看它是否是您丢失的消息。
To see if the commit is still there, and dropbox didn't "misplace" it. Use
git rev-parse branchYouLost
. This will look up the commit for the that branch.Than do
git cat-file -t SHA_above_command_gave_you
From the looks of your error message I'm assuming this will tell you that this is an invalid object. In which case it would seem that dropbox lost the tip of your branch.
Another option to try and find some your lost commits is to use
git reflog
and try and see if one of those contains the commit you want. You can usegit cat-file -p HEAD@{n}
to get the log message and see if it is the one that you are missing.