Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge a topic branch on git, removing all the topic branch's commit history?

Tags:

git

branch

I would like to know if the following is possible in git:

Suppose I have the following history:

A---B---C---D---E  master
         \
          W---X---Y  topic

I would like to merge all the changes made in the topic branch back to master, but without retaining the commit history. That is, instead of:

A---B---C---D---E---F  master
         \         /
          W---X---Y  topic

I would like to have the following history:

A---B---C---D---E---F  master

Where F is a new commit in the master branch that is equivalent to the changes made in commits W, X, Y, applied all at once.

I would also like to be able to keep the topic branch intact:

A---B---C---D---E---F  master
         \         
          W---X---Y  topic

Is this possible? I've been making some tests with git rebase, but so far it hasn't behaved on the way I need.

Thanks in advance.

like image 526
Marco Aurélio Avatar asked Feb 23 '23 10:02

Marco Aurélio


1 Answers

It should be simpler than what bad zeppelin suggested, but I haven't tried this:

$ git checkout master
$ git merge --squash topic
$ git commit *what has changed*

However, when I understand git help mergeright, it should do the trick.

like image 100
Boldewyn Avatar answered Feb 26 '23 06:02

Boldewyn