The easiest way to do this is to use the rebase command.
Imagine you have this repository:
$> git log --oneline af28aeb Another test a680317 Try something d93792b Edit both files f23cdbd Second commit add b 6f456bc First commit add a
So you did some test with commits af28aeb Another test and a680317 Try something . We want to deflate them after d93792b Edit both files to clear the repository.
For this, the command will be git rebase -i d93792b
Where -i indicates to enter interactive mode, and d93792b is the commit hash in which we want to use the previous one.
Note: if you want to deflate all your commits as the first, you should use git rebase --root -i
This command will show you that:
pick a680317 Try something pick af28aeb Another test
You must tell the rebase command what you want to do. In this case, I suggest you rewrite the first commit and issue the second character as follows:
reword a680317 Try something squash af28aeb Another test
Then your text editing will be open to set a new commit message.
Fix bug
Now you need git commit --amend and git rebase --continue to complete the process.
And your repository will look like this:
$> git log --oneline 5f98806 Fix bug d93792b Edit both files f23cdbd Second commit add b 6f456bc First commit add a
Enrimr
source share