Git - Reset commit in master or cherry-pick / merge to sync up master's commit to other branch

56 Views Asked by At

Initially I have master and develop branch at the same state, but I accidently make some commits directly to the master.

Now I'm going to sync the master's commit to develop, but our practices is branch out feature from develop and make changes to the feature and then PR to the develop.

So I branched out a feature branch sync_up_develop_with_master and planned to cherry-pick the master's commit into this feature branch.

enter image description here

But I read some articles which says merge is preferable over cherry-pick (due to SHA1 identifier). or should I just reset the commit in master since it's just minor changes.

Can anyone suggest me the correct approach on my case? Thanks.

1

There are 1 best solutions below

0
LeGEC On

In your situation: from branch develop, you can run

# from branch develop
git merge --autostash --ff-only master

and develop will be updated.


--autostash will handle the git stash / git stash pop around your merge operation to port your uncommitted changes

--ff-only makes sure that git merge will perform only fast-forward actions. That way you are 100% certain that this command will not accidentally create an unwanted merge commit.