@filiberto
To undo the last Git commit, you can use the git revert
or git reset
command depending on the desired outcome. Here's how to do it:
- Using git revert:
- Open your Git command prompt or terminal.
- Run the command git revert HEAD to create a new commit that undoes the changes made in the previous commit. This will open a text editor to add a commit message, so you can enter a suitable message and save the changes to complete the revert.
- Using git reset:
- Open your Git command prompt or terminal.
- Run the command git reset HEAD~ to remove the last commit from the current branch and move the branch pointer to the previous commit. This will keep the changes made in the last commit as uncommitted changes in your working directory.
- If you want to completely discard the changes from the last commit, you can add the --hard flag to the command, like git reset --hard HEAD~. This will remove the last commit and any changes made in it.
Remember that when using git reset
, it's important to note that any commits you remove will be lost unless you have previously pushed them to a remote repository.