2011-04-21 108 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