Oscar Mederos
Oscar Mederos

Reputation: 29813

Remove files added in lots of commits in the past

In the last 30-40 commits I included a folder and I just realized I shouldn't have done that.

My main concern is that when I push those changes to Github, it will take a while because of the size of those files...

Is there a way to completely remove that folder (or some files) from past commits?

Upvotes: 1

Views: 84

Answers (3)

phb
phb

Reputation: 721

You most probably want to use git filter-branch. Github has a fairly good tutorial how to use it here.

The following line should do the trick:

git filter-branch --index-filter 'git rm --cached --ignore-unmatch -r <path>' --prune-empty -- --all

Make sure you're using -r <path> if you want to remove a folder.

Upvotes: 3

Learath2
Learath2

Reputation: 21343

You can use git filter branch git filter-branch --index-filter 'git rm --cached --ignore-unmatch YOURFOLDER' --prune-empty -- --all this command will run through all the commits deleting YOURFOLDER you can push normally as you didn't push it yet. I use this command quite alot.

Upvotes: 1

Jack Edmonds
Jack Edmonds

Reputation: 33171

You can edit history in Git by doing an interactive rebase. Figure out the first commit before you introduced the folder and git rebase -i <that commit id>.

Upvotes: 1

Related Questions