7

I like the answers from How to squash all git commits into one?.

However, I get merge conflicts if I:

git rebase --root -i

with pick and squash as suggested.

And, I lose my submodules (I have 5), when I

rm -rf .git
git init
git add .

What is the most effective way to squash all history and keep my submodules in their current directories at their current sha.

Community
  • 1
  • 1
J0hnG4lt
  • 4,337
  • 5
  • 24
  • 40

1 Answers1

7

Try git reset --soft SHAOFFIRSTCOMMIT and then git commit --amend

The first command resets the current branch to the first commit, but keeps the current index and the second command commits the current index in the last commit.

MrTux
  • 32,350
  • 30
  • 109
  • 146
  • 1
    No, `git reset --mixed` resets the index. (`--mixed` is the default, by the way.) `--soft` is the option to leave the index as it is. –  May 14 '15 at 12:01
  • but iirc mixed also does the job innthis case, right? – MrTux May 14 '15 at 12:03
  • No, in general, it doesn't. After `git reset --mixed`, you'd have to worry about re-updating your index to the exact state it was in before you executed `git reset`, and that's not necessarily trivial. –  May 14 '15 at 12:04
  • This is brilliant. I guess this would preserve peoples branches too. – J0hnG4lt May 14 '15 at 12:14