0 votes
1 view
in Devops and Agile by (25.5k points)

By mistake, I did git add . and git commit in the develop branch. But luckily, I did not do git push.

So I wanted to revert it back to the original state.

I tried git reset --soft and git reset HEAD --hard but looks like I have messed it up.

How do I fix this? I want to go back to the original state and possibly keep the code changes.

1 Answer

0 votes
by (42.7k points)

From the question, I have assumed that till now you haven’t messed up. So you could use:

git reset HEAD^

This will bring the dir to the state before you've made the commit.

HEAD^ means the parent of the current commit (the one you don't want anymore) while keeping changes from it (unstaged).

Thus, you can undo the last commit in git.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...