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

Change commit code to other branch (Sourcetree for Windows)

Xavier Pimienta
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 18, 2013

Hi!

I am newbie with this tool and Git.

I put a 'new' branch code in 'master' branch, how can I change it to put in the right place?

Thanks a lot!!!

Xavier

1 answer

17 votes
stevestreeting
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.
June 18, 2013

That depends:

  1. If you haven't committed the change yet, you can just create a new branch (or check out another branch) right now and then commit. If there are conflicting changes in the other branch you can Stash your changes before switching, then Apply the stash again afterwards.
  2. If you have committed the change, but you haven't pushed it to anyone else, you can right-click on the commit *before* that commit and use the 'Reset branch to this commit' option to move the master branch backwards, undoing that commit. The default 'Mixed' mode should be used in the reset dialog so that your changes still exist in your local folder, they just become uncommitted again. Then, go to 1.
  3. If you've committed the change *and* you've pushed it, then you can't undo it because other people may have already seen it. You can copy the commit to the other branch by checking out the other branch then right-clicking that commit and selecting 'Cherry Pick'. This will copy that commit over to your other branch but won't undo it on master.

HTH!

jonathan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 10, 2013

Thank you for a very useful reply!

Regarding #3 it's really not possible to delete commits already pushed to origin? Even if I'm the only contributor?

Thanks!

Jens Gössing
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 12, 2017

Hey, very good explanation of the options. Thanks.

I need top go for option "2." but don't know whether to do this on master or on the branch the commit was meant to go to?

Jens Gössing
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 12, 2017

... think I just figured it with common sense. It's to be executed on the master and of course the right click needs to be on the previos entry (BEFORE the "wrong commit") ...

Johannes Herrmann
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 27, 2018

Thank you :)

Helped me a lot!

Tauqir Pervez
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 15, 2018

Thanks, exactly what I was looking for! :)

Elias Simon
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 7, 2020

For the (2) scenario, is there a way to avoid re-commits? In Mercurial, you can change the working directory, change the branch, and then graft the commits over, rather than having to make new ones.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events