Karthik
Karthik

Reputation: 377

Remove a commit and its history to avoid hook configured in git

I have typed a wrong message in the commit and pushed to my remote branch when hook configured is turned off. But however I need to change the commit message and push to the remote branch. When I amend and push the code to the branch it sit's on top of the wrong message commit. I need to remove that commit from the history and replace the latest commit with correct message in remote.

Correct commit message: ticket #123 my commit Wrong commit message: my wrong commit

Upvotes: 0

Views: 33

Answers (2)

Marina Liu
Marina Liu

Reputation: 38106

If you just need to correct the commit message you can use git commit --amend -m 'the new message' and git push -f. It will replace the last commit message and not on top of the wrong message.

If you don’t want the whole last commit, you can switch to the branch and use git reset --hard HEAD~ and git push -f.

Upvotes: 1

nPcomp
nPcomp

Reputation: 9843

First

Hard Reset your local branch and do

git push --force origin yourbranchname

That will rewrite the history.

Upvotes: 1

Related Questions