Search code examples
gitgithubversion-controlpushcommit

Git merge changes without merge commit


I am merging changes of one branch to another using no-ff and no-commit flags as following.

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

But when I commit with my own message and push it, github still shows detail as merged branch a into b

How can I only take changes without taking any commit or any change metadata details?


Solution

  • I think you have a misconception about what merge --no-commit does. You appear to think that it will not create a relation to the merged branch when you commit? That's not the case. --no-commit does the whole thing and delays the commit (you might have things to do before the commit is done)... but then the revision is created (when you actually run git commit later). it will relate to the merged branch, and you will end up with a merge revision. It is exactly the same as doing:

    git merge --no-ff
    # do stuff that you want to include in the merge revision
    git add . # add those changes
    git commit --amend --no-edit
    

    If what you want is avoid the merge revision, you might try this instead:

    git merge --squash the-other-branch
    

    Given that squash does not create a relation (at least, in terms of parents.... you might have some of that in the comment, which is irrelevant to git when establishing parenting relations) to the merged branch, it's not possible to see that the branch has been merged.

    Or this other longer and completely unnecessary path:

    git merge --no-ff # let it run the merge, just as usual
    git reset --soft HEAD~ # go back to the parent revision
    git commit -C HEAD@{1} # commit, no merge, use the same comment as the original merge commit