How do you undo the last commit and keep the changes in the working directory?
Posted by CarolTh
Last Updated: July 09, 2024
To undo the last commit while keeping the changes in your working directory, you can use the following Git command:
git reset --soft HEAD~1
Here’s a breakdown of what this command does: - git reset is the command used to move the current branch pointer to a different commit. - --soft means that you want to keep the changes from the last commit in the staging area (the index), so they can be easily recommitted if needed. - HEAD~1 refers to the commit that is one before the current HEAD, effectively pointing to the last commit you want to undo. If you want the changes to be kept in your working directory but not staged, you can use:
git reset HEAD~1
In this case, the changes will be present in your working directory as untracked files and will not be staged for commit. You can then edit them further or commit them as needed.