In this series of Git blogs, I will discuss essential Git commands crucial for developers, especially those addressing challenges in collaborative work.

During numerous interviews, Git often emerges as a favoured topic for interviewers, with a penchant for posing questions related to it.

In many interviews, Git frequently stands out as a preferred subject for interviewers who are inclined to ask questions on this topic.

The git stash and git reset is one of the favourite topic of the interview and in this blog I'm going to explain you this.

So, coming straight to the topic.

Stash

In one line we can say that,

It's the technique to store data temporarily in Git, without committing the code to the repository.

It takes the incomplete state of our code and saves it temporarily for future use.

So you were thinking, where git stash storing the data, obviously it stores the data locally in the present repoitory's object database, just like regular commits and other Git objects.

When you run git stash, Git creates a new stash entry and stores it as a special type of commit object in the repository. These stash entries are typically stored under the refs/stash namespace in your Git repository.

Remember that while stashes are handy for temporarily saving changes, they are not a substitute for proper branching and committing when working on features or bug fixes for your Git repository. Stashes are best used for quick context switching or when you need to save changes temporarily without committing them.

Revert

We all can make mistakes anywhere, including when writing code. And in this git, our very good friend helps us. As we know git is the version control tool, so we can go to the previous version of code by git.

There's various method to revert and change the code, in this blog I'm going to explain by the following git command.

git log --oneline

After applying the command we get the git commit messages and there commitId.

To quit the commit messages use the q command to quit from there.

And we can choose which commit we want to go. Then apply the following command and use the commitId of that commit.

git reset commitId

You reach to that commit, apply the changes and use the following command afterwards.

git add .
git commit -m "msg"
git push

Yay! You successfully reverted your code.

Chill!! no need to worry about the mistakes, there's always a way.

Thanks for reading this blog.

If you have a suggestion, please drop it in the comment box.

Check out my Portfolio website Click me.

Please give likes to this blog.

Did you find this article valuable?

Support Anurag's blog by becoming a sponsor. Any amount is appreciated!