Every now and again it so happens that you open a pull request, forgetting to check the diff before doing so, only to find that there is an unintended submodule commit in your pull request.
Now submodules in Git is a touchy subject for many but alas, many projects do use them. So, what to do when caught in this situation? Well, luckily it is rather easy to get that unwanted submodule commit out of your pull request. First things first.
Make sure you are on the branch you are opening the pull request from. Now we need to reset the
HEAD to the point where you branched from master. The number you use here is going to depend on the number of commits you have made since you branched. For example, say you have have made two commits since branching. In this case you want to run:
If you now run
git status, you will see all of your changes, as well as a line similar to the following:
This indicates that the submodule bleach has been modified, and this is what you want to get rid of. Now, change directory into the submodule directory, in this case:
Whilst in this directory, run:
Now that your submodule is up to date with it's master branch, you are ready to move back up to your branch, add your changes, create a new commit and force push your branch with just your changes.
git status now, will only show your changes excluding the submodule modification from before. Lastly, run the following:
1 2 3
Navigating to your pull request on Github, you should only see your changes in the diff and no longer see the submodule commit. You are all good to go!