This study will describe the process of unstage deleted files in Git.
How to Untrack a Deleted File in Git?
Suppose the user created files in their repository. But later they realized these files are unused and want to delete them from the repository. Additionally, they don’t want to update the Git repository with these changes and are required to unstage the deleted files. For this purpose, the “git rm <file-name>” command can be used.
Let’s move forward and implement the previously discussed scenario!
Step 1: Go to Git Repository
To redirect to the Git repository, the “cd” command:
Step 2: Create and Modify File
Now, make a new file and update it immediately by running the “echo” command:
Step 3: Stage Modifications
Next, add changes to the staging index through the “git add .” command:
Step 4: Update Local Repository
Then, push the staged changes to the Git repository by utilizing the “git commit” command with the “-m” option:
Step 5: Make and Update File
Similarly, run the “echo” command to create a new file and add some text to it simultaneously:
Step 6: Stage changes
To add the working area changes to the repository, use the following command:
Step 7: Commit Added Changes
Now, commit the changes to the Git repository with the help of the following command:
Step 8: Remove Particular File
Next, execute the “git rm” command to remove the particular file:
Here, the provided file is deleted successfully:
Step 9: View Git Repository Status
After that, check the status of the current working directory through the following command:
According to the below-given output, the file is deleted:
Step 10: Unstage Deleted File
Finally, to unstage the removed file, use the “git reset” command along with the file name:
It can be observed that the specified file is unstaged:
Step 11: Check Repository Status
Lastly, to ensure whether the deleted file is staged successfully or not, use the below-given command:
As you can see, the “file1.txt” deleted file is unstaged successfully:
That’s it! We have compiled the method of unstage deleted files in Git.
Conclusion
To unstage deleted files in Git, first, we will create files and then provide the process of unstage deleted files. To do so, move to the desired repository and generate a new file. Then, track it and push it to the Git repository. Similarly, generate and track another file. Next, update the repository by committing. After that, run the “git rm” command with the particular “<file-name>”. To unstage the deleted files, run the “git reset — <file-name>” command. This study illustrated the process of unstage deleted files in Git.