In git 1.7.10, the git developers decided merge commits could be made too easily. As explained in this blog post, forcing the interactive commit message behavior should make those commit messages more detailed and could reduce the overall frequency of unnecessary merges.
You can use the --no-edit flag to avoid this behavior, but, well, don't. Merge commits, like any commits to history, should be well constructed. Your history should be nothing but useful.
In git 1.7.10, the git developers decided merge commits could be made too easily. As explained in this blog post, forcing the interactive commit message behavior should make those commit messages more detailed and could reduce the overall frequency of unnecessary merges.
You can use the --no-edit flag to avoid this behavior, but, well, don't. Merge commits, like any commits to history, should be well constructed. Your history should be nothing but useful.
To create a shortcut for future use, either:-
Edit your ~/.gitconfig with the following:
[core]
mergeoptions = --no-edit
Or execute the following in Terminal
git config --global core.mergeoptions --no-edit
If git pull is essentially git fetch + git merge, why does it not ask for a merge commit message
How to make 'git pull' take a message? - Stack Overflow
merge - How to git pull with custom commit message? - Stack Overflow
How to get commit message on pull_request workflow?
If I manually do git merge, it'll open up an editor for me to modify/save the merge commit message. But when I do git pull, it just works. Why?
Edit: here's my guess, lmk if I'm on the right track. Before, I wasn't seeing a message when doing git pull because the changes were such that it was just a fast-forward pull. So no merge was even necessary; in essence an empty merge comit message was used (which I'm guessing means no commit actually occurred). When doing an actual merge, of course a merge is happening, so it prompts you to make a merge commit message. And then when doing a pull that isn't as straightforward, i.e. a merge conflict occurs, it will make you fix the conflict, and then commit that change, which serves as the merge commit message.
So I need to change my merge commit message produced by git pull to another message.. Is it possible?
Yes. After the pull, if a merge commit was created, say
git commit --amend
You will be asked for a replacement commit message.
However, you should have done this together with the pull, by saying
git pull --edit
And yes, I know that git pull is a shorthand for git fetch and git mergeI read from another similar question on SO but I just can't grasp that
Grasp it. You never need to say pull; it is confusing and dangerous. To merge master into the branch you are on, say
git fetch
git merge origin/master
Again, to avoid having to rewrite the commit message later, say
git fetch
git merge --edit origin/master
You asked: "What is the safest command to fetch and merge with custom message?" That.
(It is also possible to configure your Git so that a merge commit always offers you the chance to edit its message. I prefer it that way. Recent Git versions are set up this way by default; you might be using a somewhat outdated Git, else the problem would never have arisen.)
The easiest would be to do git pull as usual, then run :
git commit --amend -m"New commit message"
This will rewrite the last commit message that was commited.
Be aware that you should not use this if you already pushed that particular commit, because this will then need you to do git push --force which is usually bad practice.
Note that you can create a new branch for your current changes before doing the merge with master.
From Git Documentation:
Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD
As to your question about: WHY
- Why is Git creating a MERGE commit: That is the default behavior of
git pull. There are lots of explanation of this behavior on the internet, this does a good job of explaining it. - Why is Git asking for a commit message now: Three possible options come to my mind:
- You updated your git client
- You never had a local branch which was ahead of the remote before
- Your git config was changed recently
How to avoid this:
Since your local repository is 1 commit ahead, git tries to merge your remote to your local repo. This can be handled via merge, but in your case, perhaps you are looking for rebase, i.e. add your commit to the top. You can do this with
git rebase or git pull --rebase
If this is indeed the behavior you are looking for, you can setup your git config to make rebase a default option for your git pull
Set it up globally with:
git config branch.autosetuprebase always # Force all new branches to automatically use rebase
Or you can set it up per branch:
git config branch.*branch-name*.rebase true # Force existing branches to use rebase.
- Press i (i for insert)
- Write your merge message
- Press esc (escape)
- Write :wq (write & quit)
- Then press enter
Hi all,
So today I submitted my first bug in a public project/repo, I also put the fix in the report (it was just a documentation bug, and I realised the right command I had to use). Then the person asked me to submit a pull request?
So... I've never done that before, or forked anything to be honest. I am a nervous fellow, so I want to make sure I don't mess up the pull request. I've already forked the master branch, made the changes, but now I have to write a commit message / extended description.
Does anyone have any advice/general practices I should follow? I've googled a bunch and tried to keep the initial message short and concise ("Fixed command path"), but I'm not sure what to put for the extended description considering it's just changing two lines of text.
It's also been a couple hours since they requested the PR, I hope they don't think I've spent hours on the PR (even though I might've have).
Thanks!!
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)