@5minslearn shared a post, 1ย month ago

Git Checkout / Reset / Revert. When to use what?

We often come across some weird scenarios (especially my team) while committing our code changes. Some of them are,

How can I bring the file to working area, which I have added to the staging area by mistake?

OMG! I made a commit with production keys in the code but did not push the code yet. Is it possible to delete that commit? (Meanwhile, my tech lead be like ๐Ÿ˜ก)

Can anyone say how to remove the changes which Iโ€™ve pushed already?

I logged onto Production machine and made a change to a file and fixed the production issue immediately ๐Ÿ‘ (Can also be debugging on production ๐Ÿ˜œ). Now, I want to remove that change using git cli for the CI/CD to pass. Any Git commands available for this purpose?

Head to the bottom of this page, if you need blind answers for these scenarios. For those who need to understand more, continue from here.

Letโ€™s find answers to all of your such queries with just 3 commands.

1. Checkout

2. Reset

3. Revert