Search code examples
gitemacsmagit

How do I merge branches with Magit using a new commit object?


I can’t seem to get my merges intact with Magit for Emacs without squashing them into the current branch consistently. Sometimes a new commit object is created after the merge (which is what I want), sometimes commits are squashed.

I basically just want to do 'git merge --no-ff topicbranch' in Magit.

So how do I enforce the --no-ff flag/create new object rule with Magit?


Solution

  • Maybe because that patch has be included in the current Magit?

    (defun magit-manual-merge (rev)
    -  (interactive (list (magit-read-rev "Manually merge" (magit-guess-branch))))
    +  (interactive (list (magit-read-rev (concat "Manually merge"
    +                                             (if current-prefix-arg " (squashed)" ""))
    +                                     (magit-guess-branch))))
       (if rev
    -      (magit-run-git "merge" "--no-ff" "--no-commit"
    +      (magit-run-git "merge" "--no-commit" (if current-prefix-arg "--squash" "--no-ff")
                 (magit-rev-to-git rev))))
    

    If you would like to squash the merge (have git avoid creating a merge commit) then use a prefix argument with the command (@kbd{C-U m})

    Are you using a prefix argument?