I would like to modify the current git commit and remove its previous form. In other words the "old" current commit has to disapper and it is replaced by the "new" one with the same commit message.
At the moment I am doing:
git add .
git commit --amend --no-edit
git push --force
From the web interface (gitlab) or using git log, I can see only the "new" current commit; but if I search for the "old" current commit hash (web interface or in .git) I am still able to see the "old" commit content.
Is there a way to completely remove the old "current" commit?
Thanks
Update
Following some advice I have tried:
git add .
git commit --amend --no-edit
git stash clear
git fsck --unreachable --no-reflogs
git reflog expire --expire-unreachable=now --all
git gc --prune=now
git repack
git push --force
while locally I can see that the commits are not present anymore (git branch -a --contains <commit_id>), the size of the repository on gitlab continue to increase, even if I triggered housekeeping.
Not really. A commit to which no name (e.g. branch or tag) points, and is not reachable from any commit to which a name points, will eventually be cleaned up; and you can force that to happen prematurely on your machine. But on GitLab it would require human intervention by the owners of the site to make that happen ahead of schedule. (Though you might be able to make it happen through housekeeping; see How can I force GitLab to carry out a garbage collection (and permanently remove a file))
So at this moment the original ("old" current commit) is slated for destruction, but it has not yet been destroyed. That's not a bug, it's a feature.