Skip to main content

BIG NOTE

if you have already pushed changes to a repository others are using

be VERY careful with changing history and then pushing again

i don't even know what ive been doing

git log

i cant read that

too much information?

git log --oneline

bad commit message?

git commit --amend -m <new-message>

forgot to add a file?

add files to the latest commit

git add <file-name>

git commit --amend --no-edit

started work on the wrong branch?

you started work on the wrong branch and want to move to a new branch

git stash

git checkout -b my-new-branch

git stash pop

undo all the things

you hate everything you've done since the last commit

commit sudoku and undo it all

git reset --hard

if you've already committed then this won't help, your shame is eternal.

your only hope is to remove the commit

remove the last commit

git reset --soft HEAD~1

revert a file to an earlier commit

find the commit hash

git log

restore the file to the previous state

git checkout <commit-hash> -- <file-name>

fubar? got a remote?

nuke the repo

cd ..

rm -rf <repo_dir>

git clone <remote_repo_url>

in all seriousness, this shouldn't be necessary

you can undo most things with git

not an exhaustive list

there are many ways to do things with git

there are many ways to undo things with git

i'm not an expert

these are just some commands i use

if you know a better way, please let me know