This content originally appeared on DEV Community and was authored by CodeWithCaen
To undo changes in Git, you can use the following commands, depending on what you want to undo:
Method 1: Undo uncommitted changes in the working directory:
git checkout -- <file>
Method 2: Unstage a staged file:
git reset <file>
Method 3: Undo the last commit but keep changes:
git reset --soft HEAD~1
Method 4: Undo the last commit and discard changes:
git reset --hard HEAD~1
Choose the command based on your requirement. Always be cautious with --hard
as it irreversibly deletes changes.
This content originally appeared on DEV Community and was authored by CodeWithCaen

CodeWithCaen | Sciencx (2024-10-17T19:38:49+00:00) Quick Tip: Git Undo Commands. Retrieved from https://www.scien.cx/2024/10/17/quick-tip-git-undo-commands/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.