Star

Created With

linkReverting Your Commits

Whoops we made a mistake!

Let's say for example that you committed a file that contains an API key. Or perhaps you committed the wrong files all together

Maybe you forgot to set up your .gitignore and a bunch of cruddy files got committed and pushed and you project is a mess now (looking at you npm) 😆

linkGit has our back. Given the way it saves snapshots. We can easily revert to a previous commit like so

1link$# Reset the local copy to a previous commit

2link$git reset --hard <ID#Of_Commit>

3link$

4link$# Force push the local copy to the remote repository

5link$git push --force

linkWe also have the following options as well..

linkReturn to the last committed state

1link$git checkout -F | git reset --hard (you cannot undo a hard reset)

linkRevert the last commit

1link$git revert HEAD (Creates a new commit)

linkRevert specific commit

1link$git revert $id (Creates a new commit)

linkFix the last commit

1link$git commit -a --amend (after editing the broken files)

linkCheckout the ID version of a file

1link$git checkout <ID><file>

2link$

Reverting Your CommitsGit has our back. Given the way it saves snapshots. We can easily revert to a previous commit like soWe also have the following options as well..Return to the last committed stateRevert the last commitRevert specific commitFix the last commitCheckout the ID version of a file
Content

Home Backstory Why Git? Setting Up GitHub GitHub CLI Your GitHub Profile GitHub Pages Creating A New Repo Cloning A Repository Your First Commit Ignoring Files In Git Stashing Your Changes Branching With Git Merging Git Branches Rebasing Vs Merging Git Workflows Fork And Pull Flow Your First Pull Request Automated Security Alerts Seeing The Differences Removing/Deleting Files Reverting Your Commits Configuring your Git Commit Templates Creating Shortcuts Dotfile Management Sponsoring Open Source Handy Commands Thank You



Developer Student Clubs

logo2.png