Resolving Conflicts5:07 with Carling Kirk
Conflicts are eventually going to happen when we work on a team. In this video, we resolve a conflict with our project and learn useful tips on merging.
So say we're happily coding along and 0:00 we merge some changes down from master to our branch, but someone has made in 0:02 a change in a file you've also made changes in and bam, you've got a conflict. 0:05 Don't worry, it happens all the time. 0:10 I've made a change in master that conflicts with one of our changes. 0:12 Let's go to branches, merge from and choose master. 0:16 I'm gonna leave the commit box checked to show you what happens. 0:23 Merge. 0:27 Now it's letting us know that we've got a conflicting change, and 0:29 we have to resolve it before we commit. 0:31 We can review the conflict using a diff. 0:34 Click on compare files, and here's our two versions. 0:37 The one on the left is the master branch version, it says so 0:41 right here in the header, and the right one is our branch. 0:44 We've got a change in both versions of the file on the same line. 0:48 So which one is the right one? 0:52 If you are not sure it is best to communicate with the person that made 0:54 the change and make sure you agree on the final outcome. 0:56 At this point, we've got three options. 1:00 We can let the master version overwrite our change by clicking take source here. 1:02 We can let our branch version win by clicking keep target here. 1:07 Or we can use the merge tool to resolve the conflict by hand. 1:12 Let's use the merge tool by clicking on merge. 1:16 Once again, the master is on the left and our branch is on the right. 1:18 The lines of code in question are now highlighted and 1:22 have check boxes beside each one. 1:25 The final result will retain any of the lines we check. 1:28 We can check both and 1:31 you can see in the bottom, both of the changes are in the result. 1:32 But since we're not sure what change should go in, 1:36 how do we figure out who made the change that conflicts with ours? 1:38 Well, we could look at the history of the commits, but there's a neat feature we 1:42 could use that lets us view when each line of a file was committed and by whom. 1:46 In GIT, this feature is called blame, but 1:50 Visual Studio tries to be a little more polite and calls it annotate. 1:52 Let's change over to the master branch. 1:56 In order to do that, we'll need to abort our merge. 1:58 Don't worry, we can come back and attempt the merge again. 2:01 We'll switch over to the master branch with this handy little menu down here. 2:04 Home, make sure our solution's open. 2:17 Right-click on the program file and choose annotate. 2:20 On the left, you can see commit ID's, 2:26 the username of the contributor that made the change and the date of the commit. 2:28 Now we can reach out to that person who made the change and 2:34 make sure we're on the same page. 2:37 Then we can use the merge tool again. 2:39 Change to our branch and merge from master and there's a conflict again. 2:47 We'll click merge and we're back in the merge tool. 2:56 So let's say our team contributor says that our change is the better one. 3:00 So we'll check the box next to our line of code. 3:04 We can also edit directly into this pane 3:07 which is especially helpful in cases where you want to keep both versions but 3:10 you need to make an edit so that they fit well together. 3:13 These arrows at the top can help you navigate changes or just conflicts. 3:16 Say we have a really big file with lots of changes, 3:21 we can use these middle arrows to jump from one conflict to the next. 3:23 These outer arrows will navigate through all the differences if you need to 3:29 review them as well. 3:32 We are satisfied with these changes so 3:34 we'll click accept merge, now it says, there are no remaining conflicts. 3:35 Now if for some reason we need to undo our work, we can click undo merge here, but 3:40 we're satisfied with everything, so let's commit the merge. 3:45 And for a message, merge from master branch. 3:49 There's also a shortcut here on the commit button where you can commit and 3:54 sync with the same click. 3:58 And we'll sync. 4:01 No more conflict. 4:04 There's something else I want to tell you. 4:07 You don't have to use the GIT, in git hub integration with visual studio. 4:09 You've got some options. 4:12 There's git hub desktop and get command line tools. 4:14 And we can teach you all about those at treehouse too. 4:17 Check the teacher's notes for links. 4:20 Sometimes you might run into issues or 4:22 advanced scenarios that require using the command line. 4:24 So the command line tools can be good to have on hand. 4:27 If you get stuck, don't worry. 4:30 There are lots of people who use GIT and 4:32 they have probably run into the same issue and asked for help. 4:34 Github and Git have lots of useful documentation, and sites like 4:38 stackoverflow an d the treehouse community are great resources for finding help too. 4:41 So that's all there is to it. 4:47 Now you can use Git hub right in Visual Studio to share your code and collaborate. 4:48 I've learned a lot by working with other people, 4:53 and getting my hands into new projects. 4:55 UpForGrabs.net and 4:57 the .NET repository on Git Hub have a list of open-source .NET projects. 4:58 I've included links to those sites in the teacher's notes. 5:03 You should go join one. 5:06
You need to sign up for Treehouse in order to download course files.Sign up