Git¶
Undoing¶
Undo a git rm for a single file¶
- terminal:
--is often used- any future dashes are considered strings and not flags
- useful when the file path or branch name has dashes
git reset -- my-file.txtgit reset my-file.txt- will think
-fis a flag
- will think
(can't do a git alias because it's multiple lines)
Undo all changes to a single file in a PR¶
Move a file from the 'staged' state to 'unstaged' state¶
git reset HEAD <file>
git-stash¶
| Create a stash | git stash |
|---|---|
| Pop the first stash | git stash pop |
| View stashes | git stash list |
| Create a named stash | git stash -m "stash name" |
| Save a stash with specific files | git stash push -m stash_name -- file1 file2 file2 |
git revert "hash"¶
- git revert undoes only that provided hash's changes
- it will still keep all the other commits' changes
- set the HEAD as a previous commit:
git revert --no-commit 0766c053..HEAD--no-commitlets you revert every commit without creating a new commit for each- safe, no history change
- git shows
(cherry-or-revert), usegit revert --quit
git reset vs --hard¶
- staged -> unstaged:
git reset -- file
--hard¶
- move tip of branch (HEAD) to a different commit
- A -> B -> C = HEAD
git reset --hard A- B and C will be lost
- git reflog to recover the commits!
- (quickly! otherwise git might garbage collect)

reset vs checkout on files¶
- reset: staged snapshot matches the given commit
- checkout: working file matches the given commit
git diff¶
- Just get files that changed
git diff --name-status <commit/branch1> <commit/branch2>
Last update:
2023-04-24