1

I have repo with a single branch and numerous commits.

I want to squash all commits into one.

I do:

git rebase --root -i

(see: How to squash all git commits into one?)

after setting all commits to squash (except the first, set to "pick") and exiting the editor, the interactive rebase stops and asks me to solve some conflicts.

I am quite confused about this. I understand conflicts when merging a branch into another. I do not understand it when squashing: should not be the newer commit be automatically considered as the "correct" version of the file ? Also, several files have been modified throughout the commits, how come only a very few of them show conflicts ?

Vince
  • 3,979
  • 10
  • 41
  • 69

1 Answers1

4

As hinted by @mnestorov's comment : you probably have merged branches in your history.


If your intention is to throw away a chunk of history and simply squash commits together, you can do so without using git rebase.

Just run git reset --soft [target commit], followed by git commit or git commit --amend.

The first one will create a new commit on top of [target commit], the second will rewrite [target commit] in place.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • +1. This will also preserve, albeit hidden until gc (I think), branches and references, in case you need to go back before the reset. – mnestorov Mar 24 '21 at 13:57
  • 1
    Yes, and the reflog will keep the reference live and it won't be gc'ed until that drops off. I don't recall the default time it keeps things, but it's like a month or three. – JDługosz Mar 24 '21 at 14:05
  • 2
    just for context : `git rebase` also updates the reflog, so the two options offer the same "you can roll back to what it was" feature. – LeGEC Mar 24 '21 at 14:09