I have accidently push a commit which modified a git subtree. What to do now?

I have pushed a commit which modified a git subtree (not by pulling from the repository where the subtree was initially pulled). What is a clean way to restore the subtree to be what it used to be?

1 answer

  • answered 2018-11-08 06:29 Mohit Mutha

    Following ways to do it

    1. Add a new commit manually reverting the changes done to the files. This is the safest option
    2. Revert the commit git revert ddlpopp (replace ddlpopp with your commit id). This will simply add a new commit reverting the changes in the specified commit. This can be used for any commit not just the last commit. It may introduce some unexpected changes, so be careful and review before pushing
    3. Explicit rewrite of the head. This should be used extremely rarely. This will simply reset the head of the remote

      git reset --hard HEAD~1

      git push -f

    Here is an excellent article http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.html