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?
- stackoverflow.com/search?q=%5Bgit-rebase%5D+first+commitphd– phd2024-07-31 16:56:59 +00:00Commented 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.Patrick Fromberg– Patrick Fromberg2024-08-01 07:18:57 +00:00Commented Aug 1, 2024 at 7:18
- stackoverflow.com/…phd– phd2024-08-01 08:10:48 +00:00Commented 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.Patrick Fromberg– Patrick Fromberg2024-08-01 08:53:27 +00:00Commented Aug 1, 2024 at 8:53
Add a comment |
1 Answer
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.
3 Comments
eftshift0
@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.
Bert F
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.
Bert F
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.