N
N
Nikita2021-04-24 21:19:39
git
Nikita, 2021-04-24 21:19:39

How to upload the content of another branch to the master, avoiding all conflicts?

There are two branches: master and feature. feature is significantly ahead of master in terms of commits, and with a normal merge, a huge number of conflicts arise, which there is no desire to fix on your own, how can you forcefully push changes to the feature branch into the master branch in such a way that the master content is of no interest?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
Xitsa, 2021-04-29
@MiiZZo

This is, of course, a strange situation, but it happens, so it's best to simulate a merge, where the contents of one branch will be completely replaced by another:

git checkout master
git commit-tree -p master -p feature -m "Overriding master with feature" feature^{tree}
12346aa23590aa
git merge --ff 12346aa23590aa

The git commit-tree command will create a merge commit of the master and the feature, where the contents of the master will be completely replaced by the feature, and will output the identifier of this commit.
The last command integrates this commit into the master.
Advantages:
  • Looks like a normal merge commit
  • Correctly saves branch history
  • No need to go through the developers to execute any commands

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question