Home > Mobile >  Remove file from remote repository. Leaving deleted lines? Azure?
Remove file from remote repository. Leaving deleted lines? Azure?

Time:09-16

I’m trying to delete a file that was accidentally added to the remote repository azure. In my recent commit I used

git rm filename
git commit “deleted file”
git push origin main

This deleted the file, but it’s leaving a trace that it’s been deleted. Which is odd because the original main, has this file, but a different version? Any help?

CodePudding user response:

Deleting the file won't remove it from past commits, and the main branch will keep a reference in its history.

Only the most recent commit will record that file deletion.

A tool like git filter-repo would be able to truly remove the file from the all repository history.

CodePudding user response:

If you delete the file in a commit, there are now (at least) 2 commits for this file. One where it got added, and one where it got deleted. If you want to completely remove the file from git and its history, there are a couple of scenarios. Since you mention the file already being on the remote, removing the commit locally is not an option.

In addition to VonC's answer:

The git filter-repo tool [...] rewrites your repository's history, which changes the SHAs for existing commits that you alter and any dependent commits. Changed commit SHAs may affect open pull requests in your repository. We recommend merging or closing all open pull requests before removing files from your repository.

More information: Removing sensitive data from a repository.

  • Related