Reputation: 137
I am trying to delete some gitlab commits that were made in error.
the answers provided in other threads were
When I attempted to delete the commits, they were not deleted. Instead, two extra merges were created on top. I'm sure this is normal, but I don't understand why it has done that, and more importantly, it hasn't deleted the commits.
How can I delete the commits completely so that the last available commit is the one with the superman logo? thanks
Upvotes: 4
Views: 19259
Reputation: 68810
The non destructive way is simply to do what you've done: revert your commits. Sure there "2 more commits", but your branch is in the same state than before.
The destructive way is to delete commits but this would override your branch history. Because of this you'll need extra rights to rewrite the branch history.
Before to go further, you need to understand that:
- Depending on the repository configuration you may NOT be allowed to do such a thing
- You'll force everybody else working on this repository to force pull the branch, therefore they may loose their work if they're not well understanding the process
- You'll loose EVERY commit after the superman one, even those that would have been created by someone else in the last hours
I highly recommend you to NOT do this.
By code, assuming this is the branch master
:
# Retrieve the latest version
git pull origin master
# Goes back to the superman commit
git reset --hard 329a7a0e
# Force push to rewrite history
# Will be refused if the branch is protected
git push origin master --force
With Gitlab, I think you have no other way than:
329a7a0e
commit, named master-rollback
master
branchmaster
from master-rollback
master-rollback
branchUpvotes: 6