anon_swe
anon_swe

Reputation: 9355

Git: Update PR with specific changes after branch diverges

I have a local branch, my_branch, that I made after cloning repo. I made two commits (more recent commit first):

I pushed my branch and made a PR. It took a while to get it approved and now I can't merge cleanly into origin/master.

I'd like to get rid of my YAML updates commit, re-run the process that generates those changes locally, and replay my changes on origin/master, fixing any conflicts along the way.

Is this the right approach:

  1. Drop my YAML updates commit with git reset --soft HEAD^

  2. git checkout master; git pull origin master

  3. git checkout my_branch; git checkout origin/master config1.yaml; git checkout origin/master config2.yaml

  4. Re-run process to create YAML updates

  5. git add config1.yaml config2.yaml

  6. git commit -m "Updating YAML files"

  7. git rebase -i master

    If I run into merge conflicts, I should fix them and run git rebase -- continue

  8. Assuming 7. is successful, git push -f

EDIT: Is running the same steps above but swapping steps 4. and 7. equivalent to running steps 1. through 8. in sequence?

I'd normally just try the above before asking, but don't want to mess up my local branch or PR.

Upvotes: 2

Views: 59

Answers (1)

VonC
VonC

Reputation: 1327034

The steps do look good, but anyway, you have low risk of messing up:

  • your local branch: you can always mark it with a new branch or tag, it before starting those step. If the end result isn't what you expect, you can reset to that old state, and start again
  • your PR branch: again, if the new pushed PR branch has any issue, you can force push the old one.

Is swapping steps 4. and 7. equivalent to running steps 1. through 8. in sequence?

Yes: the rebase change the history of commits anyway: so doing your new commit before or after the rebase won't have any adverse effect, and the last step (8) will remain a git push --force.

Upvotes: 2

Related Questions