Anonymous user
Open Source Comes to Campus/Curriculum/Git/Students: Difference between revisions
Open Source Comes to Campus/Curriculum/Git/Students (view source)
Revision as of 19:16, 23 November 2013
, 10 years agono edit summary
imported>Shauna |
imported>Shauna No edit summary |
||
Line 136:
(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 flags that there's a conflict.)
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 ("git clone" gets a copy, as does "git fetch" and "git pull"). Make a change, locally, to the same line.
There's two ways that this merge conflict can be solved. You could push your changes to your remote copy, then submit a pull request to your instructor. When viewing the pull request, they would be warned that changes could not be merged automatically:
[[File:Merge1.png]]
And would follow the instructions github helpfully provides to merge the changes:
[[File:Merge2.png]]
This involves some concepts like branching, which we haven't gotten to yet.
Alternatively, you could fix the merge conflict yourself. To do this, you'd need to get an up-to-date copy of the remote repository. To do this, type:
git fetch [url of main project]
Line 146 ⟶ 158:
git merge
error message
There are a number of tools you can use to help visualize merge conflicts. For simple conflicts, though, I like to use a basic editor, such as nano, vim, emacs, or whatever you're most comfortable with. In basic text view, a merge conflict looks like this:
[[File:merge3.png]]
To resolve the conflict, scroll through the document until you find sections with these markings. The " " line separates the two options that are in conflict. Choose which one you want to keep by deleting the other. Then delete all of the markings. Do this for each conflict and then save and exit the file.
|