Q:

Git: resolve wrong branch derivation

I have a remote branch master, from which I derived a new branch issue-#4 to work on something.
I did some modifications, I committed them, and I pushed them, but the work was not yet completed.
Then, I found out a more important issue, so I derived a new branch issue-#7. I did a mistake: instead of checking out master first, I derived issue-#7 from issue-#4 instead of master.
I did some other modifications, I committed them, and I pushed them
Then before merging to master, I realized the mistake: issue-#7 contains the commits did on issue-#4.

How can I fix this mistake?
Current situation on origin:
master -> issue-#4 (Commit A) -> issue-#7 (Commit B)
So issue-#4 has Commit A, and issue-#7 has Commit A and B.
Correct situation to restore on origin:
master -> issue-#4 (Commit A)
master -> issue-#7 (Commit B)
So issue-#4 has Commit A, and issue-#7 has Commit B.
Thank you

A:

git rebase --onto master 'issue-#4' 'issue-#7'

will make issue-#7 be derived from master. Then you can force-push issue-#7 and also merge it to master without the commits from issue-#4. Be aware that this will alter published history, so if someone checked out issue-#7 and based some branch on it, he will have to manually do a similar rebase than you did, but I guess in your situation this is unimportant.

