3

For example, when I merge from master -> production, I'd like to see a list of the commits before I, err, commit to them. Something like:

$ git merge --doublecheck master
Commits to merge:
1292642 fix foo
3c0f30b cleanup bar
Do you want to proceed? (y/n)
David Wolever
  • 148,955
  • 89
  • 346
  • 502

4 Answers4

4

You can use revision range double-dot .. syntax to do this:

git log --oneline --graph <branch-to-merge-into>..<branch-to-be-merged>

The output will be all commits in <branch-to-be-merged> that aren't in <branch-to-merge-into>.

You can learn more about this and other revision range syntaxes in the Commit Ranges section of the FREE online Pro Git book.

1

You can prevent Git from committing automatically with the --no-commit and --no-ff flags:

git merge master --no-commit --no-ff

If the current branch and master have diverged, then --no-commit is enough. If master is simply a couple of revisions ahead then Git will automatically fast-forward, and there isn't really a commit in this case. The --no-ff prevents this automatic fast forward.

If you do this, the changes that result from the merge will be in a pending state, not committed. I do this when doing code-reviews, as it's easy to diffs in this state. If you do this often it's practical to create an alias for it in your ~/.gitconfig, for example:

rev = merge --no-ff --no-commit

In the end, I reset and let Git do the committing, as it generates a nice commit log as the summary of all commit logs of the merged revisions.

janos
  • 120,954
  • 29
  • 226
  • 236
  • While this shows the result of the merge, it doesn't show which commits are being merged in, which is what the original poster asked for. –  Sep 02 '13 at 20:51
0

Another techniques is to use the --no-commit and -no-ff option (similar to the git commit --dry-run option), so you can see the actual results. See the Examples section of the merge(1) man page.

see also SO/is-there-a-git-merge-dry-run-option and git merge without auto commit

Community
  • 1
  • 1
Philip Oakley
  • 13,333
  • 9
  • 48
  • 71
  • While this shows the result of the merge, it doesn't show which commits are being merged in, which is what the original poster asked for. –  Sep 02 '13 at 20:48
0

I've taken some of the suggestions here and written a little script, git-safemerge:

 $ git safemerge master
 Commits:
  * bc911ef Fix bug in widget
  * e80f8d1 Clean things up

 Changes:
  foo.py   |  12 ++--
  bar.py   |  35 +++++-----
  2 files changed, 47 insertions(+), 47 deletions(-)

 Fast-forward: not possible

 Continue merging master into prod? (y/n)

It's available at: https://gist.github.com/wolever/6416735

David Wolever
  • 148,955
  • 89
  • 346
  • 502