Git only merges the final output of the development branch

If your Git repository structure looks like this:

master: A-C
dev:     \B-D-E

      

it is possible to merge the development branch into master so that only one commit is added to master containing all the changes found across all commits in the development branch. So the above structure will merge to look like this:

master: A-C-E'

      

The end E'

will contain all the changes in the development branch and only the latest commit message, adding a new feature to master in one neat commit.

Is this possible in Git? I hope to keep the history of the GitHub repository neat, as my development branches often contain early commits that are unfinished, unpolished, and unusable for human consumption.

+3


source to share


2 answers


The merge part should be simple (see How to use git-merge --squash

?
"):

git checkout master
git merge --squash dev

      

You may need to customize the commit message:



git commit --amend -m "<commit message from E>"

      

(you have other options when doing the merge )

+3


source


You can achieve this, although it will not be a merge. (Remember: a merge has 2 or more parents. E'

Has only one parent:. C

)

git rebase -i master dev

      

  • A text editor will open. Change pick

    to squash

    for all but the first line, then save the file and close the editor.
  • A text editor will open. (Completed with different content.) Edit its content as the commit message you want for E'

    , then save the file and close the editor.


Then

git checkout master
git merge dev --ff-only
git branch -d dev

      

+1


source







All Articles