Reputation: 5176
I have the most recent commit Y, the second-recent commit X, and many (50+) commits before commit X. I need to remove commit X (leaked passwords) and make let Y remain. How to do it?
I have pushed all commit to remote repository too.
PS decided to resert last two commits and copy paste sc after
git reset --hard HEAD^^
works for local rep, doesn't work for remote (after push, still see those commits)
Upvotes: 1
Views: 641
Reputation: 111
If you have already fixed the issue in commit Y and just want to rewrite the history to remove commit X (as it contains passwords) then you could git rebase -i head~2
and select to squash X and Y then git push -f
. Typically this is not recommended, but if you have passwords in the commit then I guess it can be overlooked.
Upvotes: 3
Reputation: 6088
git reset --soft <<last commit you want to keep>>
then you can just re-add
only the stuff you want, then recommit and push. This may require a git push -f
which is only gonna be ok if you are sure no one else has pulled/you can coordinate with all concerned parties.
You can also git revert
the commit, but it only takes it out of your working tree, not your git history. The above solution is the only way I know of to blow it away completely (remove it from GH and history).
Upvotes: 3