Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: hide detailed commit on branch

Tags:

git

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?

like image 562
lang2 Avatar asked Jan 21 '26 16:01

lang2


2 Answers

$ 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.

like image 89
Antonio Pérez Avatar answered Jan 23 '26 14:01

Antonio Pérez


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
like image 22
Chris Maes Avatar answered Jan 23 '26 13:01

Chris Maes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!