0

I'm doing a rebase and I want to keep always the changes made in the latest commit to avoid having to resolve the conflicts manually.

  • 1
    Do you have multiple commits you are rebasing, and if yes, are you getting conflicts for multiple commits? If still yes, then you can't auto-resolve conflicts on commits before the last one since the changes may not be there yet, until you are rebasing the final commit. – TTT Jan 21 '22 at 20:43
  • The answer is yes and yes, so I guess you could turn the comment into an answer, there is nothing else that can be done. –  Jan 21 '22 at 21:11
  • Use `git rerere` to remember previous resolutions. – chepner Jan 21 '22 at 21:52
  • @chepner I was thinking about `rerere` too, but presumably each time you rebase onto a newer version of the target branch (say `origin/main`) the conflicts would be different. So I don't think that would help here? – TTT Jan 21 '22 at 22:08
  • 1
    Possible; I don't know that I've every successfully *used* `rerere` :) but I feel like there have been times when I had to repeat the same changes multiple times during a rebase. – chepner Jan 21 '22 at 22:13
  • @chepner ah- that's a good point. It might help with multiple conflicts per commit during *this* one-time rebase. I updated the answer to point that out. – TTT Jan 21 '22 at 22:14

1 Answers1

1

Unfortunately, most likely you can't.

When you have multiple commits that are conflicting during a rebase, each commit is replayed one by one. From the point of view of conflicts at each commit, the changes in the last commit don't exist yet, so it wouldn't be possible to automate choosing the final version of that file.

So what can you do? There are some options that might work for you:

  1. If you are willing to squash your commits into a fewer number of commits, you will have less total conflicts to work through.
  2. If you don't wish to squash your commits, and the pain caused by the rebase is greater than the benefit of rebasing in the first place, then you could merge instead, and then you will only have one set of conflicts to deal with.

Also, as chepner mentioned in a comment, you may be able to use rerere to assist with resolving similar conflicts on a per commit basis during your rebase.

TTT
  • 22,611
  • 8
  • 63
  • 69