如何在git中获取合并提交的父母? [英] How to get the parents of a merge commit in git?

查看:102
本文介绍了如何在git中获取合并提交的父母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些git命令将父级作为修订版;其他(例如git revert)作为父编号.两种情况下如何获得父母.我不想使用图形化日志命令,因为这通常需要向下滚动一棵长树才能找到第二个父级.

解决方案

调用合并提交的简单git log <hash>会显示其父级的简短哈希值:

 $ git log -1 395f65d
 commit 395f65d438b13fb1fded88a330dc06c3b0951046
 Merge: 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>

如果要检查父母,则可以直接用克拉来指称他们为<commit>^1<commit>^2,例如:

git show <commit>^1

这确实是普遍的;对于章鱼合并,您可以将第n th 父代称为<commit>^n.您可以使用<commit>^@引用所有父级,尽管在需要一次提交时这不起作用.其他后缀可以出现在第n 个父语法之后(例如<commit>^2^<commit>^2^@),而不能在^@之后(<commit>^@^无效).有关此语法的更多信息,请阅读 rev-parse 手册页. /p>

Some git commands take the parent as a revision; others (such as git revert), as a parent number. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆