I want to squash all the commits till a particular commit-id in a branch.
I tried using the command git reset --soft HEAD~223
The number 223 was generated as follows:
I ran the command git rev-list branch-name
and then found on which line the commit-id from which I am interested in squashing appears.
It was on line 223. So I tried running the command git reset --soft HEAD~223
(While on the current branch)
But I got the following error message:
fatal: ambiguous argument HEAD~223: unknown revision or path not in the working tree
Not sure what could be the reason for this.
Probably the way I have generated the number 223 is wrong.
~223counts only the first-parent commits, but not the commits on the side branches.git rev-listdoes list all commits.git rev-list, why, then, aren't you just using the commit ID instead ofHEAD~223?reset --soft commit-idwill it squash all the commits above it?~works on first parents always and so, if there are merges, they will be counted in the lines that you saw but they would be out of the line that git will follow withHEAD~223. You should try with the commit id so that you do not miss it.git reset --softis not a "squash commits" command. It is more like "please reseat the branch pointer to that commit, but don't change any checked-out files nor what is recorded in the index." The squash happens only when you make a commit with the state that is still in the index at this point. "squash all the commits above it"? If your history is completely linear: yes; if it is branch-and-merge-y, not necessarily.