#reset to previous commit, replace with your commit hash code, you can find it from your commit history
git reset {commit hash}
#moves pointer back to previous head branch
git reset --soft HEAD@{1}
git commit -m "Reverted commit to blah"
#update your working copy
git reset --hard
恢复到提交的一部分在这种情况下,您需要恢复到特定的提交并添加补丁
#reset to previous commit, but don't commit the changes
$ git revert --no-commit {last commit hash}
# unstage the changes
$ git reset HEAD .
# add/remove stuff here
$ git add file
$ git rm -r myfolder/somefiles
# commit the changes
$ git commit -m "fixed something"
# check the files
$ git status
#discard unwanted changes
$ git reset --hard
5条答案
按热度按时间nhaq1z211#
我想出了最简单的解决办法。
然后删除任何未跟踪的文件。
从工作树和索引中删除文件https://git-scm.com/docs/git-rm
更新工作树中的文件,以匹配索引或指定树中的版本。https://www.git-scm.com/docs/git-checkout
将更改记录到存储库https://www.git-scm.com/docs/git-commit
wmtdaxz32#
仅删除git上的文件夹及其内容
在git和本地删除文件夹
然后提交并再次推送
恢复到上一次提交
恢复到提交的一部分在这种情况下,您需要恢复到特定的提交并添加补丁
9avjhtql3#
第一个答案很好,但我想简化一下。
一切都是完全相同的,除了在我的例子中的checkout命令是:
git checkout 70157c4f57aa21307cd96f146f8e98b808e1aada ./WebRoot
在命令行中,我在一个名为Memento的目录中,我用一个点表示git commit信息将进入的新目录将在Memento文件夹中。
我在检查文件夹里的提交。
d4so4syb4#
恢复到与
首先从集结地用核武器摧毁目录
现在读取该目录的treeish
然后提交
然后抛出剩余的工作目录更改。
ffx8fchx5#
我认为你可以一步完成,
--no-overlay
https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt---no-overlay将删除不在参考文件中的文件