Home > front end >  Git: Is it possible to produce an output showing which commits differ between two branches?
Git: Is it possible to produce an output showing which commits differ between two branches?

Time:03-29

I want to be able to do something like a git diff between two branches, but show the commit ids of which commits exist on one branch but not the other. (And vice-versa.)

Adding to the complexity, I also need to be able to see who authored these commits.

Is such a thing possible?

CodePudding user response:

You can see the commit ids of which commits exist on one branch but not the other

You can use the following command

$git log wip..wip2 --oneline --no-merges

enter image description here

And for the author name you can try shortlog .. I am sure you can use grep to do these in a same line

enter image description here

$ git shortlog wip..wip2 --oneline --no-merges

CodePudding user response:

Consider not only the two-dot syntax (as shown in microtechie's answer), but also the three-dot or symmetric difference syntax:

git <insert log commands and options> br1...br2

where the three dots between the two branch names are literally three dots.

There's one problem, of sorts, with this: it selects all commits reachable from either br1 or br2, excluding all commits reachable from both br1 and br2, so this means you need some way to know which name reaches which commits. There are two ways to get this kind of information:

  1. Use the --left-right option, which inserts < or > markers to tell you that some commit is found via the left-side name (br1 in this case) or the right-side name (br2).

  2. Use --graph or some other graph-drawing software.

Since the graph is usually extremely important, I tend to prefer --graph here; --left-right is more for scripts. Using --graph with --oneline is particularly useful: see Pretty Git branch graphs.

Note that --oneline drops the author, but you can use --graph without --oneline, or with --format= (or --pretty=tformat:) and specify your own format, with whatever information you want. Again, see Pretty Git branch graphs.

  •  Tags:  
  • git
  • Related