Menu

How to delete commits from a branch in Git?

Checkout the branch. e.g we are working here with development branch
$ git checkout development

Go to the commits list and copy the commit id till where you want to remove the commits from branch. then run git reset --hard to delete the all commits above or after that commit id. e.g. commit id is "c9709eb155e18e2eb12e38bf
$ git reset --hard c9709eb155e18e2eb12e38bf

You will got a success message saying "HEAD is now at <commitid> <commit message>". It means your reset is successful.

Now run the git push to push the commit till this commit id to your branch.
$ git push origin development --force


Related Articles:

How to cherry pick in Git 

No comments:

Post a Comment