【问题标题】:How do I restore my git to the original HEAD? [duplicate]如何将我的 git 恢复到原始 HEAD? [复制]
【发布时间】:2014-12-16 21:54:10
【问题描述】:

我试图回滚到之前的提交,但显然我搞砸了。 所以我需要恢复。

幸运的是我藏了起来;但应用后出现以下错误:

error: Your local changes to the following files would be overwritten by merge:
    Bliss.storyboard
    Bliss2.xcodeproj/project.pbxproj
    Bliss2/(3.0)DiscoveryViewController.swift
    Bliss2/(3.6)Contribute.swift
    Bliss2/(3.7)CameraContribute.swift
    Bliss2/Environment.swift
Please, commit your changes or stash them before you can merge.
Aborting

所以我又藏起来了。这是我的藏匿处:

$~/workarea/bliss/Bliss2:git stash list
stash@{0}: WIP on RicBranch: e3cb317 Revert "Linked up BlissThoughts & hidden toggle for (3.6) TextView" Temp go back and see old 
stash@{1}: WIP on RicBranch: 40e664a Creation of (3.10) DiscoveryUploadViewController.

所以我尝试了这个并得到了同样的错误:

$~/workarea/bliss/Bliss2:git stash apply #1
error: Your local changes to the following files would be overwritten by merge:
    Bliss.storyboard
    Bliss2.xcodeproj/project.pbxproj
    Bliss2/(3.0)DiscoveryViewController.swift
    Bliss2/(3.6)Contribute.swift
    Bliss2/(3.7)CameraContribute.swift
    Bliss2/Environment.swift
Please, commit your changes or stash them before you can merge.
Aborting
$~/workarea/bliss/Bliss2:git commit -m 'Committed garbage'
On branch RicBranch
Changes not staged for commit:
    deleted:    ../(3.6)TableViewCell.xib
    modified:   ../Bliss.storyboard
    modified:   ../Bliss2.xcodeproj/project.pbxproj
    modified:   (3.0)DiscoveryViewController.swift
    modified:   (3.6)Contribute.swift
    modified:   (3.7)CameraContribute.swift
    modified:   Environment.swift

no changes added to commit
$~/workarea/bliss/Bliss2:git stash apply #1
error: Your local changes to the following files would be overwritten by merge:
    Bliss.storyboard
    Bliss2.xcodeproj/project.pbxproj
    Bliss2/(3.0)DiscoveryViewController.swift
    Bliss2/(3.6)Contribute.swift
    Bliss2/(3.7)CameraContribute.swift
    Bliss2/Environment.swift
Please, commit your changes or stash them before you can merge.
Aborting
$~/workarea/bliss/Bliss2:

这是我所在位置的快照。我想回滚到“RicBranch”:

我正在尝试回滚到“干净”提交:(3.10) 提交。
但是 Git 一直说我必须再做一次提交/存储。

我想做的就是在所有这些混乱发生之前回滚到我以前的 HEAD。

如何弹出原始 HEAD 或应用 2nd Stash(版本 3.10)?

【问题讨论】:

  • 首先 - 你的git status 显示了什么?另外,您是要返回到特定的存储条目,还是在另一个分支上提交?
  • 此链接可能会有所帮助:stackoverflow.com/questions/15164300,因为它看起来非常相关。
  • git reset --hard <commit sha1> 会将您返回到特定的提交,除非您已经推送了更改。 (它也会这样做,但是远程端的事情会变得复杂,尤其是如果其他人也使用你的存储库)

标签: git


【解决方案1】:

环境:Xcode 6.1

当我搞砸并破坏了我的 git 时,我正在一个新分支中工作。
我想如果我失败了,我可以很容易地回到我原来的分支。但由于损坏,我无法启动 Xcode。

我不得不去命令行并使用 gitX。这完全是修复它的问题......所有的存储库都在那里。

所以我最终使用了:

git reset --hard HEAD

现在我回到了我开始的地方。

顺便说一句:我仍然想在不搞砸应用程序的情况下查看以前的提交。

【讨论】:

  • 您之前尝试过软重置吗?在我看来,这更像是一个合并错误,所以也许 git merge --abort 有帮助?
【解决方案2】:

对于未来,也许你可以使用 gil log / 或 git reflog 给你类似的东西:

yourHash HEAD@{0}: rebase finished: returning to refs/heads/dev
yourHash HEAD@{1}: commit : some commit
yourHash HEAD@{2}: rebase finished: returning to refs/heads/dev
...

如果你想检索一个特定的状态,你可以做git reset --hard yourHash

希望有帮助

【讨论】:

    猜你喜欢
    • 2021-09-09
    • 2022-11-30
    • 2012-03-20
    • 2022-11-02
    • 2013-01-17
    • 2020-05-04
    • 2021-05-14
    • 1970-01-01
    相关资源
    最近更新 更多