Git恢复到以前提交的未合并文件也会忽略未合并的文件

Git恢复到以前提交的未合并文件也会忽略未合并的文件,git,Git,这是我的git日志 $ git log commit b5865d75efbd7bdf5b28aef6526f96ebd971e95c Author: user <user@example.com> Date: Mon Mar 31 21:20:17 2014 -0400 new work commit 7ee27d135a733fe709279f7752f5844da3102f9e Author: user <user@example.com> Date

这是我的git日志

$ git log
commit b5865d75efbd7bdf5b28aef6526f96ebd971e95c
Author: user <user@example.com>
Date:   Mon Mar 31 21:20:17 2014 -0400

    new work

commit 7ee27d135a733fe709279f7752f5844da3102f9e
Author: user <user@example.com>
Date:   Mon Mar 31 20:44:33 2014 -0400

    added password_for_form_show to attr_accessor

commit f3decd1232c6884c14cd082c3129e77ddd2b3bab
Author: user <user@example.com>
Date:   Mon Mar 31 14:21:36 2014 -0400

    phase 3.5

commit 99804b8f0adc572021f773dea5e660186d11a88b
Author: user <user@example.com>
Date:   Mon Mar 31 12:19:13 2014 -0400

    jquery stuff done
上述提交在github上发布

我试着下一步做这个

git revert HEAD~3
我想在本地和github上永久地回到这个阶段

commit 99804b8f0adc572021f773dea5e660186d11a88b
Author: user <user@example.com>
Date:   Mon Mar 31 12:19:13 2014 -0400

    jquery stuff done
当我这样做的时候

git status
我明白了

error: 'revert' is not possible because you have unmerged files.
$ git status
# HEAD detached at b5865d7
# You are currently reverting commit 99804b8.
#   (fix conflicts and run "git revert --continue")
#   (use "git revert --abort" to cancel the revert operation)
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   app/controllers/users_controller.rb
#
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add <file>..." to mark resolution)
#
#   both modified:      app/views/users/trial_signup.html.erb
$git状态
#头部在b5865d7处分离
#您当前正在恢复提交99804b8。
#(修复冲突并运行“git revert--continue”)
#(使用“git revert--abort”取消还原操作)
#
#要提交的更改:
#(使用“git重置磁头…”取消分级)
#
#修改:app/controllers/users\u controller.rb
#
#未合并路径:
#(使用“git重置磁头…”取消分级)
#(使用“git add…”标记分辨率)
#
#都已修改:app/views/users/trial_signup.html.erb

请注意,我也不想要本地提交/文件。如何强制恢复?我不想把它们藏起来,因为我不想要它们。我不想提交、添加和推送

实际上,当您执行恢复时,git会控制一个新的提交,该提交会否定在主题提交中所做的更改,并尝试在您当前的头上应用新的更改。当然,在此阶段可能存在合并冲突。您必须像往常一样解决这些问题,然后提交新的更改。可能你需要一个重基?

我想你需要的是
git reset
,它实际上会将头部重置为指向以前的提交,并将放弃任何你不想要的提交。
$ git status
# HEAD detached at b5865d7
# You are currently reverting commit 99804b8.
#   (fix conflicts and run "git revert --continue")
#   (use "git revert --abort" to cancel the revert operation)
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   app/controllers/users_controller.rb
#
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add <file>..." to mark resolution)
#
#   both modified:      app/views/users/trial_signup.html.erb