如何恢复在合并过程中删除的已删除文件

How to recover deleted files that were deleted during merging

我试图删除主分支上的所有迁移文件。 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.

因为我不需要迁移文件,所以我输入了:

git rm . -r

Git提示:

error: the following files have changes staged in the index:
/middleware.py
project_management/models.py
sales/migrations/0001_initial.py

(使用 --cached 保留文件,或使用 -f 强制删除)

认为冲突只是由于那些迁移文件,我输入:

git rm . -r -f

现在,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'

现在,当我这样做时

git status

它告诉我: 在分行主 所有冲突都已解决,但您仍在融合。 (使用 "git commit" 结束合并)

要提交的更改:

    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/

APP有10多个,机型有50多个等等,为了简单起见,这里就不一一列举了。

有没有办法撤销这些删除?这是我几个月的时间,非常感谢你的帮助。

git reset --hard 将为您恢复文件。它还将删除暂存的 所有 更改。因此,如果您有任何想要保留的内容,请在重置之前将这些文件复制出来。