lang2
lang2

Reputation: 11966

git: hide detailed commit on branch

I'm wondering if this is possible in git. So I have the master branch. Now and again I'll create a side branch for a feature development. When that's finished, I'll merge it back to master. Now normally all the commit history on the side branch will be shown in the master branch. Is there a way to make all the commit to appear as one on the master?

Upvotes: 3

Views: 221

Answers (2)

Antonio Pérez
Antonio Pérez

Reputation: 6982

$ git checkout master
$ git merge --squash <branch>

From the docs (emphasis mine):

--squash
--no-squash
Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit, move the HEAD, or record $GIT_DIR/MERGE_HEAD (to cause the next git commit command to create a merge commit). This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in case of an octopus).

With --no-squash perform the merge and commit the result. This option can be used to override --squash.

Upvotes: 5

Chris Maes
Chris Maes

Reputation: 37742

Suppose you made your developments on a side branch:

git checkout -b dev_branch
< do your changes, and commit them >

Now if you want all commits to appear as one single commit, you do the following. If you want to keep all commits as they are, skip to the following step.

git rebase -i master
< in the interface you should now keep the first commit, and select `squash` for all the successive commits >

now you want to rebase your master branch on your side branch and delete that branch:

git checkout master
git rebase dev_branch
git branch -d dev_branch

Upvotes: 2

Related Questions