在git中获取合并提交的父母 [英] Get parents of a merge commit in git
问题描述
git revert
)作为父号码。我想知道如何让这两种情况下的父母。我不想使用图形化日志命令,因为通常需要向下滚动长树才能找到第二个父级。简单 git log< hash>
调用合并提交显示其父母的缩写哈希:
$ git log -1 395f65d
commit 395f65d438b13fb1fded88a330dc06c3b0951046
合并:9901923 d28790d
...
git
根据它们的编号输出父母:第一个(最左边的)散列用于第一个父母,依此类推。
如果你想要的只是散列,那么两个等价的选择是:
$ git log --pretty =%P -n 1< commit>
$ git show -s --pretty =%P< commit>
git rev-list
也可以显示父母'散列,尽管它会首先列出提交的散列:
$ git rev-list --parents -n 1 <提交>
如果你想检查父母,你可以直接用克拉引用它们作为< commit> ^ 1
和< commit> ^ 2
,例如:
git show< commit> ^ 1
推广;对于章鱼合并,您可以将 th 父母称为< commit> ^ n
。你可以用< commit> ^ @
来引用所有的父母,尽管这在需要单个提交时不起作用。额外的后缀可以在第n个父语法之后出现(例如,< commit> ^ 2 ^
,< commit> ^ 2 ^ @
),但它们不能在 ^ @
之后(< commit> ^ @ ^
无效)。有关此语法的更多信息,请阅读 rev-parse
手册页。
Given a merge commit, how can I get its parents? Some git commands take the parent as a revision; others (such as git revert
), as a parent number. I’d like to know how to get the parents for both cases. I don’t want to use the graphical log command as that often requires scrolling down a long tree to find the second parent.
Simple git log <hash>
called for a merge commit shows abbreviated hashes of its parents:
$ git log -1 395f65d
commit 395f65d438b13fb1fded88a330dc06c3b0951046
Merge: 9901923 d28790d
...
git
outputs parents according to their number: the first (leftmost) hash is for the first parent, and so on.
If all you want is just the hashes, the two equivalent choices are:
$ git log --pretty=%P -n 1 <commit>
$ git show -s --pretty=%P <commit>
git rev-list
can also show the parents' hashes, though it will first list the hash for a commit:
$ git rev-list --parents -n 1 <commit>
If you want to examine the parents, you can refer to them directly with carats as <commit>^1
and <commit>^2
, e.g.:
git show <commit>^1
This does generalize; for an octopus merge you can refer to the nth parent as <commit>^n
. You can refer to all parents with <commit>^@
, though this doesn't work when a single commit is required. Additional suffixes can appear after the nth parent syntax (e.g. <commit>^2^
, <commit>^2^@
), whereas they cannot after ^@
(<commit>^@^
isn't valid). For more on this syntax, read the rev-parse
man page.
这篇关于在git中获取合并提交的父母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!