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.
Git Cherry-Pick — Selecting Specific Commits to Merge As you know, when you are working with Git and need to do a merge between two branches, every commit in the source branch will be merged in the target branch without exception.
Git merging combines sequences of commits into one unified history of commits. There are two main ways Git will merge: Fast Forward and Three way. Git can automatically merge commits unless there are changes that conflict in both commit sequences.
It sounds like you're looking for the --squash
option of git-merge
:
git checkout master git merge --squash branch -m "super commit"
This can be done using git rebase
and squash, or using git merge --squash
, see
Git merge flattening
and
git: squash/fixup earlier commit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With