Reputation: 1680
Suppose I've been working on a branch called my-branch
, occasionally merging commits from master
to stay up-to-date. On some merges I had to resolve conflicts, which was time consuming.
Now I'm done with my-branch
and I want to rebase it to one commit on top of master
. During the rebase I'll have to resolve the same conflicts which is going to be tedious.
But I already have the exact state I need the files to be in, I just want to clean up the history. So the fastest way to rebase would be to:
my-branch
, but discarding the commit history. At this point I'd have a lot of uncommited changes.Is that possible?
EDIT: SO is telling me to explain why my question isn't a duplicate of this one. While the most upvoted answer there would solve my problem, the question there is "how to squash commits?" and mine is "I know how to squash commits, how to do it without dealing with conflicts?". So the answer is the same, but I didn't find it when looking for the solution before posting here. Perhaps if someone else also knows about rebase but doesn't know about soft resets, they'll find the solution here.
Upvotes: 3
Views: 1458
Reputation: 30156
Sure.... it's fairly simple using git reset --soft
.
git checkout my-branch
git merge master -m "Merging last changes from master"
# we start the magic here
git reset --soft master # set the branch pointer on master
git commit -m "Here's the work for X feature in a single shot"
Upvotes: 7