0

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.

enter image description here

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?

Jorge Luque
  • 435
  • 1
  • 4
  • 17

1 Answers1

1

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>
joy
  • 327
  • 4
  • 11
  • thanks that sort of works. I can alter the way the visual representation of the branches looks like in SourceTree but it still shows that the old SHA1 under the "parent" section. This method also doesn't work on SmartGit and also it seems like the changes to the references are not pushed to the remote repo. Is there another way to edit the SHA1 of the parents of a commit? – Jorge Luque Jun 05 '20 at 13:06
  • 1
    perhaps this could help : https://stackoverflow.com/questions/14244888/remove-spurious-commit-parent-pointer – joy Jun 05 '20 at 20:37
  • Although that fixed my local repo, I'm unable to push the new git refs to the remote repo. I tried doing a "force push" in SourceTree but it says: `! [rejected] master -> master (stale info) error: failed to push some refs to 'https://gitlab.com.....` – Jorge Luque Jun 05 '20 at 23:55
  • ok so I fixed the previous error by removing protection from the branch in GitLab. However, after I push the master branch, the whole repository looks messed up. Is there a way to push all the changes made to the git references? – Jorge Luque Jun 06 '20 at 00:49
  • Oh never mind, it fixed after I forced push ALL the branches. thanks again! – Jorge Luque Jun 06 '20 at 01:21
  • `git replace` is a low-level command and should only be used by experts. You can use `git rebase --rebase-merges --interactive` to change the history in a user-friendly way. – Mikhail Jun 10 '20 at 11:07