Skip to content

Instantly share code, notes, and snippets.

@mccabe615
Last active January 10, 2024 20:59
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mccabe615/4dfe729ddd89e8ca2dd18ccb1754808e to your computer and use it in GitHub Desktop.
Save mccabe615/4dfe729ddd89e8ca2dd18ccb1754808e to your computer and use it in GitHub Desktop.
Oh Shit Git

Oh shit, I committed and immediately realized I need to make one small change!

make your change

git add .
git commit --amend

follow prompts to change or keep the commit message

now your last commit contains that change!

Oh shit, I need to change the message on my last commit!

git commit --amend

follow prompts to change the commit message

Oh shit, I accidentally committed something to master that should have been on a brand new branch!

create a new branch from the current state of master

git checkout -b some-new-branch-name

remove the commit from the master branch

git checkout master
git reset HEAD~ --hard
git checkout some-new-branch-name

your commit lives in this branch now :)

Oh shit, I accidentally committed to the wrong branch!

undo the last commit, but leave the changes available

git reset HEAD~ --soft
git add .
git stash

move to the correct branch

git checkout name-of-the-correct-branch
git stash pop
git add .
git commit -m "your message here"

now your changes are on the correct branch

Oh shit, I tried to run a diff but nothing happened?!

1git diff --staged1

Fuck this noise, I give up.

cd ..
sudo rm -r fucking-git-repo-dir
git clone https://some.github.url/fucking-git-repo-dir.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment