[英]How to recover deleted files that were deleted during merging
I was trying to delete all the migration files on the master branch. 我试图删除master分支上的所有迁移文件。 Git prompted: Git提示:
error: Merging is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
since I did not need the migration files, I typed: 由于不需要迁移文件,因此输入:
git rm . -r
Git prompted: Git提示:
error: the following files have changes staged in the index:
/middleware.py
project_management/models.py
sales/migrations/0001_initial.py
(use --cached to keep the file, or -f to force removal) (使用--cached保留文件,或使用-f强制删除)
Thinking that the conflicts are just due to those migration files, I typed: 考虑到冲突仅是由于这些迁移文件引起的,我输入:
git rm . -r -f
Now, git has removed ALL my files, including models, templates, views, static files, etc. 现在,git删除了我的所有文件,包括模型,模板,视图,静态文件等。
rm '.gitignore'
rm 'accounts/__init__.py'
rm 'accounts/__pycache__/__init__.cpython-36.pyc'
rm 'accounts/__pycache__/backends.cpython-36.pyc'
rm 'accounts/admin.py'
rm 'accounts/apps.py'
rm 'accounts/backends.py'
rm 'accounts/forms/__init__.py'
rm 'accounts/forms/authenticate.py'
rm 'accounts/forms/register.py'
rm 'accounts/migrations/0001_initial.py'
rm 'accounts/migrations/__init__.py'
rm 'accounts/models.py'
rm 'accounts/templates/login.html'
rm 'accounts/templates/signup.html'
rm 'accounts/tests.py'
rm 'accounts/urls.py'
rm 'accounts/views.py'
Now, when I do 现在,当我做
git status
It tells me this: On branch master All conflicts fixed but you are still merging. 它告诉我这一点:在分支主服务器上所有冲突已修复,但您仍在合并。 (use "git commit" to conclude merge) (使用“ git commit”结束合并)
Changes to be committed: 所做更改:
deleted: .gitignore
deleted: accounts/__init__.py
deleted: accounts/__pycache__/__init__.cpython-36.pyc
deleted: accounts/__pycache__/backends.cpython-36.pyc
deleted: accounts/admin.py
deleted: accounts/apps.py
deleted: accounts/backends.py
deleted: accounts/forms/__init__.py
deleted: accounts/forms/authenticate.py
deleted: accounts/forms/register.py
deleted: accounts/migrations/0001_initial.py
deleted: accounts/migrations/0002_auto_20170212_1028.py
deleted: accounts/migrations/__init__.py
deleted: accounts/models.py
deleted: accounts/templates/login.html
deleted: accounts/templates/signup.html
deleted: accounts/tests.py
deleted: accounts/urls.py
deleted: accounts/views.py
...
Untracked files:
(use "git add <file>..." to include in what will be committed)
accounts/
commonapp/
There are more than 10 apps, with more than 50 models, etc. but for the sake simplicity, I have not list them all here. 有10多个应用程序,50多个模型等,但是为了简单起见,我没有在此处列出所有应用程序。
Is there a way to undo these deletions? 有办法撤消这些删除吗? This is months worth of my time, so I really appreciate your help. 这是我几个月的宝贵时间,非常感谢您的帮助。
git reset --hard
will recover the files for you. git reset --hard
将为您恢复文件。 It will also remove all changes that are staged. 它还将删除所有已暂存的更改。 So if you've anything you want to keep, copy those files out before the reset. 因此,如果您要保留任何内容,请在重置之前将这些文件复制出去。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.