git分支搞乱了

发布于 2024-11-28 15:04:33 字数 467 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末骤雨初歇 2024-12-05 15:04:33

如果它被提交了,那么它就不会丢失。总有历史记录:

git reflog

然后您可以获取上次提交的 SHA,并撤消任何混乱:

git reset --hard <SHA>

重要:首先备份所有内容。 reset --hard 将删除所有未提交的更改。

If it was commited, then it's not lost. There's always the history:

git reflog

Then you can grab the SHA of your last commit, and undo any mess:

git reset --hard <SHA>

IMPORTANT: Backup everyhing first. The reset --hard will delete all non-commited changes.

娇女薄笑 2024-12-05 15:04:33

查看提交是否仍然存在,并且 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 use git cat-file -p HEAD@{n} to get the log message and see if it is the one that you are missing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文