如何在不移动HEAD的情况下重置工作树? [英] How do I reset the working tree without moving HEAD?
问题描述
A - >在给定一个git分支上有一些提交(C是最近的提交) B - > C
如何重置我的工作区,以便所有文件都处于提交B状态,但HEAD仍然在C?
我看过 git-reset
,但没有任何选项似乎有帮助。手册页建议所有不同的模式都会移动HEAD:
- soft
不要碰到索引文件或工作树的所有
(但将磁头重置为< commit>,就像所有模式一样)。
我试过 git reset HEAD 〜
但是会移动HEAD。
git checkout [-p | --patch] [< tree-ish>] [ - ]< pathspec> ...
<使用<路径> 或- 修补程序
来检查修改或删除的路径来自索引的内容或将路径替换为来自名为< tree-ish>
的内容(通常是提交ish)。
所以你需要在你的仓库的根目录下运行它(对于任何子树或文件也可以):
git checkout HEAD〜 - 。
这将导致git应用必要的更改以将文件恢复为 HEAD〜
状态,更改将位于索引中。
Given a git branch with some commits on it (C is the most recent commit):
A -> B -> C
How do I reset my workspace so that all the files are in the state they were at commit B, but HEAD is still at C?
I've looked at git-reset
, but none of the options seem to help. The man page suggests that all the different modes will move HEAD:
--soft Does not touch the index file or the working tree at all (but resets the head to <commit>, just like all modes do).
I've tried git reset HEAD~
but that moves HEAD.
git checkout [-p|--patch] [<tree-ish>] [--] <pathspec>...
git checkout with <paths>
or--patch
is used to restore modified or deleted paths to their original contents from the index or replace paths with the contents from a named<tree-ish>
(most often a commit-ish).
So you need to run this at root of your repository (works fine for any sub-tree or file(s) too):
git checkout HEAD~ -- .
This will result in git applying changes necessary to revert files to HEAD~
state, the changes will be in the index.
这篇关于如何在不移动HEAD的情况下重置工作树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!