Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make empty merge commit (ignoring changes)?

Tags:

git

Automated CI tool merges fixes from release to master. But some commits from release branch should be ignored.

Let's consider the following example:

Release branch contains two fixes: fix-1 should be ignored and fix-2 should be merged to master.

base ----------- merge-fix-2 -        master
  \                  /            
   fix-1 --- fix-2 ---                release

With this configuration merge of fix-2 also includes fix-1 changes.

To avoid this I need empty merge-commit (ignore-fix-1), just for notify Git that fix-1 has been already merged and these changes should be ignored in upcoming merges:

base -- ignore-fix-1 -- merge-fix-2 --  master
  \       /             /            
   fix-1 ----- fix-2 ----               release

The question is: how to do that ignore-fix-1 empty commit?

like image 391
Max Farsikov Avatar asked Aug 09 '18 20:08

Max Farsikov


People also ask

How do I merge without committing changes?

Thus, if you want to ensure your branch is not changed or updated by the merge command, use --no-ff with --no-commit.


1 Answers

You can pass -s ours to git merge to use the "ours" merge strategy, which does exactly what you want: performs a "merge" by completely ignoring the incoming branch.

That said, this is a surprising thing to do to your history, to say the least. I assume you have a compelling reason not to want a hotfix in master, but if this sort of thing happens frequently, you might want to consider a different approach, e.g.:

  1. Split release into stable (for fix-2) and production (for fix-1), then frequently merge stable into both master and production.
  2. Cherry-pick release fixes, rather than merging them.
like image 134
Eevee Avatar answered Oct 18 '22 04:10

Eevee