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 OverflowThat'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
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
Hey 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.
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.
I consider merge --squash extremely useful when I use a "branch per feature" approach. My commit history in temporary branches is a complete garbage, absolutely meaningless. And I really want to be unable to see that history anymore, not just to be able to skip it.
When the commits go to code review, it is important not to create extra commits.
There is, but it is nonsense. Why do you want to do that? You'll lose all branch history and information.
You could use g's commit message for your merge commit and then browse history with the --first-parent option.
If you really want to lose history from your branch use git merge --squash, I do not recommend it though.
Edit
In case you are not happy because you do not consider your history very clean, you can use Git's rebase feature:
You can retroactively edit (not really, the old commits still exist and you simply create new ones that look like the old ones) old commits and create new commits from your existing branch (in effect rewriting it). It allows you to reword commit messages, split commits, squash commits into a single commit, re-order commits, etc.
You should only use rebasing when you haven't published your branch (i.e. it is only a private branch), because it will give other developers headache and could cause merge problems later on if someone kept working on the old (before rebased) branch.
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?