![]() ![]() Apart from git reset hard there are other commands also which can be used to backtrack your changes such as git checkout. Therefore it should be used with certain caution. Git reset hard is a command which should be used carefully as to can delete your entire code commit history and what you have done till a particular commit. Like in above example we did not want to remove the changes in File 1 but it got removed Conclusion This is the main disadvantage of git reset -hard that all the changes are removed upto a certain point even though you did not want to remove them. If you check the repository now you will observe that the File2 has been removed.Īs you can observe the File2 has been removed and along with it all the changes which we have made to File 1 have also been removed.Īnd our commits have been reset to the point 00efc21 commit id as shown in the image above. The command which I will use now is git reset -hard 00efc The commit at which I have added File2 is with id 7bb59.So I will go to a commit before it. Now for example consider I have made and pushed File2 but because of this my code has stopped working so in order to remove File2 I will first have to check the commit at which I have added the File2 and use git reset hard command along with the commit id. Observe we have added the text to the file and now lets check out git log.We have a new git commit with id bc5a. The commit corresponds to the addition of the file. What you will observe is the commit in which we have added the content to the file has been removed and we only have one commit. You will observe that the file is empty and it has reached to its original state in which we have added. The / defaults to HEAD in all forms. In the last form, set the current branch head ( HEAD) to , optionally modifying index and working tree to match. Now go back to your original file and check its content. DESCRIPTION In the first three forms, copy entries from to the index. To hard reset files to HEAD on Git, use the git reset command with the hard option and specify the HEAD.You should get a message that the HEAD is at the specific commit which is 20c9. You only need to write the first 4 letters of the commit id. ![]() So we will specify the particular commit id after writing git reset -hard. Letâs run git log to check number of commit which are present in the repository right now.Īs you can see there are 2 commits and we want to move our HEAD to the first commit when we added the file. So in order to do this use our normal commands.Īfter pushing those changes we will now run the git reset -hard command and as per the command all the changes which we have made to our prehistory should be removed.Ä«ut first in order to do so we have to specify the point to which we want the changes to be effective. Our next text will be to add the changes and commit them to our repository. This is the text we have entered in the text file and saved it. As you can see we have a file called githardexample. Now we will look at the content of the file.Īs you can see the file is empty and we have no content in it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |