I have 7 recent commits that I want to remove a folder from - this folder (and its contents) don't need to be in these commits and were not in previous commits (prior to these past 7). Can I amend these past recent 7 commits and remove this folder?
These 7 commits were not made on the Master branch. So another possible option would be to create a new branch/pull request off of the Master and re-commit the most recent of the 7 commits without the folder in question being staged.
Are either of these options possible?
There are two basic options.
First, if the files were added in the first one of those seven commits, and they haven't been touched in the six commits that followed, you can git rebase -i, choose "edit" for the seventh oldest commit, the one that added the files, then after getting dropped back into the shell you can "git rm" the stuff you want to get rid of, commit that, git rebase --continue, then after the remaining commits get replayed you rebase again, and squash the new commit into its parent. This would be the easiest way to handle that situation.
Otherwise, you can use git filter-branch with the --tree-filter option, to wipe the files in question from all seven commits.
EDIT: note that this course of action presumes that you have not pushed your branch up. If you already pushed this branch, this raises some additional logistics. Basically, once you push, you need to coordinate this action with anyone else who depends on your branch, because you're going to leave them high and dry. You're going to basically discard your current branch, and replace it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With