Taladan
Taladan

Reputation: 479

AzureDevOps Git- Remove File/Changes from file

I am currently using an AzureDevOps project based on Git. I don't know much about git and find the system anything but easy to understand. Unfortunately, I accidentally uploaded a file that contains sensitive information. I would now like to delete the file. Unfortunately, there doesn't seem to be a consistent and clearly understandable set of instructions. I have already tried a few things, but so far without success. In the meantime, I already have two commits that contain the file. The second is a patch, whatever that does. Currently, the file is only included in a feature branch, but in several commits there. I work on a windows computer, if it relevant.

I have found this command several times, but I get the following message

git reset --soft HEAD^1
fatal: ambiguous argument 'HEAD^1': unknown revision or path not in the working tree.

Upvotes: 0

Views: 2529

Answers (1)

Chrizzo
Chrizzo

Reputation: 229

yes, it is possible. For example you can use BFG-Repo Cleaner, which can be found here: https://rtyley.github.io/bfg-repo-cleaner/ (to get the tool please follow the instructions from official page)

This tool can help you with a lot of "Git-Problems" for example to delete files and other sensitive data.

To delete sensitive data and leave latest commit untouched:

$ bfg --delete-files YOUR-FILE-WITH-SENSITIVE-DATA

Also you could replace text here for example out from mysensitivedata.txt - be careful, because this will remove all text.

$ bfg --replace-text mysensitivedata.txt

Important: After you removed the sensitive data, you need to do a force push to your git-repo.

But be a bit careful with force push, because it could also overwrite changes which other people did.

Upvotes: 1

Related Questions