The wrong development branch was merged into a main branch.
Background
The same repository holds the following branches and corresponding content. Initially the respective main and dev branches have the same state.
design-main
design-dev
D-files-v1 (the design itself - can never contain any test files)
test-main
test-dev
D-files-v1 (the design itself - latest from main design branch)
T-files-v1 (files for testing the design in D-files)
Development flow/process
Git repo policy restrictions
- Rewriting history (e.g. git reset --hard …) not allowed
- Developer cannot push to main branches (only admin can do so)
- main branches only updated by pushing dev branch, then create pull request to merge pushed dev branch into main
- Ideally the design branch would be in a separate repository, and subsequently a submodule in the test test repo. In which case this mistake could have bee avoided. But this is not an option as the dev flow is not changeable (at least not by me :))
Assumptions
- main and dev branches have the same (-v1) respective state
- Developer has pulled dev branches with -v1 state and made changes to D-files and T-files
Merge process
- Developer pushes changes to design-dev and test-dev, which now have the following content
design-dev
D-files-v2
test-dev
D-files-v1
T-files-v2
- Pushed dev branches are merged into respective main branches. Main branches now have the following content
design-main
D-files-v2
test-main
D-files-v1
T-files-v2
- test-main needs to be updated with the latest design files, achieved by merging design-main -> test-main. This is the expected state of the main branches after this merge
design-main
D-files-v2
test-main
D-files-v2
T-files-v2
Problem - merged wrong branch
In the step 3 (above), the wrong branch was merged into design-main. Instead of design-main -> test-main, the actual merge was test-dev -> design-main! The state of design-main after the merge is:
design-main
D-files-v2
T-files-v2 [these files are not allowed in this branch]
Undoing the bad merge, solution #1
The most straightforward way to resolve the issue is to move HEAD of design-main back 1 commit, just prior to the merge [git reset --hard HEAD~1]. Then do the design-main -> test-main merge (as was the original intent) This is not allowed due to git policy restrictions on rewriting history, and developer not having privileges to push main branches
Undoing the bad merge, solution #2
Git revert seems to be the ideal solution [git revert -m 1]. Indeed, this does restore the state of design-main to that of the pre-merge state. But (my understanding) it achieves this by adding a commit that undoes what was done in the previous merged. And in doing so, history is preserved.
With design-main restored to its' desired state, we can now proceed with step 3, above, and merge design-main -> test-main. After this merge, test-main is not in the desired state - the D-files are updated but the T-files have been deleted!
test-main
D-files-v2
T-files-v2 <-- these gone after the merge
Two different methods - git reset --hard and git revert - both restored design-main to the pre-merge state. But subsequent merges of fixed design-main -> test-main did not act the same way.
Summary
Could someone suggest a combination of dev branch changes and merges that would result in the main branches being in the state described in step 3, above?
It would be helpful to also know why the git revert approach caused subsequent merges to not work as expected.
git push -f ...which would revert the merge. Obviously: have them re-activate the flag right afterwards.