git reset --hard HEAD^ 与 git reset --hard HEAD 之间的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40141493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between git reset --hard HEAD^ vs git reset --hard HEAD?
提问by ahtmatrix
What does the ^
in git reset --hard HEAD^
do versus just git reset --hard HEAD
Is there a difference?
什么是^
在git reset --hard HEAD^
做而不只是git reset --hard HEAD
有没有区别?
回答by Paul
HEAD^
is the parent commit of HEAD
.
HEAD^
是 的父提交HEAD
。
If you want to go into details, then ref^
is the shortcut for ref^1
where ref^1
is the commit's first parent (ref^2
is the commit's second parent, which may be absent if the commit is not a merge commit).
如果您想详细了解,那么ref^
快捷方式是提交的第一个父级ref^1
在哪里ref^1
(ref^2
是提交的第二个父级,如果提交不是合并提交,则可能不存在)。
There is also ref~
which is also commit's first parent. It is also a shortcut for ref~1
. But the difference between ref^2
and ref~2
is that ref~2
is commit's first parent's first parent. There can be ref~1
, ref~2
, ..., ref~n
(if the history is long enough).
还有ref~
which 也是 commit 的第一个父级。这也是 的捷径ref~1
。但之间的区别ref^2
,并ref~2
是,ref~2
就是犯的第一个父母的第一个祖先。可以有ref~1
, ref~2
, ..., ref~n
(如果历史足够长的话)。
As for the git reset
- it resets the current branch to the commit you specify (--hard
means to discard both index and working tree changes). git reset --hard HEAD^
resets the current branch one commit backward, while git reset --hard HEAD
just discards all local changes.
至于git reset
- 它将当前分支重置为您指定的提交(--hard
意味着丢弃索引和工作树更改)。git reset --hard HEAD^
向后重置当前分支一次提交,同时git reset --hard HEAD
丢弃所有本地更改。