Merge Conflicts Guide | Visual Studio 2022 (Git)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up my name is technobe here for troubleshoot and welcome back to another video so welcome to visual studio 2022 over here in this video i'll show you how to merge conflicting branches or with pull requests from github inside of visual studio 2022 essentially i'm working on my techno account such a project here and someone else was helping me out with the project making their own commits and i merged their changes so essentially as you can see over here when i look at the different branch you can see on commits ahead and commits behind the master branch over here meaning i can't simply just merge these together as you can see open a pull request can't automatically merge but we can create one already and we can try and fix it or resolve it on github here though things can get very confusing very quickly the normal text way of doing this is clicking resolve conflicts and will be dropped into this page here with all of the different conflicting files on the left hand side and a text editor on the right do note that there are two scroll bars here so if you get confused make sure you're grabbing the right one so simply scrolling down you'll see an orange section where the issue is essentially we have this incoming section here and the existing section here these two have both had changes on their respective branches and need to be resolved before we can merge things properly essentially this was the original and a couple of bits of text were changed here and of course this was replaced with all of this on the incoming branch all we need to do is decide what we want to keep i can either get rid of the incoming by simply editing as such or i can get rid of the existing by editing as such and now we're left with only the new changes there's also a next and previous button over here that allows us to go back and forth between different conflicting issues in a file let's say we'll keep the incoming changes as such we can click mark as resolved and we'll then be able to merge these two branches but how exactly do we do this in visual studio 2022 which becomes especially useful when there's tons of these because there's no code highlighting here well i'll simply open up the project in visual studio 2022 this is the part that i was coding and at the very top i'll head across to get which is up here then manage branches now inside of here you may get a bit confused essentially this main section here has all of the different commits from everyone and the section on the side here has all of the different forks pull requests etc etc this gamestats.json branch over here what i'm trying to merge with master over here if you can tell master is currently bold which means i currently have this one selected and these are my files locally you can double click to change between branches here and when you do your code editor may reload you may need to go back to git then manage branches so now that i've double clicked on master i'm in the master branch and it's bold if i want to merge gamestats.json this branch over here with the master i'll simply right click it then inside of here we have merge game stats into master this is what i want to do so i'll click it and i'll click yes over here so things have changed but not really just yet if we head back to the manage you'll see merge completed with conflicts resolve the conflicts and commit the results up here we can click resolve the conflicts to open up a new window on the right hand side here get changes inside of here we'll have all of the different files that have been edited and i'll simply expand it to make it a bit more readable these down here are staged changes and the one that says both modified is where the conflicts are under unmerged changes if yours doesn't look like this head across to get in the top left then settings and inside of here undo get global settings scroll down and make sure that commit changes after merge by default is unticked then click ok if you'd like to compare these different files here the staged and the unmerged we can simply right click any file and click compare with unmodified this will open up a new window that looks somewhat similar to what you may see on github in fact i'll open a different one here essentially everything in red was removed and everything in green was added it's super simple and if you've ever used github desktop or even looked at github you've more than likely seen this and understand what this means on top of this if you'd like you can edit the right hand side here though i wouldn't recommend editing anything unless you really need to try and fix something while you can type on the left hand side here i wouldn't recommend doing so just use it for viewing and the right-hand side for editing so if we have a look at the unmerged changes over here then we have all of these options here compare current and incoming which will open up things like this or we can check current master which as you can see is this change over here hey it seems like this now has code highlighting anyways and if we try the other one right click compare incoming you'll see that these changes here are of course the upper half up here so that's exactly what these are and we can pick what we want to keep here you can right click and choose keep a current master which is this one over here you should compare to see what happens or we can choose take incoming which if we compare incoming will take these changes on the right hand side here that's of course if you want to go gung-ho and just pick one of the two options but if you'd like to be a bit better with this you can right-click and choose merge to get another window open this is the most important part of the video so at the very top left we have different buttons these two buttons let you go between different differences which will also take you between files these buttons right below it will take you between different conflicting issues you can also see in small text incoming current and this is the result down here this block that's all red is what's different between all of these so you can either choose the left by clicking the tick box or we can choose the right by clicking this tick box and it essentially lets us pick one of these two options here i'll choose this one we can also choose both of them and it'll simply put one on top of the other depending on which order we pick it we can choose one or the other simply turning it on and off we'll change the order you can also edit the result down here to say whatever you want and whatever you type in will of course be included when you merge everything but i'll simply hit ctrl z to undo my changes and we'll go back if you're comfortable with your changes at the very top simply click accept merge and congratulations we've now merged a file it's gone from unstaged to staged changes and we can open it up by double clicking on it to see the differences between them awesome if we simply double click on it you'll see what's coming from the outside and what was here before we've now picked one of the two changes to keep and it's able to be merged so because there's nothing else in conflicts we can head up to the enter message up here and we can enter a message about this commit from here you can type in a message commit staged and we can push it up as simple as that on top of this before i push this i'll head back to the github page over here and simply left clicking once on whatever branch i'd like to look at we can right click specific commits and click cherry pick assuming we haven't already started a merge this will bring up this merge window once more though only with the changes from the one commit that we're selecting here and we can bring in commits of one at a time if you'd like but for me i'm happy with this over here so i'll simply enter a message saying conflicts fixed i'll commit staged and you can see fire out going zero and coming i'll click the up arrow with a line below it to push it and just like that successfully pushed origin master so now that we're back on github on the master branch i'll head to my commits and you can see that all of the changes from my other branch are over here prepare for merge added get games platform blah blah blah if i change to my other branch over here game stats you can see prepare for merge added get games blah blah blah that's great everything is fixed and we've now successfully merged everything we can click create a pull request at the very top but of course this says we're merging master with master that's simply because i've already pushed the changes and everything is equal though github does get a little bit confused sometimes you can see my master over here is fine but if i head across to my other branch it says eight commits behind don't worry about this a master branch has both of these merged if you previously had a pull request open for it you'll see pull requests successfully merged and closed and we'll have the option to delete the branch here if we so wish that is if you had a pull request open already i'll delete the branch and that's about it that's as simple as merging gets on github using visual studio 2022 i've shown you both the vanilla way of using github and the visual studio way of using visual studio and these different merging windows here that makes life a lot easier there probably is also a way of doing it through github desktop though maybe i'll feature that in an upcoming video at some stage i'll close out of these get compares i won't save any changes and i'll continue with my code as per usual that's about it for this quick video thank you for watching mine is being technobaby troubleshoot and i'll see you all next time ciao
Info
Channel: TroubleChute
Views: 48,881
Rating: undefined out of 5
Keywords: visual studio, merge conflict, merge conflicts, git merge conflicts, visual studio code, git merge conflict, git merge conflict visual studio, visual studio 2022, how to resolve merge conflicts, handle merge conflicts, git merge conflict tutorial, resolving merge conflicts in git, visual studio basics, visual studio c++, visual studio app, visual studio git, visual studio code python, cherry picking in visual studio, visual studio tutorial
Id: ziQlAo8H5w8
Channel Id: undefined
Length: 9min 21sec (561 seconds)
Published: Sun Jul 10 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.