Reputation: 4840
Someone pushed 3 commits which I want to delete, but I mean that I don't want to see them in commit history on Github, because their have wrong name. How to achieve that ?
Upvotes: 0
Views: 5765
Reputation: 293
That depends on what's the current status of your repository.
If those are the last three commits and you really "don't want to see them", you could reset to the commit that is located just before those three:
git reset --hard HEAD~3
And then push using --force.
In general, if you want to revert a commit, you should use git revert. For example:
git revert HEAD~<2>..HEAD
That would create a commit that removes the changes from the last three commits.
Upvotes: 1
Reputation: 513
You can the rebase
command to delete or change commits messages.
Type git rebase -i HEAD~4
. The -i
option does an interactive rebasing.
Your text editor will open with the last 4 commits listed. Each commit will have the word pick
before it.
Delete the lines for the commits you want to delete. That will tell rebase
that you don't want to keep those commits in history.
Save the file and close it.
Now git should do a "rebase" of your history according to the options you chose in the file that opened, that is delete the commits you didn't want.
If you want to change the commits messages, change the pick
to reword
before each commit you want to edit and save the file.
Upvotes: 0
Reputation: 58
Assuming the three commits are the three most recent commits, the first thing that will be helpful is the sum of the parent commit that you want to revert to. For example: 6b1d1ca
. You can find this on the right column of your commit history in GitHub.
Next, you want to reset your git tree to that commit using
git reset --hard 6b1d1ca
Since you are removing commits from your history, you will need to force the push to GitHub, which can be done by appending the option --force
.
git push --force
Be careful using the --force
option, if you have pushed commits since as they will certainly be overwritten.
Upvotes: 3