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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:22:01  来源:igfitidea点击:

Difference between git reset --hard HEAD^ vs git reset --hard HEAD?

gitgithub

提问by ahtmatrix

What does the ^in git reset --hard HEAD^do versus just git reset --hard HEADIs 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^1where ref^1is the commit's first parent (ref^2is the commit's second parent, which may be absent if the commit is not a merge commit).

如果您想详细了解,那么ref^快捷方式是提交的第一个父级ref^1在哪里ref^1ref^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^2and ref~2is that ref~2is 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 (--hardmeans to discard both index and working tree changes). git reset --hard HEAD^resets the current branch one commit backward, while git reset --hard HEADjust discards all local changes.

至于git reset- 它将当前分支重置为您指定的提交(--hard意味着丢弃索引和工作树更改)。git reset --hard HEAD^向后重置当前分支一次提交,同时git reset --hard HEAD丢弃所有本地更改。