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.
Say for example, if you are in a local work tree and you have 15 commits and want to squash them, you can perform the following with
--soft. This will set theHEADat the 15th commit and then you can push your changes to your branch as if you were on the first commit, but all the subsequent changes would be included in the commit.OR you can move the
HEADto a particular commit hashOR another option is
rebase. This will rewrite the commit hash.It's highly recommended not to rebase if you push to a remote where others are working on the same branch. if you want to squash PRIOR to pushing to a remote branch, you can do the following:
<number of commits>is the physical number of commits you want to rewrite.-iis interactive mode which allows you to modify the commitsOR
You can also rebase and squash any commits using the first commit hash prior to your work. This says you want to
rebaseON TOP of the last commit before yours. When the editor opens, you need to change the keyword tosquashon all the commits you wish to squash.