如何恢复在合并期间删除的已删除文件

时间:2017-12-04 18:45:50

标签: django git merge merge-conflict-resolution

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

它告诉我这个:     在分支大师 所有冲突都已修复,但您仍在合并。   (使用&#34; git commit&#34;结束合并)

要提交的更改:

    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/

有超过10个应用程序,超过50个模型等等,但为了简单起见,我没有在这里列出所有。

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

1 个答案:

答案 0 :(得分:1)

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