Open Source Comes to Campus/Curriculum/Git/Students: Difference between revisions

imported>Shauna
No edit summary
imported>Shauna
Line 134:
Your instructor should have showed you what she sees when you submit a pull request. Probably you saw a message from Github saying that the pull request could be "merged automatically". That means that you managed to avoid changing a part of the project that someone else also changed. Yay! That's how we designed this activity. But what happens if you ''do'' change the same part of a project as someone else? It generates what we call a "merge conflict".
 
(A brief thought experiment to explain merge conflicts: let's say there's a repository with a single file that says, '''Hello [celestial object]!''' If you change that to '''Hello world!''' and submit a pull request, you're creating a diff which says: ''change "[celestial object]" to "world"''. If someone else copied the repository at the same time as you and changed the same line, they might create a diff which says ''change "[celestial object]" to "galaxy"''. If you make your changes to the repository first, it now says '''Hello world!''', so when the other person says '''change "[celestial object]" to "galaxy"''' the repository does not see [celestial object] and says, "There's a conflict here.")
Let's say you and a friend both got up-to-date copies of the repository, at the same time. You both decide to edit the page's title, which currently says, 'Practicing Git at Princetown'. You both decide to fix the spelling of Princeton. You're really excited, though, so you change it to 'Practicing Git at Princeton!' Your friend, meanwhile, is confused. She changes it to 'Practicing Git at Princeton????'
 
To induce a merge conflict in this activity, go to the main github repository and find a change that has been made since the last time you copied the repository (this"git mayclone" wellgets bea whencopy, youas diddoes "git clonefetch" and "git pull"). Make a change, locally, to the same line. Then type:
When your friend submits her change as a pull request, it tells git to change 'Practicing Git at Princetown' to 'Practicing Git at Princeton????'. Git checks and sees that its current version of the file does say 'Practicing Git at Princetown' at that line, so it goes ahead and makes the change. But when you submit your change as a pull request, you're telling git to change 'Practicing Git at Princetown' to 'Practicing Git at Princeton!' But it no longer says 'Practicing Git at Princetown' - it says 'Practicing Git at Princeton????'. Git doesn't know what to do! So it turns to you for help.
 
To induce a merge conflict in this activity, go to the main github repository and find a change that has been made since the last time you copied the repository (this may well be when you did "git clone"). Make a change, locally, to the same line. Then type:
 
git fetch [url of main project]
Anonymous user