I have a remote Git server, here is the scenario which I want to perform:
For each bug/feature I create a different Git branch
I keep on com
Merge newFeature
branch into master
with a custom commit:
git merge --squash newFeature && git commit -m 'Your custom commit message';
If instead, you do
git merge --squash newFeature && git commit
you will get a commit message that will include all the newFeature
branch commits, which you can customize.
I explain it thoroughly here: https://youtu.be/FQNAIacelT4
You want to merge with the squash option. That's if you want to do it one branch at a time.
git merge --squash feature1
If you want to merge all the branches at the same time as single commits, then first rebase interactively and squash each feature then octopus merge:
git checkout feature1
git rebase -i master
Squash into one commit then repeat for the other features.
git checkout master
git merge feature1 feature2 feature3 ...
That last merge is an "octopus merge" because it's merging a lot of branches at once.
Hope this helps
Suppose you worked in feature/task1 with multiple commits.
Go to your project branch (project/my_project)
git checkout project/my_project
Create a new branch (feature/task1_bugfix)
git checkout -b feature/task1_bugfix
Marge with the --squash
option
git merge --squash feature/task1
Create a single commit
git commit -am "add single comments"
Push your branch
git push --set-upstream origin feature/task1_bugfix
Use
git status
to check what's going on.
Then
git checkout master
git merge --squash bugfix
git add (add which files you want or use wildcard command like ".")
Then
git commit -m "message"
And now last but not the least
git push -u origin master
Here origin
can be other remote you prefer.
You can use tool I've created to make this process easier: git-squash. For example to squash all commits on feature branch that has been branched from master branch, write:
git squash master
git push --force
What finally cleared this up for me was a comment showing that:
git checkout main
git merge --squash feature
is the equivalent of doing:
git checkout feature
git diff main > feature.patch
git checkout main
patch -p1 < feature.patch
git add .
When I want to merge a feature branch with 105(!!) commits and have them all squashed into one, I don't want to git rebase -i origin/master
because I need to separately resolve merge conflicts for each of the intermediate commits (or at least the ones which git can't figure out itself). Using git merge --squash
gets me the result I want, of a single commit for merging an entire feature branch. And, I only need to do at most one manual conflict resolution.