无法恢复Git中的文件
可能重复:
恢复Git仓库中已删除的文件
我在Git,master和newFeature中有两个分支。 在分支newFeature中,我首先在终端中物理删除fileA,然后在Git中删除
git rm fileA
随后,我跑了
git add .
git commit
现在,我再次需要fileA 。 通过简单地切换到分支主人,我有了这个想法,我可以把它弄回来。 我显然是错的,因为我找不到fileA 。
我怎样才能让Git获得fileA?
首先,你需要找到你有最新版本的fileA
。 您可以使用“git log -p”或“git whatchanged”来检查它何时被删除,或者您可以使用“git ls-files <revision> - fileA”来检查文件是否存在于给定的提交中,其中'修改>'可以是主或新功能^(新功能^意味着新功能的父功能)。
那么你需要检查出来,或者使用
$ git checkout <revision> -- fileA
或重定向“git show”输出
$ git show <revision>:fileA > fileA
不要忘记添加文件到Git(如果需要的话)!
在删除fileA之前,在提交处创建一个标签或分支,检出它,将文件复制到其他地方,然后再次检出newFeature
分支。 其余的应该很简单。
@titan:~$ cd /tmp/
@titan:/tmp$ mkdir x
@titan:/tmp$ git init
Initialized empty Git repository in /tmp/.git/
@titan:/tmp$ echo a > a
@titan:/tmp$ git add a
@titan:/tmp$ git ci -m a
Created initial commit c835beb: a
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 a
@titan:/tmp$ git rm a
rm 'a'
@titan:/tmp$ git ci -m b
Created commit de97fae: b
1 files changed, 0 insertions(+), 1 deletions(-)
delete mode 100644 a
@titan:/tmp$ git whatchanged
commit de97fae7a72375ffa192643836ec8273ff6f762b
Date: Wed Mar 11 17:35:57 2009 +0100
b
:100644 000000 7898192... 0000000... D a
commit c835beb7c0401ec27d00621dcdafd366d2cfdcbe
Date: Wed Mar 11 17:35:51 2009 +0100
a
:000000 100644 0000000... 7898192... A a
@titan:/tmp$ git show 7898192
a
@titan:/tmp$ git show 7898192 > a
@titan:/tmp$
链接地址: http://www.djcxy.com/p/18929.html