This manual will elaborate on the procedure to uncommit Git’s last commit with examples.
Example: How to Uncommit Git’s Last Commit?
To revert or uncommit Git’s last commit, first, move to the Git directory, then create and update the file. Next, add the file to the Git directory and check the current directory status. After that, commit all changes and view the Git reference log history. Again, make and commit changes in the file and check the status. Lastly, uncommit the last commit and check the repository status.
Now, move toward the implementation of the above-discussed procedure!
Step 1: Move to Directory
Execute the “cd” command to move inside the required Git directory:
Step 2: Create and Update File
Next, create and make changes in the Git repository simultaneously utilizing the below command:
For instance, we have created a file name “file1.txt” and added the required text to it using the “echo” command and the redirect operator “>”:
Step 3: Add File
Now, add the created file into the Git repository by exciting the “git add” command:
Step 4: Check Status
Run the given command to view the repository’s current status:
As you can see, our “file1.txt” is added successfully:
Step 5: Commit Changes
Next, commit all changes into the repository with the help of the below command:
Here, you can also specify a commit message using the “-m” option:
Step 6: View Repository Log Reference History
Then, run the “git log” command with the “–oneline” flag to view the reference log history of repository:
Step 7: Update File
Execute the “echo” command to make changes in the created file:
Step 8: Commit Changes
Again, commit changes to the Git repository using the below-given command:
Step 9: Check Repository Reference Log History
Check the reference log history of the repository through the following command:
Step 10: Uncommit Changes
Finally, execute the “git reset” command with the“–soft HEAD~1” option to revert the recently made changes:
Step 11: Verify Uncommit Operation
Lastly, run the “git log” command to verify the revert or uncommit operation:
As you see, the recently made changes are reverted successfully and HEAD point towards the previous commit reference:
This study led you to uncommit Git most recent commit with an example.
Conclusion
To revert Git’s last commit, first, move to the Git directory, then create and update the required file. Next, add the file to the Git directory and check the current directory status. After that, commit all changes and view the Git reference log history. Again, make and commit changes in the file and check the status. At last, uncommit the last commit by executing the “$ git reset –soft HEAD~1” command. This manual illustrated the method to uncommit Git’s last commit.