Schalk Neethling

Scripting on Caffiene

There Is a Submodule Commit in Your Pull Request

| Comments

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:

git reset HEAD~2

If you now run git status, you will see all of your changes, as well as a line similar to the following:

M vendor-local/src/bleach

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:

cd vendor-local/src/bleach

Whilst in this directory, run:

git checkout master

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.

cd ~/project/root

Running git status now, will only show your changes excluding the submodule modification from before. Lastly, run the following:

git add --all
git commit -m 'Your descriptive commit message'
git push -f origin your-branch-name

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!