-2

I have five revisions in total and the first commit hash is 123. I want to squash all commits into one. If I do git rebase -i 123 I will end with a minimum of two commits. Any way to specify a virtual revision -1?

4
  • stackoverflow.com/search?q=%5Bgit-rebase%5D+first+commit Commented Jul 31, 2024 at 16:56
  • "How do I git rebase the first commit" is not a title I understand. Is this correct git language? However, the responses under that title do indeed answer my question. Commented Aug 1, 2024 at 7:18
  • stackoverflow.com/… Commented Aug 1, 2024 at 8:10
  • @phd, I do understand "first commit" perfectly. It's the title I dont get and I am surprised "that people understand" it. But maybe it's just me. Commented Aug 1, 2024 at 8:53

1 Answer 1

2

You could try with git rebase -i --root but if you mean to squash everything into the first commit, you could do this instead to avoid the rebase hassle:

git reset --soft 123
git commit --amend -m "Putting everything into a single commit"

As another way to do it, you could pull it off creating an orphan branch.

Sign up to request clarification or add additional context in comments.

3 Comments

@BertF there is no need to do any previous steps.... Just the reset soft is enough.... It can be done when you have 5, 2 or 50 commits, it doesn't matter.
My mistake on the edit @eftshift0 - I got paranoid they were going to lose some edits because I confused --hard and --soft and didn't think it through completely. I should have just left a comment about my concern.
I'll add for the OP - after you do this (or any other method for collapsing the commits into 1 commit) and before you force push, you can do a git diff between your new 1-commit local branch and the multi-commit remote tracking branch to convince yourself that the end result is identical.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.