Home > Software design >  Git merge changes without merge commit
Git merge changes without merge commit

Time:08-15

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?

CodePudding user response:

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

CodePudding user response:

Quote from reference document at https://git-scm.com/docs/git-merge#_options

--commit
--no-commit
Perform the merge and commit the result. This option can be used to override --no-commit.

When you use --no-commit , it just does not conduct a combo commands, then you commit manually, it likes normal --no-ff

  • Related