How to Roll back from a git commit ?

To roll back from a Git commit, you have a few options depending on your desired outcome. Here are three common scenarios and the corresponding commands:


1. Undo the last commit and keep the changes as unstaged:

```

git reset HEAD^

```

This command will remove the last commit but keep the changes in your working directory. The changes will be marked as unstaged, allowing you to modify them further before committing again.


2. Undo the last commit and discard the changes:

```

git reset --hard HEAD^

```

This command will remove the last commit and discard all the changes associated with it. Be cautious when using this command because it will permanently delete the changes.


3. Undo a specific commit (not the latest) and keep the changes as unstaged:

```

git revert <commit-hash>

```

Replace `<commit-hash>` with the actual commit hash of the commit you want to roll back to. This command will create a new commit that undoes the changes introduced by the specified commit. The changes will be marked as unstaged, allowing you to modify them further if needed.


Remember, when you make changes to your Git repository, it's always a good practice to create a backup or make sure you understand the consequences of rolling back commits.