git filter-branch
might be useful. This allows you to rewrite a series of past commits, changing what was committed.
If the the changes you've made have never left your local repository, then this will work. If you've pushed the offending changes somewhere, or if someone has pulled them from you, then you have a bigger problem of getting rid of them in everyone's repository.
But, to fix your local repository:
git filter-branch --index-filter 'git rm --cached --ignore-unmatch bad-file1.txt bad-file2.txt' master..abc
This means:
git filter-branch
: Let's rewrite some commits!
--index-filter
: Change each commit's index without actually checking it out on disk.
'git rm --cached --ignore-unmatch bad-file1.txt bad-file2.txt'
: For each commit, unstage the two files if they exist.
master..abc
: Do this on all commits on branch abc back to where it forked from the master branch. You could also say "master~3
" to rewrite the past 3 commits, or any other range of revisions. You can also use "-- --all
" (two dashes, space, two dashes, "all") to rewrite everything in your repository.