2011-04-21 98 views
1

我在這個上搞得很糟糕。 我正在研究分支'feature1-branch'並提交了更改,但未將它們與主分支合併。如何恢復到Git中較舊的提交?

的git的日誌顯示是這樣的:

git log 
commit 0829f9f0b68ce58ca37efd4e07cf3e8b3b67ed49 
Date: Thu Apr 21 00:38:58 2011 -0700 

feature1-branch lots and lots of changes 

我不知道我在想什麼,但我所做的:

git checkout master 

這刪除了一堆與分支添加新文件的優點1 -科'。

現在git的狀態顯示:爲刪除提到

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 feature1-branch 
D app/controllers/activations_controller.rb 
D app/controllers/products_controller.rb 
M app/controllers/application_controller.rb 

git的狀態返回:

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") 

回答

1

我懷疑發生了什麼事是您在某些時候刪除了這些文件,但未提交它們的刪除。這意味着,當你切換分支時,它們仍然會被顯示爲已刪除,因爲當你改變分支時,git會嘗試保留工作樹中的修改,除非這會損失數據或產生問題。

只是閱讀的git status輸出,你已經引用,它看起來好像你可以通過,恢復被刪除的文件,例如:

git checkout -- app/controllers/activations_controller.rb app/controllers/settings_controller.rb 

...當你在feature1-branch

+0

謝謝馬克。那樣做了。我意外地運行git checkout master並按下ctrl-c時,我意識到發生了什麼事情。那整個事情搞糟了。你和Noufal都有很大的幫助,只要我可以給你們買一兩杯啤酒:) – truthSeekr 2011-04-21 08:33:16

+0

我是一個茶壺,但是感謝你的祝福。 :) – 2011-04-21 08:38:52

+0

@truthSeekr:沒問題:)如果您嘗試在沒有足夠磁盤空間的情況下嘗試「git結帳」,可能會出現類似混淆狀態...... – 2011-04-21 10:00:55

2

我不明白,在git的狀態行那就是說你在feature1分支上。你能做到這一點,並粘貼輸出? git log -1 feature1-branch?如果它告訴你它指向0829f9f0b68ce58ca37efd4e07cf3e8b3b67ed49,那麼只需要git checkout feature1-branch即可轉到master之前的位置。

+0

'git的日誌-1特徵1支 提交0829f9f0b68ce58ca37efd4e07cf3e8b3b67ed49 日期:星期四4月21日0時38分58秒2011 -0700 特徵1支許許多多changes' – truthSeekr 2011-04-21 08:01:04

+0

等待的。什麼是'pivot_cars_apts'?我認爲它被稱爲'feature1-branch'? – 2011-04-21 08:02:11

+0

這是GIT中結帳返回 'GIT中結帳特徵1分支 d \t應用程序/控制器/ activations_controller.rb d \t應用程序/控制器/ products_controller.rb 中號\t應用程序/控制器/ application_controller。rb' – truthSeekr 2011-04-21 08:04:02