Git reset last commit

broken image
broken image

To understand the undo process by using Git restart with –hard and –soft flags, let us start with the basics.įor the demo, I have created a remote and local repository. Still unclear, let us go through adding files in a branch, committing the changes and then doing hard and soft operations for undoing changes in the example below.

broken image

You will see, the changes in the last commit are preserved, however, the HEAD pointer is moved back to the previous position. If you run this command after the above command: For that, you may use the –soft in reset command as used below: So, for example, you do not want to discard changes made: files added, or any other changes. The other two are:īy using the –soft flag, you may keep the changes in the last commit while moving the HEAD pointer back to the last commit. The one is used in the above command i.e. Keeping the changes in previous commit exampleīasically, the reset command has three forms of invocation. So, your last commit is undone and any files added or changes made are removed. This command will make the Git move the pointer of HEAD back to the previous commit.

broken image