1

From docs(https://git-scm.com/docs/git-merge)

SYNOPSIS

git merge [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
    [-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
    [--[no-]allow-unrelated-histories]
    [--[no-]rerere-autoupdate] [-m <msg>] [-F <file>] [<commit>…​]
git merge --abort  
git merge --continue

DESCRIPTION

"git merge topic" will replay the changes made on the topic branch

There is no mentioning of branches in synopsys, it lists [<commit>…​] but all examples show merge with branches.

  • Is it incorrect help output or am I missing something?
  • Can you merge a specific commit? (looks like have been asked in 2009: How to merge a specific commit in Git - is it up-todate ?)
Alexei Martianov
  • 2,291
  • 3
  • 23
  • 50

2 Answers2

2

Branch is a reference to a commit. So you can specify a commit by any way (a branch, a tag...).

Git will search the common ancestor and create merge commit. Merge commit represent itself changes from commit sequence which begin from common ancestor to specified reference.

If you need to merge only some amount of commits form specified sequence (not all of them) you need to do rebase some of them to separated sequence (or use cherry-pick command for each commit) and merge new sequence. Or any combination.

If you need to merge only one specific commit you can cherry-pick it but it will be not an merge commit but generic commit. To do actually merge commit with a branch contains only one commit use previous approach.

oklas
  • 6,279
  • 2
  • 21
  • 36
0

You can use Cherry Pick

  1. Checkout the branch where you want to cherry pick the specific commits. In this case master branch:

    git checkout master

  2. Now you can cherry pick from your features branch:

    git cherry-pick ae79cffbcf5e14e776903521009b9361fe35fd76

This will cherry pick the commit with hash ae79cffbcf5e14e776903521009b9361fe35fd76 and add it as a new commit on the master branch.

Note: it will have a new (and different) commit ID in the master branch.

IMParasharG
  • 1,743
  • 1
  • 13
  • 23