Skip to content

Instantly share code, notes, and snippets.

@saurabhj
Last active December 4, 2019 11:22
Show Gist options
  • Save saurabhj/5f61ec198ec104f3f86f195c2ca993d0 to your computer and use it in GitHub Desktop.
Save saurabhj/5f61ec198ec104f3f86f195c2ca993d0 to your computer and use it in GitHub Desktop.
Git Undo Stuff

Get your local branch to match the online repository i.e. online repo -> local

git fetch origin
git reset --hard origin/master

https://stackoverflow.com/a/36177806/7082 (Undo stuff that has been already pushed) I have a project in a remote repository, synchronized with a local repository (development) and the server one (prod). I've been making some commited changes already pushed to remote and pulled from the server. Now, I want to undo those changes. So I could just git checkout to the commit before the changes and commit the new changes, but I'm guessing that there will be problems to push them again to remote. Any suggestion on how should I proceed?

In the server, move the cursor back to the last known good commit:

git push -f origin <last_known_good_commit>:<branch_name>

Locally, do the same:

git reset --hard <last_known_good_commit>
#         ^^^^^^
#         optional

I have just made a commit (not pushed online) - but I want to uncommit it - because either I need to add more files or I committed it to the wrong branch.

git reset --soft HEAD^

More info: https://stackoverflow.com/questions/2845731/how-to-uncommit-my-last-commit-in-git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment