commit repository file deletion

Deleting Files from a Committed Repository in Git

When programming with Github and Git, there are times when you want to delete files from a git repository. This explains how to delete specific files from git and commit.

Shou Arisaka
1 min read
Oct 8, 2025

When programming with Github and Git, there are times when you want to delete files from a git repository. This explains how to delete specific files from git and commit.

Image

If there are extra files like tmp files or log files in the git repository directory, unless they’re excluded in global gitignore or local gitignore, they’ll be included in the repository when committed. I often monitor file changes with git log, but if temporary files that change frequently are included in the repository, statistics like insertions and deletions get messed up. This is very undesirable.

While this wouldn’t happen in the first place if you had set up gitignore beforehand, accidents do occasionally happen. In such cases, you can delete the file from the repository with the following command, and it won’t be counted in git log anymore.

git rm --cached git_log_d_on_output\*.txt

And what you must not forget after executing the above command is adding it to gitignore.

git_log_d_on_output*.txt

Share this article

Shou Arisaka Oct 8, 2025

🔗 Copy Links