2

This is three parts this is a more step-by-step question than Make Git rebuild history using the current .gitignore

  1. I was wondering if it is possible to do a rebase to some early point in history and set the .gitignore rules there such that it carries it all the way to the top. The way I do it is git checkout KNOWN_COMMIT_WITH_PROPER_GITIGNORE .gitignore && git rebase --continue

  2. Apply the removal of ignored files for each commit in the history while --preserve-merges https://stackoverflow.com/a/19757964/242042. I am thinking this can be done in a similar way of git-filter-branch

  3. Create an alias that would do this operation

Key thing is that this needs to be based on the .gitignore that could've changed over time and I want a specific version of the .gitignore file applied to the first commit and applied through the rest of history.

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265
  • 1
    Possible duplicate of [Completely remove file from all Git repository commit history](https://stackoverflow.com/questions/307828/completely-remove-file-from-all-git-repository-commit-history) – Code-Apprentice Mar 04 '18 at 20:09
  • Close but I wanted it to apply the removal based on the .gitignore files. – Archimedes Trajano Mar 04 '18 at 20:10
  • It's tricky, but I believe you can do this with `git filter-branch`. I think I even provided code to do it in some earlier StackOverflow posting. – torek Mar 04 '18 at 20:12
  • Maybe you can point to the posting, because the ones I had found I put in there already. – Archimedes Trajano Mar 04 '18 at 20:13
  • Found it: https://stackoverflow.com/q/43463687/1256452 (the trick was google search for `git filter-branch gitignore torek site:stackoverflow.com`). – torek Mar 05 '18 at 06:07

1 Answers1

0

I think you can combine 'git filter-branch' with 'git ls-files'. Something like this:

git filter-branch --index-filter 'git rm --cached `git ls-files --exclude-standard -i`'

I.e., filter the branch and modify index; for every commit list ignored files in the index and remove them from the index.

PS. But please make a backup before experimenting.

phd
  • 82,685
  • 13
  • 120
  • 165