I have a remote repo with 7 total commits (let's call them A - G, with G being the most recent commit). Commits C and E didn't actually warrant a brand new commit, and I'd like to remove them from the remote commit history all while keeping commit G as HEAD. How can I do this?
Asked
Active
Viewed 47 times
0
-
1Possible duplicate of [How to squash commits in git after they have been pushed?](https://stackoverflow.com/questions/5667884/how-to-squash-commits-in-git-after-they-have-been-pushed) – Robin Green Dec 07 '18 at 23:32
-
Please take a look here: https://stackoverflow.com/a/11955118/1506009 - The interactive git rebase is what you're looking for. – Rozart Dec 07 '18 at 23:56
1 Answers
0
The git documentation says the following about this:
A range of commits could also be removed with rebase. If we have the following situation:
E---F---G---H---I---J topicA
then the command
git rebase --onto topicA~5 topicA~3 topicA
would result in the removal of commits F and G:
E---H'---I'---J' topicA
This is useful if F and G were flawed in some way, or should not be part of topicA. Note that the argument to --onto and the parameter can be any valid commit-ish.
BUT this applies only the local repo in the first place. So when pushing this modified commit history to your remote, you need to have sufficient privileges to do so. See force push for more details. I can tell you from my own experience, that this can be an issue in MS TFS.

salchint
- 371
- 3
- 10