我正在清理分支併合並它們。在完成主分支之後,我嘗試結帳其他分支,但它不讓我這樣做,因爲有2個文件將被覆蓋!我用-f來切換分支(我只希望看到那個分支發生了什麼變化)。沒有什麼是在其他分支。所以我沒有看到任何刪除它的危險。之後,我失去了主分支中的所有其他更改。這是發生了什麼!請讓我知道如何恢復主分支中的所有更改?刪除分支後丟失了所有內容 - 沒有提交(工作目錄清理)
[[email protected] 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
#
[[email protected] core]$ git merge otherbranch
Already up-to-date.
[[email protected] core]$ git merge master
Already up-to-date.
[[email protected] 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
[[email protected] core]$ git checkout -f otherbranch
Switched to branch 'otherbranch'
[[email protected] core]$ git status
# On branch otherbranch
nothing to commit (working directory clean)
[[email protected] core]$ git checkout otherbranch
Already on 'otherbranch'
[[email protected] core]$ git branch -d otherbranch
error: Cannot delete the branch 'otherbranch' which you are currently on.
[[email protected] core]$ git checkout master
Switched to branch 'master'
[[email protected] core]$ git branch -D otherbranch
Deleted branch otherbranch (was d3c9c6f).
[[email protected] core]$ git branch
* master
[[email protected] core]$ git status
# On branch master
nothing to commit (working directory clean)
編輯:當Stony suggessted,我運行reflog。這是輸出!
d302fab [email protected]{0}: checkout: moving from otherbranch to master
d3c9c6f [email protected]{1}: checkout: moving from master to otherbranch
d302fab [email protected]{2}: checkout: moving from otherbranch to master
d3c9c6f [email protected]{3}: checkout: moving from otherbranch to otherbranch
d3c9c6f [email protected]{4}: checkout: moving from master to otherbranch
d302fab [email protected]{5}: pull: Fast-forward
f1569af [email protected]{6}: pull: Fast-forward
d0f72c6 [email protected]{7}: pull: Fast-forward
4c007c4 [email protected]{8}: pull: Fast-forward
d3c9c6f [email protected]{9}: checkout: moving from otherbranch to master
d3c9c6f [email protected]{10}: merge master: Fast-forward
506d77d [email protected]{11}: checkout: moving from master to otherbranch
d3c9c6f [email protected]{12}: checkout: moving from otherbranch to master
506d77d [email protected]{13}: checkout: moving from master to otherbranch
d3c9c6f [email protected]{14}: checkout: moving from otherbranch to master
506d77d [email protected]{15}: checkout: moving from master to otherbranch
d3c9c6f [email protected]{16}: pull: Fast-forward
72b9fee [email protected]{17}: pull: Fast-forward
2a7f380 [email protected]{18}: pull: Fast-forward
506d77d [email protected]{19}: checkout: moving from otherbranch to master
506d77d [email protected]{20}: checkout: moving from master to otherbranch
506d77d [email protected]{21}: checkout: moving from otherbranch to master
506d77d [email protected]{22}: checkout: moving from master to otherbranch
506d77d [email protected]{23}: commit: (Ticket ####)
0cb7e3a [email protected]{24}: pull: Fast-forward
fef5044 [email protected]{25}: pull: Fast-forward
a92f38f [email protected]{26}: pull: Fast-forward
1715fc0 [email protected]{27}: pull: Fast-forward
8cad089 [email protected]{28}: pull: Fast-forward
ecb5708 [email protected]{29}: pull: Fast-forward
87fd764 [email protected]{30}: commit: (Ticket ###)
745c5ad [email protected]{31}: clone: from [email protected]:/opt/git/seqcore.git/
我使用HEAD @ {0},HEAD @ {5},HEAD @ {9}創建了幾個分支,但它沒有幫助我。我仍然無法在主或新創建的分支下看到我的舊更改。
您的reflog中的事件與您運行的命令不匹配。例如,reflog應該顯示你檢查'otherbranch'。您是否刪除了您的副本並再次克隆存儲庫? – Schwern
爲了舉例,我改了名字,但忘了在reflog中做。現在它已更新!感謝您指出@Schwern – kalibrain