I don't know about you, but this happens to me all the time; I accidentally pull in the wrong branch, curse a bit, call myself some names 🤬, and then apply this fix, which is effortless if you understand the concept well enough.
If you made `git reset --hard` by mistake, possibilities are you can still get your commit back, as git holds a log of everything for a few days.
Despite all the fixes you try, faulty commits occasionally make it into the central repository. Still, this is no reason to despair, since git offers an easy way to revert single or multiple commits.
There are several situations when you have to remove some part of your code from git history. Doing so is very easy if you know these commands.
You have to remove some part of your code from git history in several situations. Doing so is very easy if you know these commands.
Everybody has their own way of writing code, and there are times when you try out a few ways of creating a functionality or fixing that nasty bug, which is not such a good way of doing it. If you want to discard your current changes, you can do it easily by checking out the modified files.
To remove your staged changes or to undo your last `git add` command, you can use `git reset`. Running the below command will remove all files from your staging area
Initially, when I started working on git, I was terrified of squashing commits, I always feared that I would do it wrong and will lose some code, but it's very simple once you understand the underlying logic.
Moving between different branches is tricky if you don't remember all the steps, but you can always bookmark this page.
The simplest way of revering commits is to reset your head to the last commit you want and just discard the changes, here is how you can do it.