Reputation:
Say we create a topic/feature branch and we are working on it for a week. To keep up to date with the integration branch we could use git rebase
, but for the sake of the question let's use git merge
. So we create merge commits in our feature branch - merging the integration branch into the feature branch, as we go.
I believe these merge commits are basically useless noise at the end of the day. Is there a good way to get rid of these merge commits when merging the feature branch into the integration branch when you are done with the feature? I assume squashing the branch into one commit is one way to do that?
Upvotes: 0
Views: 155
Reputation: 60275
I believe these merge commits are basically useless noise at the end of the day. Is there a good way to get rid of these merge commits
Tell git what branch you're tracking and your command is a plain git rebase
.
Make wizzo
track dev with e.g. git branch -t wizzo dev
, work some on dev, work some on wizzo, merge, work more on both, you get something like this:
* f7b551f (dev) 4dev | * 982b0c7 (HEAD -> wizzo) 3wiz | * 5de6750 Merge branch 'dev' into wizzo | |\ | |/ |/| * | 2e8c7ec 1dev | * a320e00 2wiz |/ * c823194 Init
After a plain git rebase
:
* 096cbfc (HEAD -> wizzo) 3wiz * 8e5d6c5 2wiz * f7b551f (dev) 4dev * 2e8c7ec 1dev * c823194 Init
git rerere
is built to make this workflow as painless as possible, it remembers how you resolved merge conflicts so when you eventually rebase back like this a month from now, even if you don't remember what you did, Git does.
Upvotes: 1
Reputation: 744
Tymtam is right, but if you want to do it by hand you can do:
git checkout a
git merge b
git reset --soft origin/a
git add -A
git commit -m "Single commit all changes"
Upvotes: 0
Reputation: 34987
Yes, if you merged and not rebased then squashing is the way to 'remove' merge commit.
I don't do it always though, especially when the feature is large and the merges needed conflict resolution.
Upvotes: 1