Skip to content

Instantly share code, notes, and snippets.

@psenger
Created February 17, 2025 19:59
Show Gist options
  • Save psenger/7129542b351428a8d11bed794cfc37c8 to your computer and use it in GitHub Desktop.
Save psenger/7129542b351428a8d11bed794cfc37c8 to your computer and use it in GitHub Desktop.
[Git Reset / Undo Changes] #git

Git Reset / Undo Changes

Reverting changes in Git traditionally required using git checkout to restore files or git reset to adjust the branch HEAD. However, both commands carried risks if misused: git reset could shift the branch HEAD, while git checkout could either switch branches or load a different commit, potentially disrupting the current branch state.

Discard working directory changes

git restore main.js

Unstage changes from the index

git restore --staged main.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment