Adam
Adam

Reputation: 33126

How to remove file from git history without commiting changes?

The standard oft-quoted answer is "use filter-branch".

Great. Except ... that fails:

"Cannot rewrite branches: You have unstaged changes."

I'm trying to un-**** git, but git really doesn't want to help here :(. I can't commit changes on some of the files here for a long, long time. The repository is large enough that I can't clone it a second time on this machine (thanks to git's insistence on pulling down massive .git folders for a long-lived project).

Is there a way to simply "remove file X / file-pattern Y" without having to commit everything first? Fundamentally, commiting is an unrelated process (at the user level), so I'm hoping git doesn't conflate the two internally, and there's a way out of this mess.

Upvotes: 1

Views: 70

Answers (1)

mipadi
mipadi

Reputation: 410552

You can stash your changes, which will allow you to do operations like branch filtering, and then re-apply the stashed changes when you're done (although you may have a lot of conflicts afterwards that you'll have to sort out).

I would suggest committing the changes, though. Is there a reason you're making tons of changes without committing them?

Upvotes: 1

Related Questions