[英]How do I revert back to an older commit in Git?
我對這個很糟。 我正在分支'feature1-branch'上工作,並提交了更改,但未將它們與master合並。
git日志顯示如下內容:
git log
commit 0829f9f0b68ce58ca37efd4e07cf3e8b3b67ed49
Date: Thu Apr 21 00:38:58 2011 -0700
feature1-branch lots and lots of changes
我不確定自己在想什么,但我做到了:
git checkout master
這刪除了添加有分支“ feature1-branch”的一堆新文件。
現在git status顯示:
git status
# On branch feature1-branch
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: app/controllers/activations_controller.rb
# deleted: app/controllers/settings_controller.rb
# modified: app/controllers/application_controller.rb
# deleted: app/controllers/products_controller.rb
提到刪除的文件不再存在。 我如何使他們回到提交狀態
0829f9f0b68ce58ca37efd4e07cf3e8b3b67ed49
我擔心這些文件是否永遠消失了。
謝謝你的幫助。
添加其他信息:
git log -1 feature1-branch
commit 0829f9f0b68ce58ca37efd4e07cf3e8b3b67ed49
Date: Thu Apr 21 00:38:58 2011 -0700
feature1-branch lots and lots of changes
這是git checkout返回的內容:
git checkout feature1-branch
D app/controllers/activations_controller.rb
D app/controllers/products_controller.rb
M app/controllers/application_controller.rb
git status返回:
git status
# On branch feature1-branch
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# # deleted: app/controllers/activations_controller.rb
# deleted: app/controllers/products_controller.rb
no changes added to commit (use "git add" and/or "git commit -a")
我不理解git status中表示您在feature1分支上的行。 但是,您可以這樣做並粘貼輸出嗎? git log -1 feature1-branch
? 如果它告訴您它指向0829f9f0b68ce58ca37efd4e07cf3e8b3b67ed49
,則可以git checkout feature1-branch
到達git checkout feature1-branch
位置,然后再切換到master
。
我懷疑發生的事情是您在某個時候刪除了這些文件,但沒有提交刪除。 這意味着,當您切換分支時,它們仍將顯示為已刪除,因為git會在更改分支時嘗試將修改保留在工作樹中,除非那樣會丟失數據或造成問題。
只需閱讀引用的git status
的輸出,就好像您可以通過以下方式還原已刪除的文件:
git checkout -- app/controllers/activations_controller.rb app/controllers/settings_controller.rb
...當您在feature1-branch
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.