0

git example

After merging master into branch A - a lot of changes were made. We now want to push those changes back to Master.

Unfortunately, someone merged master into a second Branch B - made a lot of changes, then pushed those changes back to Master.

My goal is to have Master contain the code from Branch A (node X) - but NOT the code from branch B (node Y).

The files changed in branch B are entirely different from Branch A - so, for example, if I were to merge master into branch A now - the merge would happen without any conflicts.

I'm happy for master to look as if B's merge/push never happened, or to show it, I don't mind. However, at a later date, I want Branch B to be able do the same thing (merge master into itself, and push to master)

What I've tried:

  • If I just push Branch A(Node X) onto Master, I get the error: ! [rejected] BRANCH_A -> master (non-fast-forward) - SourceTree thinks I've forgotten to merge in B's changes. However, I want to explicitly want to overwrite them...and really don't want to have to merge them in.

  • I've looked up force push - and everything says this is generally not what people are looking for. SourceTree doesn't even allow explicit force push.

What's the cleanest way to handle this? Massive preference for any steps I can take through source-tree.

Community
  • 1
  • 1
Paul
  • 3,318
  • 8
  • 36
  • 60
  • The only really safe option here, assuming you want to remove commits from `master`, would be to use `git revert` on the undesired merge commit. There is a caveat in this case with `git revert`; you'll have to tell Git which parent to follow. You want to follow the `master` parent and not the branch B parent. – Tim Biegeleisen Jul 18 '18 at 15:42
  • Possible duplicate of [How to revert a Git repository to a previous commit](https://stackoverflow.com/questions/4114095/how-to-revert-a-git-repository-to-a-previous-commit) – Liam Jul 18 '18 at 15:51
  • If it were me I'd find the commit I want to get back to then `git reset --hard ` followed by `git push -f` but there are multiple ways to do this – Liam Jul 18 '18 at 15:52

0 Answers0