Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Git Tutorial 32 – How To Restore Deleted And Committed But Not Pushed File Without GIT Reset?

Posted on 02/19/2025 By admin

As a part of GIT Tutorials End To End, we will learn about retrieving a deleted and committed file in Git without using GIT reset command.

I will expect that you are aware of the basic concepts and commands of GIT. But if you are a beginner in GIT then I strongly recommend you to refer GIT Basic Commands and Concepts section on my blog first.

Previously we learned How To Retrieve Deleted But Not Committed File In Git.

In the previous post, we deleted the file but did not commit it. In this post, the scenario will be a little different. I will delete the file and will commit it as well. Please note that the commit will be local and will not be pushed to the remote repo.

Let’s create a GIT repository and some files with contents.

Add and commit.

Now let’s delete a file and commit the change i.e. deletion.

In the previous post, we recovered the deleted file using the checkout command because the deleted file was not committed. Let’s run the same command again in this scenario.

We will see an error as above. As I have explained in my previous post that deleted file is recovered from the last commit i.e. HEAD. We have deleted the file but the deletion was not committed. So HEAD was still pointing to the commit in which deleted file was present. In this post, we have deleted the file and also committed the changes. Committing the changes will create a new commit id and HEAD will point to that. So when we used the checkout command in this condition, GIT tries to recover the file from the latest commit i.e. HEAD but the latest commit does not have that file because the latest commit actually has changes to delete the file.

So can we try to recover a deleted file from another commit rather than the HEAD? Yes, we can do it.

List out all commits.

We know that commit id 9928269 which is HEAD currently has changes in which we deleted the file. The commit id d240dca is the stage at which my deleted file was present. So we can retrieve the deleted file from stage i.e. commit id d240dca. We just need to use this commit id instead of HEAD.

So we are able to recover the deleted file. You need to commit this change i.e. retrieval.

You can see in the above screenshot that we still have the commit id in which the file was deleted. We have another way of retrieving the deleted file which will omit the commit history as well. We will see that in the next post.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe to my YouTube channel.
#ThanksForReading
#HappyLearning

Uncategorized

Post navigation

Previous Post: TestNG Tutorials 30: Groups Attribute at Class Level In TestNG
Next Post: How To Iterate Map In Java?

Related Posts

November 10, 2018 – Make Selenium Easy Uncategorized
Hierarchy of Selenium Classes and Interfaces – Make Selenium Easy Uncategorized
TestNG Tutorials 48: How to Pass Parameters of Different Datatypes in TestNG | Make Selenium Easy Uncategorized
nodejs Uncategorized
image – Make Selenium Easy Uncategorized
Git Tutorial 2 – What is GIT and Its Advantages? Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark