Git

How to Commit a Manually Deleted File on Git?

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:

$ cd "C:\Git\ReposB"

 
Step 2: View List of Files

Next, view the list of available files in the repository using the “ls” command:

$ ls

 

Step 3: Check Git Status

Then, check the current status of the working repository:

$ git status

 
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:

$ git commit -a

 
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:

$ git status

 
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:

$ 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.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.