Skip to content

Latest commit

 

History

History
31 lines (20 loc) · 1.06 KB

delete-the-last-commit.md

File metadata and controls

31 lines (20 loc) · 1.06 KB

Delete The Last Commit

Category: Git

In some situations you might need to delete the last commit from a repository changelog. For example, where you accidentally commit information that contains sensitive data or commit a large binary file.

Before running this command, ensure you have backed up any changes in your working directory that you wish to keep.

Preserve changed files and delete the last commit

If you want to delete the last commit on the current branch and retain changed files, you can use the --soft flag:

git reset --soft HEAD~1

Abandon changed files and delete the last commit

If you want to delete the last commit on the current branch and lose changed files, you can use the --hard flag:

git reset --hard HEAD~1

Push changes to remote branch

After performing a git reset, force push to the remote branch:

git push --force

Note: Git reset is a solution that should only be used as a last resort. Be careful performing a reset as it could affect other users working on the same repository.