-1

The issue: There is a folder in my GitHub repo, in a branch called 'my-branch' and it needs to be removed. It is not the last commit.

Details of issue:

  1. created a branch off of master, let's call it 'my-branch'.
  2. did some work in 'my-branch' including an upgrade that included a cache directory (.angular/cache/...).
  3. ran these commands - git add. ; git commit -m "some message" ; git push origin head
  4. the push failed since the files were too large for git.
  5. realizing that folder should not have been pushed in the first place, I updated the .gitignore and did a subsequent push (git add .gitignore; git commit -m "added /.angular/cache to .gitignore" ; git push origin head)
  6. The problem is that the history of 'my-branch' still contains the directory '/.angular/cache' and I got hit with bot security scanner saying that the folder is still in some commit (84bd63...).
  7. I tried to run 'bfg-repo-cleaner' tool to delete that folder completely from the history, but failed to push since develop and master branches are protected.
  8. Now I see the folder is still being picked up by the bot scanner, but above it, it says that the file doesn't belong to any branch.

Desired Outcome:

  1. Remove the folder from the history of "my-branch" not touching any other branches or master.
  2. 'Master' and 'develop' branch are protected and I do not have access to write to them directly, which is why the 'bfg-repo-cleaner' failed to push.

PLEASE HELP

A K
  • 3
  • 1
  • 1
    `develop and master branches are protected.` is the problematic commit in either of these branches? Assuming not it’s not relevant (and means whatever you did that didn’t work - was not what was needed). Please edit the question to clarify – AD7six Nov 24 '22 at 19:54
  • 1
    Does this answer your question? [How to remove/delete a large file from commit history in the Git repository?](https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-the-git-repository) (remember to only force push to `my-branch`) – AD7six Nov 24 '22 at 19:55

1 Answers1

2

If the branch is straight (at least, since adding that directory), it's rather simple to correct

git rebase -i the-commit-where-the-directory-was-added~ # do _not_ skip the pig tail, it has to biñe there
# the commit should be the first in tbe list
# change pick for edit in that commit only
# save exit
# rebase will stop right after applying that commit
git rm --cached the-directory
# consider adding the directory to .gitignore and add it also so it's not added by mistake later
git commit --amend --no-edit
git rebase --continue

When it finishes running, you should have a branch without the directory

eftshift0
  • 26,375
  • 3
  • 36
  • 60