Last active
June 28, 2024 12:39
-
-
Save rcanepa/8a334d7c4f46df948c676aab489fe2c2 to your computer and use it in GitHub Desktop.
Undo committed files (move them back to the staging area without cancelling changes)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Reset current branch to the parent of HEAD | |
git reset --soft HEAD~ | |
- Reset the unwanted files in order to leave them out from the commit: | |
git reset HEAD path/to/unwanted_file | |
- Commit again using the same commit message: | |
git commit -c ORIG_HEAD | |
(*) git reset --soft HEAD~ | |
The last commit will be undone and the files touched will be back on the stage again. Also, | |
index and staging remains untouched. | |
(*) git reset HEAD -- file | |
Moves file from stage to the working directory (unstage a file). | |
(*) git reset --hard | |
Unstage files AND undo any changes in the working directory since last commit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment