![]() ![]() We will simply open this file again with the nano editor and you will notice from the following image that the modification that we did earlier to this file has been reverted.īy going through the detailed scenario presented to you in this article, you will hopefully be able to use the “git revert” command in Ubuntu 20.04 in a very effective manner. you will try to nullify the effect of the revert operation you have just performed, then you will be able to see these two files again.įinally, we can also check our file abc.txt once again to see if it is back with its original content or not. However, if you will perform the revert operation once again on this revert transaction i.e. That is why, as a result of reverting this commit, these files will not exist anymore. A point to be noted over here is that the files Stash1.txt and Stash2.txt have been deleted by our revert operation solely because before committing the transaction having the transaction ID of 220ac, there was no existence of these two files. Therefore, there will be no more new files to be committed as shown in the following image:Īlso, we can try to list down the contents of our Git project repository to confirm the deletion of the files Stash1.txt and Stash2.txt as shown in the image below. Stash1 and Stash2 have already been deleted by the revert operation. ![]() Here, we will be able to see that there will be no more files to be committed as the ones that were there previously i.e. However, we can still ensure it by checking the Git status. Step # 10: Verify if the “git revert” Command has worked successfully or not:Īlthough, we have already seen that our project Head is currently pointing to the revert transaction which is enough to indicate that the “git revert” command has functioned properly. If the revert operation has been performed successfully, then the Head of our project will be pointing to this revert transaction as highlighted in the image shown below: Now we will check our Git commit history once again to see the current situation. Step # 9: Check the Git Commit History once Again: Moreover, the files Stash1.txt and Stash2.txt will have been deleted. it will represent its original content without modification. It also means that now our file abc.txt will be back in the previous state i.e. the modification of abc.txt and the addition of Stash1.txt and Stash2.txt have been reverted. This status will tell us that the changes made earlier i.e. You need to press Ctrl+ X after seeing this message so that you can see the exact status on your terminal as shown in the following image. When this command will execute, it will display a message within nano editor that your transaction with the transaction ID 220ac will be reverted as shown in the image below: To further elaborate on this scenario, we would like to walk you through the following steps: Step # 1: Switch to your Git Project Directory:įirst, we will go to the directory where our Git project repository resides in the manner shown below: a state in which neither the files Stash1.txt and Stash2.txt existed nor the file abc.txt was modified. Then we will try to revert to a previous state i.e. ![]() So, we will be committing all of these changes at once. Also, we have two other files in our test project repository named Stash1.txt and Stash2.txt that we had not committed previously. In this scenario, we will first modify an already existing file named abc.txt. Method of Reverting to a Previous Commit in Git in Ubuntu 20.04:įor explaining to you the method of reverting to a previous commit in Git in Ubuntu 20.04, we have designed an example scenario. Therefore, this article is intended to teach you the method of reverting to a previous commit in Git in Ubuntu 20.04. It means that you can easily nullify or cancel the effect of any previous commit without actually removing it from your Git history. The “git revert” command exactly allows you to do so. At times, you wish to undo the changes that you have once committed without actually removing those changes from the “git log” so that you can always redo them in the future whenever you want. The “git revert” command performs an amazingly useful operation within the Git environment. ![]()
0 Comments
Leave a Reply. |