Developers create multiple files while dealing with a large complex project in Git. Sometimes, they delete unusable files manually from their project folder but forget to delete them from the Git project. As a consequence, when they check the status of their repository, it shows the manually deleted files. So, in order to clear the Git status, it is required to commit the manually deleted files on Git.
This article will illustrate the procedure to commit a manually deleted file on Git.
How to Commit a Manually Deleted File on Git?
To commit a manually deleted file on Git, first, navigate to the Git local repository. Then, check the current status to view the deleted files. Next, run the “git commit -a” command to commit the deleted file. Lastly, verify changes by checking the Git status and commit history.
Step 1: Switch to Local Repository
First, type out the following command and redirect to a particular local directory:
Step 2: View List of Files
Next, view the list of available files in the repository using the “ls” command:
Step 3: Check Git Status
Then, check the current status of the working repository:
The below output indicates that the repository contains an “F2.txt” file that has been deleted manually:
Step 4: Commit Deleted File
Now, execute the below-provided command to commit the manually deleted file:
After executing the above-stated command, the default text editor will open up. Type your desired commit message, press the “Ctrl + S” keys to save changes, and then close the editor:
Step 5: Verify Changes
Next, check the repository’s status again to verify if it still contains the deleted file:
According to the below-provided output, the Git status is clear now:
Step 6: Check Git Log
Finally, view the deleted file commit by checking the Git log:
The below image displays the commit of deleted file:
That was all about committing a manually deleted file on Git.
Conclusion
To commit a manually deleted file on Git, first switch to the particular local repository and check its status. Then, execute the “git commit -a” command to commit the deleted file. Lastly, check the Git status and Git log to verify changes. This article illustrated the method to commit a manually deleted file on Git.