gitgit-commitgitkgit-history-graph

How do I see a commit's path through git history, or "how it got in the current branch"?


I'm looking in the commit history using gitk and git log and I'm trying to see how a specific commit arrived in a certain branch. I can see the commits in the history, so I know they are there.

What I want to understand is how they got merged (they were supposed to remain on their own branch). This is a very large project and there are hundreds of commits between the commit in question and the current state of the branch, so I cannot clearly decipher through the limited DAG in gitk, and the commit gets masked in other branches and merges and commit messages.

To do this, I have been trying:

gitk {sha1hashIDstring}..branch_name
gitk {sha1hashIDstring}..branch_name --ancestry-path
git log {sha1hashIDstring}..branch_name --reverse
git log {sha1hashIDstring}..branch_name --merges --reverse
git log {sha1hashIDstring}..branch_name --ancestry-path --reverse
git log {sha1hashIDstring}..branch_name --ancestry-path --merges --reverse

And I'm not understanding the results. I ONLY want to see items that include the specific commit in question, such that I see clearly how it got into the branch in question. How do I do so?

Example

What I'm looking for, in gitk preferrably but git log would suffice:

Message       Author         Date         #commit that merged branch z into current branch
Message       Author         Date         #commit that merged branch y into branch z
Message       Author         Date         #commit that merged branch x into branch y
Message       Author         Date         #commit that merged {sha1hashIDstring} commit/branch a into branch x
Message       Orig_Author    Date         #{sha1hashIDstring} original commit, on branch a

More Information

I'm not seeing any answers yet, so I'll start a bounty if none come in, but perhaps I'm not explaining the question right (I'm open to suggestions to improve and clarify).

The driver for this is that I can see the commit itself, and I'm being told it should not be on a certain branch. Here's what I'm seeing:

Message       Orig_Author    Date         #{sha1hashIDstring} commit
Message       Orig_Author    Date         #Merged into branch test_dec14 (includes original commit)
...
Message       Author         Date         # unrelated commits
Message       Author         Date         # more unrelated commits
# Stuff happened here ??? everything I do gives me hundreds of things here 
# Not all of them related to the {sha1hashIDstring} commit
# No idea how to see only the ones that are
...
Message       Author         Date         # final commit on test_jan15 branch

I'm being told commits in test_dec14 should not have made it to test_jan15 unless they were released, and as such the {sha1hashIDstring} commit SHOULD NOT BE in test_jan15, yet it is. I want to know why, how it got there, and who put it there.


Solution

  • For the latter part of your question, "how it got in the current branch?", take a look at git-when-merged.

    It's a Python script that will, per its readme:

    Find when a commit was merged into one or more branches. Find the merge commit that brought COMMIT into the specified BRANCH(es). Specifically, look for the oldest commit on the first-parent history of BRANCH that contains the COMMIT as an ancestor.

    This sounds like what you're looking for in the case of determining when the {sha1hashIDstring} commit was merged into test_jan15 branch.