我在清理我的树枝并把它们合并。在我完成了主分支,我试图签出其他分支,但它不让我做,因为有两个文件,将被覆盖!我使用-f来切换分支(我只希望看到这个分支中发生了什么变化)。另一根树枝上什么也没有。所以我看不出删除它有什么危险。在那之后,我失去了主支部的所有其他变化。这就是发生的事!请告诉我如何恢复主分行的所有更改?
[kali@core core]$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: blabla.cgi
# deleted: blabla2.cgi
# modified: blabla3.cgi
# new file: blabla4.cgi
# modified: blabla5.cgi
#
[kali@core core]$ git merge otherbranch
Already up-to-date.
[kali@core core]$ git merge master
Already up-to-date.
[kali@core core]$ git checkout otherbranch
error: Your local changes to the following files would be overwritten by checkout:
blabla3.cgi
blabla5.cgi
Please, commit your changes or stash them before you can switch branches.
Aborting
[kali@core core]$ git checkout -f otherbranch
Switched to branch 'otherbranch'
[kali@core core]$ git status
# On branch otherbranch
nothing to commit (working directory clean)
[kali@core core]$ git checkout otherbranch
Already on 'otherbranch'
[kali@core core]$ git branch -d otherbranch
error: Cannot delete the branch 'otherbranch' which you are currently on.
[kali@core core]$ git checkout master
Switched to branch 'master'
[kali@core core]$ git branch -D otherbranch
Deleted branch otherbranch (was d3c9c6f).
[kali@core core]$ git branch
* master
[kali@core core]$ git status
# On branch master
nothing to commit (working directory clean)编辑:正如石材暗示的那样,我运行reflog。这是输出!
d302fab HEAD@{0}: checkout: moving from otherbranch to master
d3c9c6f HEAD@{1}: checkout: moving from master to otherbranch
d302fab HEAD@{2}: checkout: moving from otherbranch to master
d3c9c6f HEAD@{3}: checkout: moving from otherbranch to otherbranch
d3c9c6f HEAD@{4}: checkout: moving from master to otherbranch
d302fab HEAD@{5}: pull: Fast-forward
f1569af HEAD@{6}: pull: Fast-forward
d0f72c6 HEAD@{7}: pull: Fast-forward
4c007c4 HEAD@{8}: pull: Fast-forward
d3c9c6f HEAD@{9}: checkout: moving from otherbranch to master
d3c9c6f HEAD@{10}: merge master: Fast-forward
506d77d HEAD@{11}: checkout: moving from master to otherbranch
d3c9c6f HEAD@{12}: checkout: moving from otherbranch to master
506d77d HEAD@{13}: checkout: moving from master to otherbranch
d3c9c6f HEAD@{14}: checkout: moving from otherbranch to master
506d77d HEAD@{15}: checkout: moving from master to otherbranch
d3c9c6f HEAD@{16}: pull: Fast-forward
72b9fee HEAD@{17}: pull: Fast-forward
2a7f380 HEAD@{18}: pull: Fast-forward
506d77d HEAD@{19}: checkout: moving from otherbranch to master
506d77d HEAD@{20}: checkout: moving from master to otherbranch
506d77d HEAD@{21}: checkout: moving from otherbranch to master
506d77d HEAD@{22}: checkout: moving from master to otherbranch
506d77d HEAD@{23}: commit: (Ticket ####)
0cb7e3a HEAD@{24}: pull: Fast-forward
fef5044 HEAD@{25}: pull: Fast-forward
a92f38f HEAD@{26}: pull: Fast-forward
1715fc0 HEAD@{27}: pull: Fast-forward
8cad089 HEAD@{28}: pull: Fast-forward
ecb5708 HEAD@{29}: pull: Fast-forward
87fd764 HEAD@{30}: commit: (Ticket ###)
745c5ad HEAD@{31}: clone: from git@oldseqcore:/opt/git/seqcore.git/我使用HEAD@{0}、HEAD@{5}、HEAD@{9}创建了两个分支,但它没有帮助我。我仍然看不到我的旧变化,无论是在主人或新创建的分支。
发布于 2015-10-07 22:53:41
我不明白你说你失去了主支部的零钱是什么意思。从你写的东西看,我看到两样东西丢失了。
blabla*.cgi的更改。otherbranch.第一个不见了。未提交的更改,即使它们是阶段性的,也无法恢复。抱歉的。分期区域被git checkout -f覆盖。吉特警告过你。
$ git checkout otherbranch
error: Your local changes to the following files would be overwritten by checkout:
blabla3.cgi
blabla5.cgi
Please, commit your changes or stash them before you can switch branches.
AbortingGit在单个工作副本中切换分支的方法可能很难适应。从中吸取的经验教训:
git checkout -f。git stash save。otherbranch可以恢复。告诉你身份证在哪里。
$ git branch -D otherbranch
Deleted branch otherbranch (was d3c9c6f).您可以使用ID d3c9c6f重新创建分支。
git branch otherbranch d3c9c6f没有必要使用git branch -D。您应该始终首先使用git branch -d。这样,您就会知道合并的分支实际上是合并的。
还有另一个问题: reflog与您编写的命令不匹配。您的reflog应该显示您签出了otherbranch,但它没有,这表明您正在进行签出的存储库和您在上面执行的库是不同的存储库。这也许可以解释为什么有什么东西丢失了。
我猜您删除了您的工作副本并克隆了一个新的存储库。如果是这样的话,您可能已经在master中提交了未被推送的。他们都走了。
发布于 2015-10-07 22:38:42
如果您正在寻找对blabla3.cgi和blabla5.cgi的更改,它们将永远消失(除非您有与git无关的备份解决方案)。你做git checkout -f otherbranch的时候他们都走了。你后来做了什么并不重要。
遗憾的是,git reflog这次无法帮助您,因为您似乎从未提交过它们。如果您将某些内容提交到分支中,然后删除该分支,git reflog可以帮助您。它也可以帮助你,如果你犯了什么,然后搞砸了提交(例如,通过重基或-修改)
当git警告你时,它是真心的。
error: Your local changes to the following files would be overwritten by checkout:
blabla3.cgi
blabla5.cgi
Please, commit your changes or stash them before you can switch branches.
Aborting发布于 2015-10-07 22:28:13
你可以试着和雷司令合作。
git reflog
然后你就能看到雷射了。使用id,您可以恢复最后的更改。
22490d2 HEAD@{58}: commit: xxxx
262a092 HEAD@{59}: commit: xx2
0a168bc HEAD@{60}: commit: xx2git checkout -b my_new_branch HEAD@{60}
例如。有了它,你就可以在这一点上有一个新的分支。
https://stackoverflow.com/questions/33003409
复制相似问题