Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Merge a particular commit to another branch in sourcetree

rintogeorge September 13, 2015

I have to merge a particular commit to another branch. Let's say I have 2 branches live and dev, when I complete the work in the dev need to merge those files to live branch. There are several people working in this project. I don't need to merge all the changes from others, just the changes from my side.

Whenever i tried to merge it always merge everything means all the changes from other user also. Anyone has a solution for this. I am not much familiar with Source tree, neither git.

Below an ref pic for my repo

 

footer-pic.jpg

 

 

 

 

3 answers

1 accepted

3 votes
Answer accepted
Kaz September 13, 2015

You shouldn't have shared a branch with others if you would like to merge your changes only. If you really want to resolve your problem now, I would check out the root of the branch and create another new branch, then cherry pick your own changes only on the branch and merge it to live. It might cause merge conflicts later when others try to merge their changes, though.

rintogeorge September 13, 2015

Thanks!. I just started on this Git things, Can you please elaborate with some steps, how to do this

Kaz September 13, 2015

If you want a branch that only has your changes, first checkout the commit just before any changes are made (right-click on the Log/History and choose Checkout) and make a new branch there. Then, right-click on each your change and choose Cherry Pick until all your changes are committed on the new branch. Now you should have a branch that only has your changes and you could merge it to any other branch. It is not a good idea to have multiple independent changes intermixed on a single branch in my opinion. Make as many branches as necessary as merging a branch is quite easy.

Like # people like this
John L_ Stanley January 18, 2017

Using current version (v1.9.10.0).

No sign of "Cherry Pick" when I right click a change.  What now?

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 23, 2017

@John L. Stanley, sounds like that should be it's own question.

0 votes
John L_ Stanley January 19, 2017

After a bunch of poking around I found it.  At some point, "Cherry Pick" was renamed.

So follow Kaz's second posting (the one dated Sept 14, 2015), but select the "Graft.." menu item instead of the now non-existent "Cherry Pick".

Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 23, 2017

Are you possibly using Mercurial instead of Git? SourceTree uses the terminology of the underlying DVCS.

0 votes
Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 14, 2015

If you want only the changes from a few commits (or just one, ideally), you can use the cherry-pick feature.

Checkout the branch you want to apply the changes to, then right-click the commit that has the changes you want and choose cherry-pick.

In the future, you should follow Kaz's advice: if you are going to want to keep your changes separate from others' changes, you should commit them into a separate, local-only branch. Your team might want to consider using the git flow development model:

https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

http://nvie.com/posts/a-successful-git-branching-model/

SourceTree even has directly integrated a git plugin to facilitate git flow. Make sure you understand it before you try to use it, though.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events