Up and Running with Git Transcripts
Chapter: Teamwork: Merging
Lecture: Yikes! Merge conflict, now what?

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's push our luck. Let's make some changes that are right at the heart of what's going on. We did a code review and they said we don't want to
0:09 just import data, import jokes from data. In fact we want to use data as a name space to make it super clear where these jokes are coming from.
0:19 That's fine. We can do that. So we'll say you know what import data which is cool. And then down here we're just going to say instead of this,
0:27 we will say data.jokes. Let's just be real good citizens and make sure this runs again and press F5.
0:37 Open it up sure enough we can still get a good joke about the bank. Seems like it's working so we're ready to commit.
0:45 Let's go over here and push our changes in stage it this is gonna be something to the effect of moved to data,
0:54 name space. That's cool. Gonna check that and sync those changes. Great. Meanwhile over on the Mac we've decided we need logging,
1:10 logging please. So we're gonna come down here, we're going to print out a statement that says starting to you know, beginning to tell a joke like that.
1:25 And then we're going to print out the joke we are telling is and let's do a little F string thing so we can format the string and PyCharm is an
1:36 awesome feature. If you hit this and you type something that will auto complete. It will put the F back there.
1:43 That's pretty dope. Well let's just run that. That seems good and if we look where it's running.
1:53 Look at this beginning to tell a joke the joke we were telling his relationship status
1:57 Let's do another one. This is how do you get the code beginning to tell a joke down here? How do you get the code from the bank vault
2:06 Awesome. Looks like our logging works. Let's go ahead and stop this and we're going to commit it. So we'll go do this now.
2:17 It's a logging. Fantastic. We're going to try to do I'll just two steps Let's do a commit wait that's local.
2:28 And then remember the Windows developers already pushed their changes so we're going to try this and it's going to go probably go bang.
2:37 Perfect. You don't normally want to crash. But this time I did so it says, look, you both modify this file and as we saw it already tries to do
2:46 the merge. If you've modified one part that seems unrelated to another, it'll give you a good shot at just doing that automatically.
2:53 But if it's too close, if it literally is basically either the same line or the same block of code, git will say no no no no no no no
3:02 We're not doing this, you have to decide what happens now because I can't fix this. So what I can do is I can either say,
3:09 you know what I'm always right except mine. I just want to throw their changes away and be careful.
3:14 This will throw them away. they will be stored in history of source control but they'll be gone or you can say what I did doesn't really matter.
3:22 Let's just take what they did. I know that they're feature is important. I'll just re add mine or it's not important or more likely you want to try
3:31 to merge those changes so we'll hit merge and check this out. We get this really nice merge tool here, but then shows us make it a little bigger.
3:41 It shows us your version. I said begging, begin now whatever, we'll fix that in a minute. We're begging to tell a joke apparently,
3:50 which is fine. So we have this change that we made down here, right? And they've made this change that's like that.
3:59 So let's see if we can get these all to go together. It might be a little bit too much, we have to might have to type it.
4:06 But what we can do is at the top we can say look this, I've made no changes here, this one,
4:10 this is all of them so I can press this button and it accepts that and I do absolutely need that line to have data.jokes on it.
4:19 So I'm gonna try to do this and then I'm going to try to accept that but it's probably going to wipe away that section.
4:26 Let's see. Be real careful here, boom now it's said we took both changes and kind of jammed them together So now the final bit, I'm gonna have to go,
4:37 you know what? That's why it could do it automatically. So I'm gonna have to put that back together. I do notice though that we get PyCharm's,
4:46 code highlighting and code checking. So if we have like data's, it'll say we don't know what data is,
4:52 but like this, this lit up before when this was gone, that was great out at the top and so on.
4:58 And so now you can sort of see it's helping us put it together in a pretty rich way. Okay, so now we can say apply before I do,
5:06 let's bump over to source tree, open this thing up and notice it's in this merge warning problem here as well,
5:15 but we can come over to the file status and it says problem problem, we could go over and say resolve conflicts using an external tool,
5:25 mind there's restart, just say it's fine, whatever, it's fine, whatever however it happens to be and so on. I'm not going to do this in two places.
5:34 That's insane. But I just wanted to show you, it also shows up over here now we're going to apply this,
5:40 this will tell git the merge is good and it will also save this file, our push was rejected because we tried to push it up and it realized it needed
5:51 to do a pull first. It tried to merge it and it failed tried to auto merge and that failed. So I just said stop, stop, stop, stop you fix it,
6:00 you test it again and when you're happy then you can push those changes in,
6:04 we can see the commits that we received and we can actually see the changes done by that person, right? They did this which is all super cool.
6:14 I think we fixed it though. Let's go and run it again. Just make sure it still works sure enough. It does. So I think we're good,
6:21 let's stop over to commit. PyCharm is already remember we said now with logging it's already locally committed that but I don't think it's pushed it.
6:31 Let's check Indeed it hasn't. So we tried to do this, changing this change here which added our logging still annoyingly says begging,
6:40 I'll fix that in a minute and it says you have to do this merge which resolved the conflicts in app.py Okay, let's push our changes. Good to go.
6:53 We've made changes that were not able to be automatically fixed but no problem, the tools decided that they couldn't quite make those changes for us.
7:03 So it did, its best it could. It brought up some nice tools and showed us like here are the problems which do
7:10 you want to choose from them which do you want to choose from yours also really quickly just so we don't go crazy,
7:18 let's fix beginning, commit and push and off we go good deal That was close We had emerged conflict. We both wrote exactly in the same part of the
7:33 code, but we were able to see how to fix it and use the tools to really support us along the way.


Talk Python's Mastodon Michael Kennedy's Mastodon