Git: Merge in only one commit

Ivan picture Ivan · Jan 5, 2011 · Viewed 36.6k times · Source

Usually, I work with branches in Git, but I don't like to see hundreds of branches in my working tree (Git history). I'm wondering if there is a method in Git to "join" all commits in a branch in only one commit (ideally with a clear commit message).

Something like this:

git checkout -b branch
<some work>
git commit -a -m "commit 1"
<some work>
git commit -a -m "commit 2"
<some work>
git commit -a -m "commit 3"
git checkout master
git SUPER-JOIN branch -m "super commit"

After this, only "super commit" will exist in the git log.

Answer

Greg Hewgill picture Greg Hewgill · Jan 5, 2011

It sounds like you're looking for the --squash option of git-merge:

git checkout master
git merge --squash branch -m "super commit"