Skip to content

Instantly share code, notes, and snippets.

@rcanepa
Last active June 28, 2024 12:39
Show Gist options
  • Save rcanepa/8a334d7c4f46df948c676aab489fe2c2 to your computer and use it in GitHub Desktop.
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)
- 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