[英]How to recover deleted git projects
I wanted to merge a git branch named gh-pages
with the master branch, but instead I typed ph-
and pressed the tab button for autocompleted. 我想合并一个名为gh-pages
的git分支和master分支,但我输入了ph-
并按下了tab键进行自动完成。 I tried that several times, and when I looked into the folder, nothing was there Only the .git
folder and the Readme.md
file are left. 我尝试了几次,当我查看文件夹时,没有任何内容只剩下.git
文件夹和Readme.md
文件。
I have checked the log by running git reflog
, and I can still see all the commits I have done. 我通过运行git reflog
检查了日志,我仍然可以看到我所做的所有提交。 Please how do I recover the files? 请问如何恢复文件?
I do not see yet how you got there, as merging a branch that does not exist leads to an error message. 我还没有看到你如何到达那里,因为合并一个不存在的分支会导致错误信息。 Here is a typical scenario: 这是一个典型的场景:
$ git init metest
Initialized empty Git repository in /tmp/metest/.git/
$ cd metest
$ echo "file1" >> file1
$ git add file1
$ git commit -m "File 1"
[master (root-commit) 5f56a1d] File1
1 file changed, 1 insertion(+)
create mode 100644 file1
$ git checkout -b some
Switched to a new branch 'some'
$ echo "file2" > file2
$ git add file2
$ git commit -m "File2"
[some 47af0d5] File2
1 file changed, 1 insertion(+)
create mode 100644 file2
$ git log # Shows 2 commits
$ git checkout master
Switched to branch 'master'
$ git log # Shows 1 commit
$ git merge foo- # Tab completion should show nothing
merge: foo- - not something we can merge
There may be a bug in the Git version you are using, or in one of the satellite tools. 您正在使用的Git版本或其中一个卫星工具中可能存在错误。
Anyway, assuming your remote is pristine (you did not push the changes), you can: 无论如何,假设您的遥控器是原始的(您没有推动更改),您可以:
git checkout .
to recover the files. 恢复文件。 This would work if git status
was showing some local changes. 如果git status
显示一些本地更改,这将有效。 git reset
and its flavors, depending on your particular case (see help). git reset
及其风格,具体取决于您的具体情况(请参阅帮助)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.