Get parents of a merge commits in git

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.

Git log: list all parents commits

In a shared GitHub repository, I would like to use git log to show a list of recent commits. The current history is similar to the following: (master) B——Merge1–Merge2–Merge3 / / / – -C1 / / –

Show parents of uncommitted merge in git

How can I see the parents of an uncommitted merge in git? I can see one parent by doing git log -1 but how do I see the other parent? This is easy to do in Mercurial: $ hg parents changeset: 2:b65656d

How to get rid of Merge commits in git

I have a repository which is shared by more than 1 person So often I see there are a lot of merge commits in commit history. I want to get rid of them to make my commit history to look cleaner. What i

Git – Merge a part of branch commits

How could I merge several, selected commits from branch B into A. I did this but I am not sure if there is a one line solution for this: git log -p -1 B~~ | git apply git log -p -1 B~ | git apply git

Git files status of merge commits

What do the file status mean in git merge commits? Such as MM, MA, AM? One can see them using git log –merges –name-status -c One of the commits is like: commit 6be3b2d7d24e0ca90260d422b5e7777

Make git pull –rebase preserve merge commits

git pull –rebase removes unpushed merge commits. Is there a way to make it preserve them? Say my history looks like— A | / B H | | C G | | D F | / E (A being the merge commit.) After a git pull –re

Git merge commits

I’m new to git (and enjoying it a lot!). While developing in a new branch, I kept committing the various development ‘states’ of my application. Now I have to check it in for review but didn’t want ev

Git merge commits between branches

I’ve got two branches. Lets call them A & B for now. I want to selectively copy something like 20 commits from A to B. Is there any efficient way to do this? I know I can git cherry-pick commits

How does git handle commits in a merge?

I’m having trouble understanding how a git merge works in terms of the commits created by the merge process. I’ve read the relevant sections in pro git and the git community book, but am still confuse

git cherry-pick merge conflict pulling in other commits?

For some reason, it looks like git cherry-pick pulls in other commits when flies have merge conflicts. These go away when we use git mergetool but prevent us from manually editing the merge-conflicted


Also note that the normal log output shows the abbreviated hashes of the parents, no need to scroll:

 commit 395f65d438b13fb1fded88a330dc06c3b0951046
 Merge: 9901923 d28790d

git always prints them in order of parent number: the first hash is for the first parent, and so on.

If you just want the hashes, two equivalent choices:

git log --pretty=%P -n 1 <commit>
git show --pretty=%P <commit>

rev-list can also show the parent hashes for a commit. It will first list the hash for a commit, followed by the parents’.

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.

Also note that the normal log output does show abbreviated hashes of the parents:

 commit 395f65d438b13fb1fded88a330dc06c3b0951046
 Merge: 9901923 d28790d

The following is the simplest way I’ve found to view the parents of a merge

git show --pretty=raw 3706454