1

Hi I'm using source tree with github for unity as an inexperienced user and have made a big mess. Basically I was making changes to a game in the master branch in a higher version of unity 2019.3 and decided to then revert back to a older version of unity earlier in the master branch.

I then created a new branch and started making new game changes in unity 2018.4. I have decided that I want to keep with unity 2018.4 but the problem I have now is that my master branch is behind and has different changes and in a totally different version of unity. I went to merge and resolve conflicts using theirs to keep changes for the 2018.4 branch but it has left a huge mess.

All I want to do is possible is to delete/remove all the changes I made in the master branch in unity 2019 and just make the top of the 2018 branch become the master so I can continue with that as the master branch.

Is this possible to do if so how, I hope my explanation made sense.

  • So to be clear, you just want to remove all of the Unity2019 commits from master, and then merge in your branch that has the Unity2018 changes? – LLSv2.0 Mar 04 '20 at 21:09

2 Answers2

0

Sounds like you'll need to use rebase to remove the 2019 commits from master. Then you should be able to just merge into master.
Try this

Rebase master, drop bad commits, merge branch.

Should be run git rebase -i master replace the "bad" commits keyword with drop. You'll likely want to specify how many commits to edit, this can be relative like HEAD^x or a SHA of the last "good" commit. Then fix and merge conflicts and merge the second branch with git merge branchname.

You might want to make a copy of the repo on your machine or github before doing this as you could mess up pretty bad.

Derek C.
  • 890
  • 8
  • 22
0

Get the latest master, revert your local version to the commit you want to be on the master (latest 2018) (find the commit and right click revert to this revision) and push that.

You have a nice answer just about what you are trying to do in an easier way here :D

Milos Romanic
  • 457
  • 3
  • 12
  • Thanks that worked I now have the master branch at the top and deleted all of my 2019 versions I didnt want to keep. I now have an issue of not being able to push to github as its saying hint: Updates were rejected because the tip of your current branch is behind –  Mar 05 '20 at 17:18
  • I'm not a 100% sure what you did, but it sounds like you didn't do the revers on top of the master branch. So, to recap, you need to have the most recent (HEAD / new 2018) commit on the master branch, revert the commits you don't want (2019), and push that new commit to the master. Hope that helps :D – Milos Romanic Mar 05 '20 at 18:08
  • Thanks again for the information, I no longer see the 2019 commits they have been removed. and I can commit locally fine but I have nothing locally now I want to reverse/remove but I can't figure out how to make it so I can push. I tried pulling and it just made aload of merge conflicts so I had to undo it. –  Mar 05 '20 at 20:11
  • If you're just looking to fix the branch, just delete everything (or just unity stuff that causes conflicts if there are other stuff), commit that, then just copy and paste files that you want to be on the head of the branch, commit that, and push those two commits. Whenever you have commits that won't merge properly and you are sure that you just want to overwrite files, just delete the unwanted one and put the new ones in :D – Milos Romanic Mar 05 '20 at 20:35
  • Hi Im not quite sure what you mean, If youre up for watching it Ive created a short video that shows and explains the mess I've created so you can see exactly my issue as I've no idea what to do with it. I also said thanks Milos at the beginning but for some reason it got cut out https://www.loom.com/share/e1d84e81ae13429687bfb99dca3a2e4d –  Mar 05 '20 at 21:26
  • It appears that you can't push since you have not pulled everything from the master, and you can't pull since you have merge conflicts. I think what you did is that you made that last commit before you were at the top of the master (you didn't pull before commiting). There's two options since I'm not quite sure what changes you have locally : 1. If you want your master to look like your latest local commit, you can merge and keep YOUR versions not the masters. 2. You can stash/patch your latest local commit, pull from the master, and then apply your stash/patch (messy work) – Milos Romanic Mar 06 '20 at 08:46
  • The video was cool, but since your commit messages are not telling me which commits are a problem, if you could go over them I could get a better feeling about what needs to be where. And just a thought, if your latest local commit aint much, just delete it (or revert the changes) https://stackoverflow.com/questions/3197413/how-do-i-delete-unpushed-git-commits , pull from the master (toi update your branch), then do that last commit again :D – Milos Romanic Mar 06 '20 at 08:49
  • Hi thanks again, I want to keep all of my local commits as they are now as I;ve already removed the commits locally I don't want. However I want my online git stored commits to be the same as my local. However when you say about pulling from the master do you mean my commits online? Its the commits online that are stored that have commits I dont want, the local commits are the ones I want but I can;t figure out how to make githubs online stored commits the same as my local if that makes sense? –  Mar 06 '20 at 14:06
  • Then you could try mergeing everything using your local changes (pretty sure you can select all of the conflicts and do that at once). – Milos Romanic Mar 06 '20 at 14:11
  • I've just managed to fix it by pulling everything and unstaging and discarding everything that was pulled so nothing that was pulled was commited I was then able to make a fresh commit locally then push it. Thanks again this mess is finally sorted. –  Mar 06 '20 at 14:47