I am trying to rebase a branch onto a drastically different one. It's a React project. If I merge two branches brutally, I cannot even compile the code. Therefore, I am trying to rebase interactively.
While doing that, I want to make sure that after each rebase step the code base can compile. What would be a way to automatically reinstall node_modules
and rerun the project (say I use yarn start
to run the project) after each git rebase --continue
?
Or if I am not on an ideal route, what would be the right way to merge those two branches?
The way to do this is use -x
/--exec
to run a command between each step. For example, if I do:
git rebase HEAD~3 -i -x 'npm run ship'
Then I see the following rebase plan:
pick <hash> <message>
exec npm run ship
pick <hash> <message>
exec npm run ship
pick <hash> <message>
exec npm run ship
In this case npm run ship
is the command that runs all of the linting, testing, etc. to check that each commit is still good.
Note that the command needs to succeed (i.e. exit 0) for the rebase to continue, so make sure that's true of whatever you plan to do to check each commit.