3

I have some forked repository with my feature branches. I kept it up-to-date with the upstream using fetch/merge. At some point, upstream owner edited one commit (C2) and rewrote the whole history from that point forward (C2'-C3').

----C1---C2'--...---C3'--C5---...---C6(upstream/master)
     \
      ---C2---...---C3(origin/master)
                     \
                      ---C4(origin/feature-branch)

How can I get my fork synced now? I'd like to somehow rewrite C2-C3 with C2'-C3', rebase C4 on top of C3' and then sync my fork up to C6. I'd like to avoid just merging C6 into C3.

SOLVED:

$ git fetch upstream
$ git reset --hard upstream/master --
$ git push origin +master
$ git checkout feature-branch
$ git reset --hard master --
$ git cherry-pick C4
$ git push origin +feature-branch
sikmir
  • 178
  • 2
  • 6
  • 1
    Possible duplicate of [Git pull after forced update](https://stackoverflow.com/questions/9813816/git-pull-after-forced-update) – pschichtel Jul 12 '18 at 09:14

1 Answers1

1

As long as it's only a few commits, you can always use git cherry-pick (https://git-scm.com/docs/git-cherry-pick).

One way to do this is to clone your main branch, reset the main branch to upstream/master, then cherry pick the commits you want from the cloned branch.

Jacob Sievers
  • 506
  • 4
  • 13