SourceTree - make a branch a new master

Im using GIT and Sourcetree as gui.

I have two branches - master and function-01. Now I want to rewrite everything to master using function-01.

I had to do this after canceling a few changes on the host. however, I canceled the changes in the new branch, I got the branch 100% where I want the master to be, but now when I merge the two masters, it saves all the rollback changes that it should discard, as in the branch: /

+6
source share
3 answers

You can do the following:

  • From feature-01 branch: git merge --strategy=ours master
  • Then from your main branch: git merge feature-01

The first command will create a new (merge) commit from two branches, but ignore everything in master using the --strategy=ours parameter. Then the second command will push master to this new commit.

At this point, you will have the feature content in master . With this option, you do not need to "reset" the remote or anything like that; it will just put in the master all the work you have done in feature .

+4
source

Is this possible in SourceTree?

No, this is not possible because merge --ours not supported in Sourcetree.
(I tested it with the latest 2.1.11.0, with Git 2.14.1, September 2017).

See SRCTREEWIN-1237 (... since 2013!)

I need to use our strategy, i.e. merge myBranch into master, discarding any changes to myBranch

 git merge -s ours myBranch 

This is still not available when merging two branches:

merge options


As mentioned in this article , you will need to define a custom action:

custom action

This will allow you to emulate the merge --ours step of the following sequence.

 git checkout feature-01 git merge --strategy=ours master git checkout master git merge feature-01 

SourceTree supports checkout and simple merge . A custom action allows you to perform the merge --ours step.
And then the contents of master will be replaced by the contents of feature-01 .
Completely from SourceTree.


For mercurial, following " Replace the contents of hg branch ", you need to create your own action (as shown above) for the hg branch -f command (the -f option is not available in the regular branch dialog)

+1
source

You can delete the main branch (it's just a name marked with a commit), and then recreate it where you want:

 git branch -d master // this will delete the branch git checkout feature-01 git branch master // this will recreate it where you are checked out. 

Be careful if you share this repository, you need to clear the console, and you should probably talk to someone who uses the repository / is responsible for the repository, because you will rewrite the history.

-1
source

Source: https://habr.com/ru/post/985066/


All Articles