We accidentally put a bunch of new commits directly into our Master branch, and now we need to bring them back into Staging. What is the best way to do this to prevent git issues?
Here's our flow (notice how we typically go from feature branches to Staging, then Master):
Feature Branches -> Staging -> Master -> Deploy
CodePudding user response:
You can simply reset staging to master:
git checkout staging
git reset --hard origin/master
git push --force
This will make staging identical to master. The problems that you could encounter with this approach is that any feature branches merged to staging, but not yet in master, will need to be re-merged in staging again.
If you have other considerations, let us know in the comments happy to re-think my answer then.
CodePudding user response:
Assuming you are talking about the local copy of master.
Go to staging branch:
git checkout staging
Rebase it on top of master (which includes the changes you want):
git rebase master
Or, instaed of rebase master, you can use:
git cherry-pick <commit-sha1>
For each commit you want to bring from master into staging branch