Whenever I try to merge a branch, I get the following screen prompting me to add a message. When I try to add a message I can only use up and down keys and I can't enter any text. Also, I'm not sure how to submit it so that the screen prompt goes away and back to the normal terminal. Any help would be appreciated, thanks.
version control - git: merge branch and use meaningful merge commit message? - Stack Overflow
How to exit a git merge asking for commit message? - Unix & Linux Stack Exchange
Merge commit message with list of commits
Can't enter commit message in Git after merging branch. Any advice?
Just pass the -m and --no-ff parameters to the merge command:
$ git merge other-branch -m "Commit Message" --no-ff
The --no-ff parameter is required to prevent merging as a fast-forward without merge commit.
You basically have two option.
Easy solution: don't merge, Rebase
Rebase your branch on top of the main branch, resolve conflict, and then merge. As you'll have a straight history, you'll be able to fast-forward to merge and this won't create any merge commit.
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 history after your merge (before you push to a remote). You can manage this with rebase interactive mode.
git checkout main
git merge feature
#You merge and resolve conflict
git rebase -i <sha of the commit before the merge>
Then you'll be taken into an interactive shell with the list of the commits, e.g.:
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 would squash together b8a0b83 and 2120f47. The next step will be a commit text editor where you have both commit message combined, and it's now up to you to edit them correctly to only keep your original message.
This is depend on the editor you're using.
If vim you can use ESC and :wq or ESC and Shift+zz. Both command save file and exit.
You also can check ~/.gitconfig for editor, in my case (cat ~/.gitconfig):
[user]
name = somename
email = [email protected]
[core]
editor = vim
excludesfile = /home/mypath/.gitignore_global
[color]
ui = auto
# other settings here
The answer marked correct here did not work for me as after you quit the editor with wq or :q!, the file gets saved and the merge happens.
The alternative, I've found for now is to suspend the vim process by using a Ctrl + Z and then aborting the merge with a git merge --abort and then killing the background process (you'll see the PID when you do the Ctrl + Z)