I have a "long lived feature" branch that i have been working for last 2 months. It has 211 commits that i want to squash into single commit before this "long lived feature branch" can be merged with "origin master". When i run "git rebase -i HEAD~210" it kicks off a conflict resolution process of more than 500 conflicts.
What's the best way to squash commits and complete rebase ?
When i do:
git rerere
git rebase -i HEAD~210
# change all "pick" with "squash" and save and exit followed by single
# commit message
It will then present me with 500 or so conflicts to be resolved which is my problem. i.e. is there any way i can get away with it?
There are only 4 files that keep repeating and git rerere hasnt been of much help.
My other confusion is why i get more than 500 conflicts to be resolved when the commits are 211?
I have been reading on merge vs rebase and the difference seems to be only retaining history or not but in effect processes are quite different. merge works fine but rebase creates a lot of trouble. I have been thinking of creating another feature branch and run git merge --squash to get rid of commits but my colleagues have already committed on a PR based on my "long lived feature branch" and i would prefer a way to sort out this issue without creating another branch
Here is a recipe to create a branch which groups all the changes brought by your feature branch squashed in one single commit:
You now have
my-squashed-branch, which introduces the exact same changes as your initial branch, with only one commit. That commit is based on the last point inmasterwhere you syncedmasterwith your branch.You may open a pull request directly from that squashed branch, or run
git fetch; git rebase origin/masterto rebase it on the latest version ofmasterbefore opening that pull request.Should there be conflicts in that last rebase, at least they will be contained to one single commit.
note: if the branch modifies 500 files, and that out of bad luck these same 500 files have also been modified on master, you may have 500 conflicts even though there is one single commit.
The number of conflicts is bound by the number of individual file changes (if you have 200 commits, you would have to sum the number of file changes in each commit), not by the number of commits alone.