Search code examples
gitgit-revertsubproject

How to revert an automatic subproject commit in git


I have couple of submodules in my project and I inadvertently made some changes to the modules. Though I did not explicitly check in the changes, I see the subproject commits when I diff the repository.enter image description here
(Using stash)

When I do a git status on my local repo. it showed a (modified content) against the subproject. So I moved to the subdirectory of the subproject and discarded the changes. When I do a git status now, the (modified content) does not show. However, since there are no commits, I cannot check in or revert the inadvertent commit shown in pic. git revert <green commit hash in pic> errors out as there is no such commit in my local repo.

Please help me understand how I can revert the commit on my subproject. These commits do not show even when I go into the subdirectory of the subproject.


Solution

  • Not sure if it's the best way, but I found out how to do it.

    1. I discard all my changes on my subproject by git checkout -- <file>
    2. When I do a git branch on the subproject, it shows it's detached from HEAD. I do a git pull origin master.
    3. Now , when I go to the root project and do a git status, it shows (new commits) besides the subproject. Add the subproject using git add <subproject-name> and git commit
    4. git push the changes to the remote repository.