0
o-master-remotes/origin/master good commit message
|
|
|   commit 99 we want to remove this commit
|  /
| / 
|/
o-commit 77
|

We have the git structure above and have pushed commit 99 to the remote. So commit 99 is stranded.

We would like to remove commit 99 from the remote repo? How do we do that?

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
Angus Comber
  • 9,316
  • 14
  • 59
  • 107
  • Is the commit part of any branch? If not, garbage collection should eventually remove it; see also https://stackoverflow.com/q/3162786/14637. – Thomas Sep 07 '21 at 10:41
  • Commit 77 then appears to be a merge commit. You would probably have to redo the merge in this case. Why do you want to remove commit 99? – Tim Biegeleisen Sep 07 '21 at 10:42
  • @TimBiegeleisen: the graph above seems to be drawn the way Git does, i.e., backwards, so commit 77 isn't a merge, but rather the place where two different commits spring forth: a "fork" as it were. (Note to OP: drawing the graph "backwards" is often a good idea since Git itself *works* backwards.) – torek Sep 07 '21 at 17:26

1 Answers1

0

If commit 99 is detached the garbage collection should clean it up just like @Thomas mentioned in the comments.

If that doesn't happen, it's probably a part of some branch. In that case, you should be able to see the branch name and delete the branch altogether using:

git push origin :<branch-name>
Daniel Trugman
  • 8,186
  • 20
  • 41