1

I have currently two branches: a development branch and a master branch.

The master branch (ideally) is populated with tagged commits that correspond to releases. One commit, one release, one tag.

The development branch, branches out from the latest release. I develop a new feature and merge back to master.

The problem is that when I do this, the master branch will now have all the commits I have in the development branch but ideally I want to keep the master branch clean and only release commits should be visible.

One solution I've found would be to "cherry-pick" the last commit of a development branch and placing it into master. But this seems to have downsides.

So in the master branch each commit will be cherry-picked from the development branch which will never merge with master.

1)Would this be the "best-practice" approach to keep a release branch clean with only tagged commits? Is there a way to solve this issue with "merge" or some other way? 2)Would merging the development branch would have advantages even though the master branch would not look too clean? (I could solve this with tags).

Asan
  • 327
  • 3
  • 17
  • 2
    Are you making a merge commit, or fast forwarding? Note that cherry-picking only the last development commit will only bring *that commit's changes* into master, which I think *"seems to have downsides"* is underselling. – jonrsharpe Apr 03 '20 at 10:01
  • I branch, develop and commit many times and finally checkout master and merge develop branch. This makes the master branch have all the commits of the develop branch. I think this would be a fast-forward merge from what i've read. – Asan Apr 03 '20 at 10:05
  • 1
    If that's *not* what you want, have you tried [`--no-ff`](https://git-scm.com/docs/git-merge#Documentation/git-merge.txt---no-ff)? – jonrsharpe Apr 03 '20 at 10:06
  • I think this solves the issue. Just to clarify, i'm using the git bash and when I do git log, I can still see all the commits of the develop branch. This is because from the master branch I should be able to see all the commits that lead to the current position even though they are not from the same branch right? Even though the commit I merged is the only one that belongs to gamma master. – Asan Apr 03 '20 at 10:53
  • 1
    A merge commit has two parents, you may see both depending on your log settings – jonrsharpe Apr 03 '20 at 10:54

1 Answers1

3

Looks like you want

git merge --squash develop

How to use git merge --squash?

You can also use interactive rebase if you only want a subset of the commits

git rebase -i origin/master

Then follow the prompts to squash the desired commits into your master branch.

Jeremy Ninnes
  • 553
  • 3
  • 15
  • 1
    This would solve the issue. However I think a non-explicit commit using --no-ff would allow me to track all the previous changes in the development branch. This would unify all the commits into one commit and place it in the master branch (squash). In the end if opted for the other option that @jonrsharpe suggested. – Asan Apr 03 '20 at 11:21