简体   繁体   中英

How to replace a commit with the commit from another branch

I have a commit from a branch that was deleted. I'm referring to the selected commit in the picture below. The deleted branch is the yellow one.

在此处输入图像描述

As you can see, right under that selected commit, there is an exact duplicate of that commit on the Basic_Gameplay branch (which is the green branch to the left).

I want to get rid of the commit on the no-longer-existing yellow branch and just use the duplicate on the green branch. However, the problem is that the selected yellow commit is referenced in a merge with the blue master branch as you can see in the picture.

Is there a way to get rid of the yellow commit and replace it with the commit from the green Basic_Gameplay branch so that the commit being referenced for the merge with the blue master is the green one, not the yellow one?

You could do the below on the commit referencing the yellow commit and remove the reference. (ensure you have reference to the correct parent commit)

git replace --edit <sha>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM