tags:

views:

18

answers:

1

What's the best way to view commits that were originally committed to a specific branch. For example, if I have two branches Jack and Kate:

Jack:  A-B-C-m-F
            /
Kate:    D-E

Is there a command that lists A, B, C, and F as commits made on Jack. I know there are ways to visualize this, but on projects with lots going on it's really hard to trace everything.

A: 

There is a way!

git log --first-parent Jack

You can also pass the --first-parent option to gitk, if you prefer the graphical view. (And as usual with gitk, you can also set that option from within gitk, by going to view > new view and checking the "Limit to first parent" option.)

This isn't precisely what you asked for - what it actually does is only follow the first parent of merge commits (the merged-into parent, not the merged parent). In your case, this will get you exactly what you want.

Just keep in mind that git doesn't actually record what branch you were on when you made a given commit. That information isn't really relevant; what's important is the content of the commit (including who its parent(s) are). So, if you actually made commit B on some other branch, then merged it (fast-forward) into Jack, B would still be listed.

Jefromi