![]() ![]() If it is just the commit then -soft is the preferred option. It all comes down to what one wants to undo.The Hard option will revert changes in the working directory along with the staging area and the repository. The Mixed option will revert the changes in the staging area. Soft won't affect the working directory or the staging area.These three modes will take us back to a previous commit, but they differ in how they treat changes in the working directory and the staging area. This command works in three modes - Soft, Mixed, and Hard. We can undo a commit by using the Git Reset command. ![]() However, this method cannot be used if we do not want to create a separate branch or the branch with the unwanted commit is the master branch.After doing that we can use the -b flag to create a new branch based on this commit.To undo the last commit we will need the hash of the second last commit. To go back to the previous commit, the Git Checkout command will need its commit hash.The commit point C is no longer a part of the new feature branch. Consider the following example where we created a new branch and added two new commits to it. This newly created branch will no longer have unwanted commits. After going back to a previous commit we can create a new branch based on that commit and start working on that branch.This happens because our HEAD is no longer at the tip of the branch and is pointing directly to a commit. But checking out a previous commit takes our repository in a Detached HEAD state. We can also check out a previous commit using this command. Git Checkout command is used to navigate to different branches and can also be used to create new branches.There are three ways in which we can undo changes in Git but it depends on the situation and how you want to undo the commits. We can always undo the Git Commit and go back to the former state of our repository. But there may be cases where we realize that we no longer need that commit. Commits are used when we want to permanently store a change in our repository. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |