That's a default merge commit message. It doesn't take anything special to get it - just do any nontrivial merge into master:
- o - o - X (master)
\ /
o - o (topic)
The default commit message for commit X will be "Merge branch 'topic'". If you merge into a branch other than master, the default message is "Merge branch '<merged-branch>' into '<branch>'".
I'm not sure why you're asking about "fixing" and "avoiding" this. It's a very reasonable default message for a merge commit. If you'd like a more detailed merge commit message, you're certainly welcome to provide one. (The two primary ways are to use git merge --no-commit followed by git commit, or git merge followed by git commit --amend to edit the message.)
Perhaps you're used to doing only fast-forward merges? (Those are trivial merges, where the commit you're merging has your current branch as ancestor, so all git has to do is move the branch forward through history.) Those don't generate merge commits, so there's no commit message.
(By the way, pushing has nothing to do with this - all it does is copy information from one repo to another. It doesn't ever create commits.)
Answer from Cascabel on Stack OverflowHey y'all,
I'm a bit of a beginner in Git usage and GitHub, so I am having some trouble merging two branches.
I have a repository A (forked from a repository X) on which I made changes. At the same time, other developers have made changes on their own fork of X (let's call it B), more specifically, they created a branch in addition to the fork. I now want to merge these two versions (the branch of B and my own fork A), but ideally I would like to be able to look at all the changes and accepting them one by one (or not).
Basically, this is what I want:
...-o-o-x-------C
|\ /|
| A---/ |
\ /
B---/But, I'd like to be able to control exactly which changes get made. Here are the commands I used:
git clone <url to my repo A> A git clone <url to the other repo B> B cd A git remote add B ../B git fetch B --tags git merge --squash --allow-unrelated-histories B/main git reset
Now, I opened VS code, hoping that all the changes would not be committed (as I used --squash, or at least so I thought), but the files have all been changed, some deleted, others created, and I only have the option of syncing the changes to Git. Attached is a screenshot of source control in VS Code showing no changes at all (nor can they be reverted? Or so it seems...)
Thank you for your help.
How to "git merge" without creating a merge commit? - Stack Overflow
How to exit a git merge asking for commit message? - Unix & Linux Stack Exchange
git - merge branches without commit messages - Stack Overflow
git merge without commiting - Stack Overflow
That's a default merge commit message. It doesn't take anything special to get it - just do any nontrivial merge into master:
- o - o - X (master)
\ /
o - o (topic)
The default commit message for commit X will be "Merge branch 'topic'". If you merge into a branch other than master, the default message is "Merge branch '<merged-branch>' into '<branch>'".
I'm not sure why you're asking about "fixing" and "avoiding" this. It's a very reasonable default message for a merge commit. If you'd like a more detailed merge commit message, you're certainly welcome to provide one. (The two primary ways are to use git merge --no-commit followed by git commit, or git merge followed by git commit --amend to edit the message.)
Perhaps you're used to doing only fast-forward merges? (Those are trivial merges, where the commit you're merging has your current branch as ancestor, so all git has to do is move the branch forward through history.) Those don't generate merge commits, so there's no commit message.
(By the way, pushing has nothing to do with this - all it does is copy information from one repo to another. It doesn't ever create commits.)
git merge -m
I am using git 1.7.8
Note the output while doing the merge - it is saying Fast Forward.
In such situations, you want to do:
git merge <name-of-branch> --no-commit --no-ff
Important: If you do it this way, then you are not able to do any changes to the files in the staging area e.g. you can't remove/add files or make any changes to the files.
If you want to merge the changes and then commit as if you had manually typed all of the changes you merged in (as opposed to a traditional merge) you need to run rm .git/MERGE_HEAD afterward, which will force git to forget that the merge happened.
You're misunderstanding the meaning of the merge here.
The --no-commit prevents the MERGE COMMIT from occuring, and that only happens when you merge two divergent branch histories; in your example that's not the case since Git indicates that it was a "fast-forward" merge and then Git only applies the commits already present on the branch sequentially.
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)
So my tree looks like this, where X is always a commit:
X
X
| X
| X
X |
X |
\ |
\|
X
X
Where the branch on the right is the dev branch and the left one is the feature branch. What I want is to silently get rid of the feature branch, and act as if I had committed the changes to the dev branch to begin with. The timeline order doesn't matter, so the commits on the right branch can be before the earlier commits in the feature branch.
How can I do this without git merge, since it leaves ugly merge commit message?
# A-B-C <-dev
# \
# D-E-F <-feature
git checkout feature
git rebase dev
# A-B-C <-dev
# \
# D-E-F <-feature
git checkout dev
git merge feature
# A-B-C-D-E-F <-dev,feature
This rebases feature onto dev and then merges it in using "fast-forward" merge, which doesn't require a merge commit. Fast-forward merges are the default in git, but you can give git merge options to make sure it only does fast-forward merges if that's what you want. I'm aware of projects that use merge commits regularly but every team I've worked on has preferred keeping a linear history.
Change the commit message for the merge to something better. And why does the Git log need to be pretty? It's meant to inform you of what's been done.
case:
remote branch: first commit, second commit
corrosponding local branch: first commit
Now, I am in the working space, and the working space is clean
I want get the second commit code change to my working space, just like I type the change on my working space
How to do it with git?
I have a branch test1 from which I created a new branch test2. It looks like below.
test1 => X => Y => other commits => test2 where X and Y are two commits.
Now, I want to merge all changes in test2 branch back to test1 branch, except for the changes associated with the two commits X and Y. It's also worth mentioning that the changes in commits X and Y are in files that are not touched by the other commits.
How do I do this? (Also, I don't want such merge to automatically commit.)