Reputation: 41921
Imagine that you have committed several changes (in separate commits). For example, we have 3 commits: A , B and C.
Now, you have found out that in the commit B you have added a certain file (including some changes) that you shouldn't have committed.
How would you remove that file in that commit?
An example would be great.
Thanks
Upvotes: 0
Views: 3031
Reputation: 2080
you could also do
git rebase --interactive A
and edit commit B not to include the file in question
but same warning applies and if you made changes to file in any commit after B these will fail to apply
Upvotes: 1
Reputation: 36084
git filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD
This command will remove a file from all commits [from history].
Warning: If you've already shared your work with others, it's not recommended to use this command. Please make sure you understood the full implications before using this command.
Upvotes: 1