How fix my git branches after squashing is master behind dev
Asked Answered
T

2

7

I have created 2 commits to remote dev branch. That I squashed and merge into remote master branch.

Now when I want to continue with working on dev branch - I don't know how can I correctly "repair" my branches - because after creating new pull request from dev to master I get list of all commits which were squashed in previous pull request.

I have something like this:

O ---- A ---- B ---- XY <--(master)
 \
  X ---- Y ---- Z <--(development)

How can I create correct pull request with commit Z from dev to master?

Tarantula answered 23/6, 2018 at 6:59 Comment(2)
You should use the git bash or github ?Iseult
I am working with githubTarantula
T
6

Before adding new commits to your dev branch, you should first reset it to origin/master, since you squashed/merge dev to it.

In order to not break anything, create a new branch from origin/master:

cd /local/repo
git fetch
git checkout -b newBranch origin/master

Then report back your new commits on that new branch:

git cherry-pick Y..Z

Finally, reset your dev branch to said new branch:

git checkout dev
git reset --hard newBranch

And force push: git push --force.

The end result would be a new PR with only the new commits

Tramroad answered 23/6, 2018 at 7:58 Comment(0)
C
1

If you're unable to correctly determine the Y commit, in case we're talking about a much more complex scenario, reverting the XY commit from master also works:

git checkout master
git revert XY
git push

Then your pull request from dev to master will have no conflicts anymore.

Cruciform answered 15/4, 2021 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.