![]() Fast forward, I ran a few commands as shown in the graphic below – for synchronizing the remote branch with local, creating a new branch locally and started adding files: The remote repository is created on Github and local on a Window system.īy right clicking on the local system folder, I opened the Git Bash ( as explained in this tutorial). 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. 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. ![]() You have learned two ways to undo the last commit and also when it's best to use one over the other.This command will make the Git move the pointer of HEAD back to the previous commit. Revert instead creates a new commit that undoes the changes, so if the commit to revert has already been pushed to a shared repository, it is best to use revert as it doesn't overwrite commit history. This command changes the commit history and it might overwrite history that remote team members depend on. You should really only use reset if the commit being reset only exists locally. In this image, each circle represents a commit. This will undo the latest commit, but also any uncommitted changes. If you want to reset to the last commit and also remove all unstaged changes, you can use the -hard option: git reset -hard HEAD~1 The -soft option means that you will not lose the uncommitted changes you may have. It will move the HEAD, the working branch, to the indicated commit, and discard anything after: git reset -soft HEAD~1 But be careful – it will change the commit history, so you should use it rarely. You can also use the reset command to undo your last commit. In this image, each circe represents a commit. Then you can copy from there the alphanumerical name and use that in the revert command. The first commit that's described there is the last commit created. You can find the name of the commit you want to revert using git log. You can use it to revert the last commit like this: git revert The revert command will create a commit that reverts the changes of the commit being targeted. We'll look at both of them in this article. There are two possible ways to undo your last commit. So now you need to revert your last commit. Say you're working on your code in Git and something didn't go as planned.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |