git 插入符号 (^) 字符是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1955985/
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
What does the caret (^) character mean?
提问by Charles Ma
I saw an answer to a questionhere that helps restore a deleted file in git.
我在这里看到了一个问题的答案,该问题有助于在 git 中恢复已删除的文件。
The solution was
解决办法是
git checkout <deleting_commit>^ -- <deleted_file_path>
What does the caret character (^
) do? I've seen it elsewhere doing very useful things in git. It's magical. Someone please spoil it for me and tell me what it does?
插入符号 ( ^
) 有什么作用?我在其他地方看到它在 git 中做了非常有用的事情。这很神奇。有人请帮我破坏它并告诉我它有什么作用?
回答by Greg Bacon
HEAD^
means the first parent of the tip of the current branch.
HEAD^
表示当前分支尖端的第一个父级。
Remember that git commits can have more than one parent. HEAD^
is short for HEAD^1
, and you can also address HEAD^2
and so on as appropriate.
请记住,git commits 可以有多个父级。HEAD^
是 的缩写HEAD^1
,您也可以根据需要进行寻址HEAD^2
等。
You can get to parents of any commit, not just HEAD
. You can also move back through generations: for example, master~2
means the grandparent of the tip of the master branch, favoring the first parent in cases of ambiguity. These specifiers can be chained arbitrarily
, e.g., topic~3^2
. See related answer to What's the difference between HEAD^
and HEAD~
in Git?
您可以联系任何提交的父母,而不仅仅是HEAD
. 您还可以通过几代向后移动:例如,master~2
表示主分支尖端的祖父母,在歧义的情况下支持第一个父母。这些说明符可以任意链接,例如,topic~3^2
。请参阅Git和Git之间有什么区别?HEAD^
HEAD~
For the full details, see the “Specifying Revisions”section of git rev-parse --help
.
有关完整的详细信息,请参阅“指定修订版本”一节git rev-parse --help
。
回答by mipadi
It means "parent of". So HEAD^
means "the parent of the current HEAD". You can even chain them together: HEAD^^
means "the parent of the parent of the current HEAD" (i.e., the grandparent of the current HEAD), HEAD^^^
means "the parent of the parent of the parent of the current HEAD", and so forth.
它的意思是“的父母”。所以HEAD^
意思是“当前 HEAD 的父级”。您甚至可以将它们链接在一起:HEAD^^
表示“当前 HEAD 的父级的父级”(即当前 HEAD 的祖父级),HEAD^^^
表示“当前 HEAD的父级的父级的父级”,等等。
回答by cmcginty
The ^
(caret) can also be used when specifying ranges.
的^
时(脱字符号)也可以使用指定范围。
To exclude commits reachable from a commit, a prefix ^ notationis used. E.g. ^r1 r2 means commits reachable from r2 but exclude the ones reachable from r1.
<rev>
Include commits that are reachable from (i.e. ancestors of) .
^<rev>
Exclude commits that are reachable from (i.e. ancestors of) .
要从提交中排除可访问的提交,使用前缀 ^ 表示法。例如 ^r1 r2 表示可从 r2 访问的提交,但排除可从 r1 访问的提交。
<转>
包括可从(即的祖先)访问的提交。
^<转>
排除可从(即的祖先)访问的提交。
回答by cdosborn
Here's a visual explanation. Suppose you have a history like so:
这是一个直观的解释。假设你有这样的历史:
master
... <- B <- C <- D
/
... <- E <- F
feature
When feature was merged into master, C
was created with two ancestors. Git assigns these ancestors numbers. The mainline ancestor B
is assigned 1 and the feature ancestor F
is assigned 2.
当 feature 合并到 master 时,C
是用两个祖先创建的。Git 分配这些祖先编号。主线祖先B
被分配 1,特征祖先F
被分配 2。
Thus C^1
refers to B
and C^2
refers to F
. C^
is an alias for C^1
.
因此C^1
指代B
和C^2
指代F
。C^
是 的别名C^1
。
You would only ever use <rev>^3
. if you had performed a merge of three branches.
你只会使用<rev>^3
. 如果您执行了三个分支的合并。
回答by mopoke
The caret refers to the parent of a particular commit. E.g. HEAD^
refers to the parent of the current HEAD commmit. (also, HEAD^^
refers to the grandparent).
插入符号是指特定提交的父级。例如,HEAD^
指的是当前 HEAD 提交的父级。(也HEAD^^
指祖父母)。
回答by Amber
The carat represents a commit offset (parent). So for instance, HEAD^
means "one commit from HEAD" and HEAD^^^
means "three commits from HEAD".
克拉代表提交偏移量(父)。例如,HEAD^
表示“来自 HEAD 的一次提交”和HEAD^^^
“来自 HEAD 的三次提交”。
回答by TALLBOY
The (^) gets the parent source of the command i.e. HEAD^ will get the parent of HEAD.
(^) 获取命令的父源,即 HEAD^ 将获取 HEAD 的父级。
回答by Ncat
Greg Bacon gave a great link, but it's pretty dense. The Git introductory docs online also introduce revision and range specifiers:
Greg Bacon 给出了一个很好的链接,但它非常密集。在线 Git 介绍性文档还介绍了修订版和范围说明符: