Git: after creating a real merge, how to create a simple commit?

After calling git merge --no-commit <commit> , committing will commit the merge with two (or more) parents. Which command to invoke to create a simple commit instead (without re-executing the merge command with the --squash option)?

+6
git git-merge
source share
3 answers

According to the git -merge man page, the -squash option does not write $ GIT_DIR / MERGE_HEAD>. $ GIT_DIR / MERGE_HEAD is responsible for creating the merge commands ; you can see this in Git sources, builtin / commit.c file :

in_merge = file_exists(git_path("MERGE_HEAD"));
...
if (in_merge) {
... // Perform merge_commit
}

Solution : after performing a normal merge, just get rid of $ GIT_DIR / MERGE_HEAD to avoid getting the merge. You can manually clear $ GIT_DIR / MERGE_MSG and $ GIT_DIR / MERGE_MODE, or leave this task to Git if you commit successfully.

+4
source share

The best solution without hacking in the .git directory is to use erase and reset.

 >git merge --no-commit $otherbranch >git stash >git reset HEAD >git stash pop >git commit -a 

It should be trivial to automate if you need it more often.

Please note that this seems to work without the code part at a glance, but it fails to add files, so unnecessary passage through the cache cannot be omitted.

+1
source share

You can try git merge --squash .

See the question " In git, what is the difference between merge --squash and rebase ? "

from

  X stable / a---b---c---d---e---f---g dev 

in

  X-------------------G stable / a---b---c---d---e---f---g dev 

It will perform a compressed commit to the destination branches, not marking any merge relationships.

0
source share

All Articles