-
Notifications
You must be signed in to change notification settings - Fork 2
Fix broken pushes using force push
We use a heirarchy of sub-repos in our codebase. Our structure looks like:
website
experiment (theshold-scientist)
threshold
psychojs
This adds a bit of complexity to our system, and comes with additional requirements when pushing changes to ensure each level of the heirarchy references the correct subreposity. That is, it's not enough to ensure that you're referencing the current remote head of website
when pushing changes to website
; you need to ensure that the reference to threshold-scientist
is pointing to the current remote head of that repo, and likewise with experiment
.
When your repo references are out of sync with the remote, this can cause problems. Namely, Netlify will fail to deploy. When this occurs, one way to resolve the situation is to --force push
the remote to a previous, working commit. (Note this isn't ideal, as it removes the broken commits from the history. It is therefore imperative that whoever pushed the breaking commits retains them in their local working history, so they don't get permanently obliterated in the change. A more elegent solution would be great, if it can be found.)
To make this change to a previous, working commit, start by changing the branch permission for website/main
to allow force pushes. (Information on configuring branch permissions. We might want to consider leaving this permission on, but turning it on and then off when done with the fix seems a more conservative approach).
Go through the git log to find the last working commit. Copy the SHA hash provided. You can then run git push --force origin bigLongHash:main
to force push our github remote to that last working commit. (Note, assuming here that your local name for this GH remote location is origin
). See more about this process here. This proceedure should then be applied for the other sub-repos with broken commits, eg git push --force origin thresholdScientistWorkingCommitHash:new-main
from threshold-scientist
.
Once all the relevant repos have been pushed back to the previous working commit, Netlify will rebuild -- and hopefully succeed! At this time, the developer with the initially broken commit can pull in all repos (or run npm run pull
from website
) to ensure they are referencing the remote HEADs, and try pushing their changes once more. One straightforward way to do this is to run git reset --soft HEAD~n
to undo the last n
commits (ie those which caused the initial break) and keep their changes in working directory, git stash
in each repo with changes, then call npm run pull
from website
(perhaps multiple times, until it returns ALready up to date.
for each repo, ensuring that each repo has its HEAD at the correct commit), then run git stash pop
in each repo where changes were stashed.
At this point, you should now have your changes as un-staged in the working directory, applied on top of the remote HEADs for each repo. From here you should be able to run npm run git ...
from website
to push changes together at each relevant level. Check that Netlify
builds successfully as confirmation that your fix has worked.