Git: merge branch and use meaningful merge merge message?

After I merged the function branch into the main branch, I usually need to do the default merge. But I would like to use the original commit messages from my function branch in this commit instead of merging XXX branch.

How can I do it?

+4
source share
5 answers

I found that after performing a merge. I can add the commit commit "git ci --amend" to change the commit message, which does exactly what I requested. I will answer my answer as the correct answer.

Simon Budrias and Ranendra gave corresponding answers, which are also effective in a different way. So I voted for them.

+2
source

Just pass the -m option to the merge command:

 $ git merge other-branch -m "Commit Message" 
+9
source

You basically have two options.

A simple solution: don't team up, rebase
Restore your branch on top of the main branch, resolve the conflict, and then merge. Since you will have a direct history, you can speed up the switch for a merge, and this will not fix the merge.

 git checkout feature git rebase main # Resolve conflict if there is git checkout main git merge feature 

Second Option: Rebase -i
You can edit your story after the merge ( before that you click on the remote). You can control this using the interactive call forwarding mode.

 git checkout main git merge feature #You merge and resolve conflict git rebase -i <sha of the commit before the merge> 

Then you will be taken to an interactive shell with a list of commits, for example:

 pick 73c991e Create progress bar module pick b8a0b83 merge branch feature pick 2120f47 Add user form pick 70c55e4 Quiz prototype system 

You just need to add squash or s instead of pick :

 pick 73c991e Create progress bar module pick b8a0b83 merge branch feature s 2120f47 Add user form pick 70c55e4 Quiz prototype system 

This command will be crushed together by b8a0b83 and 2120f47 . The next step is a commit text editor, in which you have a commit message at the same time, and now you need to edit them correctly to save only the original message.

+7
source

When you have different change commands in the main and local branches, git automatically creates an additional commit for merging. To stop such additional commits, you can reinstall the master in the branch before merging with the master.

 $ git pull(in master which retrieves the new changes> $ git checkout <local_branch> $ git rebase master $ git checkout master $ git merge local_branch. 
+2
source

First copy the original commit message that you want to keep.

Then use git merge , as in the example below:

 $ git checkout mainBranch $ git merge featureBranch --squash --no-commit 

You may need to resolve conflicts.

This method avoids automatic commit, so all files remain in the index; that way, you can commit the code with the original commit message saved in the first step.

I know this is a hoax, but it works. =)

0
source

All Articles