3

So I am working on a project and add a gitignore file to prevent some sensitive data from being included only it fails to work as expected and now I have pushed it. Is there a way to delete that from the remote repository so there is no evidence of it in the history?

ChiliYago
  • 11,341
  • 23
  • 79
  • 126
  • Are you the only one working on the repository? – Stephan Jul 19 '18 at 13:17
  • If no one else has pulled or pushed in the meantime, you can try removing the information, and using `git commit --amend` to change the existing commit. A `git push --force`, while bad practice, will overwrite the remote. This assumes that the server will completely trust you and will not keep track of force pushed changes. If it does, and you don't administer the git server, you're SOL. – Thomas Jager Jul 19 '18 at 13:20
  • @Stephan: yes at this point I am the only one working on the repository. – ChiliYago Jul 19 '18 at 13:21
  • 1
    Possible duplicate of [Remove sensitive files and their commits from Git history](https://stackoverflow.com/questions/872565/remove-sensitive-files-and-their-commits-from-git-history) – phd Jul 19 '18 at 14:20

2 Answers2

2

You could revert the changes locally

git commit --amend

or

git reset <last-hash>

and then do a

git push -f

but this should only be done

if you:

  1. (know what your doing ;-) )
  2. noone else did something with the repo in the meantime

Tip:

Be very careful, that the repository is in the state you want it to be, before you push -f, because changing history is generally a big no-no for various good reasons

Stephan
  • 1,639
  • 3
  • 15
  • 26
  • 1. I only know a little about what I am doing. This is a real pain in the arse! Someone should make resolving this issue a lot less painful. – ChiliYago Jul 19 '18 at 13:23
  • no, this is done intentionally. if you `push -f` you change history, which causes a lot of pain for everyone else in your team (working on the repo) - in your case you can do it, because you are the only consumer – Stephan Jul 19 '18 at 13:24
1

If the sensitive information was introduced before the most recent commit and you would like to remove it from the full tree, I recommend git BFG.

See: https://help.github.com/articles/removing-sensitive-data-from-a-repository/

If you commit sensitive data, such as a password or SSH key into a Git repository, you can remove it from the history. To entirely remove unwanted files from a repository's history you can use either the git filter-branch command or the BFG Repo-Cleaner.

Also, https://rtyley.github.io/bfg-repo-cleaner/

The BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data >out of your Git repository history:

  • Removing Crazy Big Files
  • Removing Passwords, Credentials & other Private data
Oliver Evans
  • 1,405
  • 14
  • 17
  • 1
    I tried this but it is complicated and my attempt so far have not removed the content from the remote repository – ChiliYago Jul 19 '18 at 16:22