Keep only last n commits--
git fetch --depth=<n-1> . <branch>
Remove commits older than specified time--
git fetch --shallow-since="<timestamp>" . <branch>
Remove commits reachable from tag, including itself--
git fetch --shallow-exclude=<tag(but not commit hash)> . <branch>
git gc --prune=now # Don't use --prune=now if another process is writing to the repository concurrently
git count-objects -vH