git undo all uncommitted or unsaved changes

This will unstage all files you might have staged with git add:git reset This will revert all local uncommitted changes (should be executed in repo root):git checkout . You can also revert uncommitted changes only to particular file or directory:git checkout [some_dir|file.txt] Yet another way to revert all uncommitted changes (longer to type, but works from … Read more

Move existing, uncommitted work to a new branch in Git

Update 2020 / Git 2.23 Git 2.23 adds the new switch subcommand in an attempt to clear some of the confusion that comes from the overloaded usage of checkout (switching branches, restoring files, detaching HEAD, etc.) Starting with this version of Git, replace the checkout command with: The behavior is identical and remains unchanged. Before Update 2020 / Git … Read more

Can I delete a git commit but keep the changes?

It’s as simple as this: Note: some shells treat ^ as a special character (for example some Windows shells or ZSH with globbing enabled), so you may have to quote “HEAD^” or use HEAD~1 in those cases. git reset without a –hard or –soft moves your HEAD to point to the specified commit, without changing any files. HEAD^ refers to the (first) parent commit of your current commit, which in your … Read more

Why are there two ways to unstage a file in Git?

git rm –cached <filePath> does not unstage a file, it actually stages the removal of the file(s) from the repo (assuming it was already committed before) but leaves the file in your working tree (leaving you with an untracked file). git reset — <filePath> will unstage any staged changes for the given file(s). That said, … Read more