<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ysun6</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ysun6"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Ysun6"/>
	<updated>2026-08-16T17:54:58Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81216</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81216"/>
		<updated>2013-10-30T19:45:54Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Project description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt;. Expertiza also supports team projects and any document type of submission is acceptable&amp;lt;ref&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza wiki]&amp;lt;/ref&amp;gt;. Expertiza has been deployed for years to help professors and students engaging in the learning process. Expertiza is an open source project, for each year, students in the course of CSC517-Object Oriented Programmning of North Carolina State University will contributes to this project along with teaching assistant and professor.&lt;br /&gt;
&lt;br /&gt;
For this year, we are responsible for refactoring plagiarism_check.rb and sentence_state.rb of the Expertiza project. Expertiza is built using Ruby on Rails with [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller MVC design pattern]. plagiarism_check.rb and sentence_state.rb are parts of the automated_metareview functionality inside models. The responsibility of sentence_state.rb is to determine the state of each clause of a sentence, and the responsibility of plagiarism_check.rb is to determine whether the reviews are just copied from other sources.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
===Classes===&lt;br /&gt;
Classes we are going to refactor are plagiarism_check.rb (155 lines).&lt;br /&gt;
sentence_state.rb (293 lines)&lt;br /&gt;
&lt;br /&gt;
===What it Does===&lt;br /&gt;
The two class files performs functions which are needed in NLP analysis of reviews in the research. plagiarism_check.rb and sentence_state.rb are used to check whether the reviews are copied from other places. To check whether plagiarism happens is important because the reviewers are tends to game with the automated review system to get a high score instead of writing a high quality review. The classes compare the review text with text from Internet to determine whether and copy-paste happens&amp;lt;ref&amp;gt; [http://www.lib.ncsu.edu/resolver/1840.16/8813 Automated Assessment of Reviews]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Our Job===&lt;br /&gt;
The code has many code smells. First, the methods are long and complex, and the codes are not structured well, which makes it not readable and understandable. Second, extremely long if-else branch and loop exists everywhere. Third, the responsibility of sentence_state.rb is heavy, some functions of sentence_state should be given to others. Finally, there are some duplicate codes.&lt;br /&gt;
&lt;br /&gt;
Our job is to refactor the two classes and make it more O-O style and have a clear structure. To eliminate the code smells, we need removing the duplicate code, reconstruct long if-else branch and loop, generating new methods and classes to encapsulate functionality of other complex methods, clear the responsibility of classes and methods. After refactoring, we also need to test the two classes throughoutly without error.&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb sentence_state.rb]&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
The first step in refactoring is to get the tests to pass. This required some debugging to find that some constants were defined in two different files, [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/constants.rb constants.rb] and [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/negations.rb negations.rb], and the NEGATIVE_DESCRIPTORS definition was incomplete in negations.rb file. After updating this, all 18 original tests in sentence_state_test.rb passed.&lt;br /&gt;
&lt;br /&gt;
The first place to refactor was the longest method in SentenceState, the method sentence_state(str_with_pos_tags). There were three for loops, each with deeply nested if-else statements inside of them. To make this method more readable, I extracted three for or if-else statements into their own method to clean up the code. This changed the code from 164 lines of if-else and for statements to:&lt;br /&gt;
 def sentence_state(str_with_pos_tags)&lt;br /&gt;
    state = POSITIVE&lt;br /&gt;
    prev_negative_word =&amp;quot;&amp;quot;  &lt;br /&gt;
    tagged_tokens, tokens = parse_sentence_tokens(str_with_pos_tags)&lt;br /&gt;
    for j  in (0..tokens.length-1)&lt;br /&gt;
      current_token_type = get_token_type(tokens[j..tokens.length-1)&lt;br /&gt;
      state = next_state(state, current_token_type, prev_negative_word, tagged_tokens)&lt;br /&gt;
      if(tokens[j].casecmp(&amp;quot;NO&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NEVER&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NONE&amp;quot;) == 0)&lt;br /&gt;
        prev_negative_word = tokens[j]&lt;br /&gt;
      end&lt;br /&gt;
    end #end of for loop&lt;br /&gt;
    if(state == NEGATIVE_DESCRIPTOR or state == NEGATIVE_WORD or state == NEGATIVE_PHRASE)&lt;br /&gt;
      state = NEGATED&lt;br /&gt;
    end&lt;br /&gt;
    return state&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This was much easier to read and it revealed that the class SentenceState had too many responsibilities. The class now had two methods which parse the sentence: break_at_coordinating_conjunctions and parse_sentence_tokens. However, parsing a sentence into its sentence clauses and individual tokens (words) could potentially be useful elsewhere, so it is better to decouple this responsibility from SentenceState into a new class. So these two methods were refactored into a TaggedSentence class with the methods break_at_coordinating_conjunctions and parse_sentence_tokens. Now when SentenceState is called, it makes a new TaggedSentence and then calls break_at_coordinating_conjunctions which returns the sentence clauses as arrays of sentence tokens. See the new TaggedSentence class here: [https://github.com/shanfangshuiyuan/expertiza/blob/master/app/models/automated_metareview/tagged_sentence.rb tagged_sentence.rb]&lt;br /&gt;
&lt;br /&gt;
Once this change was done, the next step was to refactor each of the three new methods that were created earlier to clean up the sentence_state method, because these still contain deeply nested if statements. The first method created was parse_sentence_tokens(str_with_pos_tags). Originally this method was as shown below:&lt;br /&gt;
 def parse_sentence_tokens(str_with_pos_tags)&lt;br /&gt;
    tokens = Array.new&lt;br /&gt;
    tagged_tokens = Array.new&lt;br /&gt;
    i = 0&lt;br /&gt;
    interim_noun_verb  = false #0 indicates no interim nouns or verbs&lt;br /&gt;
        &lt;br /&gt;
    #fetching all the tokens&lt;br /&gt;
    for k in (0..st.length-1)&lt;br /&gt;
      ps = st[k]&lt;br /&gt;
      #setting the tagged string&lt;br /&gt;
      tagged_tokens[i] = ps&lt;br /&gt;
      if(ps.include?(&amp;quot;/&amp;quot;))&lt;br /&gt;
        ps = ps[0..ps.index(&amp;quot;/&amp;quot;)-1] &lt;br /&gt;
      end&lt;br /&gt;
      #removing punctuations &lt;br /&gt;
      if(ps.include?(&amp;quot;.&amp;quot;))&lt;br /&gt;
        tokens[i] = ps[0..ps.index(&amp;quot;.&amp;quot;)-1]&lt;br /&gt;
      elsif(ps.include?(&amp;quot;,&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;,&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      elsif(ps.include?(&amp;quot;!&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;!&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      elsif(ps.include?(&amp;quot;;&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      else&lt;br /&gt;
        tokens[i] = ps&lt;br /&gt;
        i+=1&lt;br /&gt;
      end     &lt;br /&gt;
    return tagged_tokens, tokens&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
**Future note. The TaggedSentence class could be refactored by allowing a sentence to be either broken into sentence clauses or into sentence clause arrays of parsed sentence tokens.&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Main Responsibility ===&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism.&lt;br /&gt;
&lt;br /&gt;
===Design Ideas===&lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are: compare_reviews_with_submissions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_questions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_responses, and&lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    &lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      &lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 &lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
 #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Please see code after refactoring in detail on this [https://github.com/shanfangshuiyuan/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb page].&lt;br /&gt;
&lt;br /&gt;
All the tests have been passed without failures since refactoring.&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
&lt;br /&gt;
Through refactoring we've made the code easier to understand with design patterns involved, which meets the requirements of this project. But from our perspective, there should be more work to do in order to improve the whole performance of the code, which includes:&lt;br /&gt;
&lt;br /&gt;
1. There are some bugs in the initial method compare_reviews_with_questions_responses and google_search_response, which can not be implemented so far. We hope that people who are responsible for this project can fix it and make the method do the expected function well.&lt;br /&gt;
&lt;br /&gt;
2. Based on 1, we can do more tests regarding plagiarism, which makes the code development better.&lt;br /&gt;
&lt;br /&gt;
3. Through running tests, we've found there are some errors within the method of text_preprocssing.rb file,  which may cause a conflict with the function of plagiarism-check. Bug-fixing is needed.&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Through refactoring we've made the code easier to understand with design patterns involved, which meets the requirements of this project. But from our perspective, there should be more work to do in order to improve the whole performance of the code, which includes:&lt;br /&gt;
&lt;br /&gt;
1. There are some bugs in the initial method compare_reviews_with_questions_responses and google_search_response, which can not be implemented so far. We hope that people who are responsible for this project can fix it and make the method do the expected function well.&lt;br /&gt;
&lt;br /&gt;
2. Based on 1, we can do more tests regarding plagiarism, which makes the code development better.&lt;br /&gt;
&lt;br /&gt;
3. Through running tests, we've found there are some errors within the method of text_preprocssing.rb file,  which may cause a conflict with the function of plagiarism-check. Bug-fixing is needed.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81211</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81211"/>
		<updated>2013-10-30T19:44:45Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Project description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt;. Expertiza also supports team projects and any document type of submission is acceptable&amp;lt;ref&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza wiki]&amp;lt;/ref&amp;gt;. Expertiza has been deployed for years to help professors and students engaging in the learning process. Expertiza is an open source project, for each year, students in the course of CSC517-Object Oriented Programmning of North Carolina State University will contributes to this project along with teaching assistant and professor.&lt;br /&gt;
&lt;br /&gt;
For this year, we are responsible for refactoring plagiarism_check.rb and sentence_state.rb of the Expertiza project. Expertiza is built using Ruby on Rails with [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller MVC design pattern]. plagiarism_check.rb and sentence_state.rb are parts of the automated_metareview functionality inside models. The responsibility of sentence_state.rb is to determine the state of each clause of a sentence, and the responsibility of plagiarism_check.rb is to determine whether the reviews are just copied from other sources.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
===Classes===&lt;br /&gt;
Classes we are going to refactor are plagiarism_check.rb (155 lines).&lt;br /&gt;
sentence_state.rb (293 lines)&lt;br /&gt;
&lt;br /&gt;
===What it Does===&lt;br /&gt;
The two class files performs functions which are needed in NLP analysis of reviews in the research. plagiarism_check.rb and sentence_state.rb are used to check whether the reviews are copied from other places. To check whether plagiarism happens is important because the reviewers are tends to game with the automated review system to get a high score instead of writing a high quality review. The classes compare the review text with text from Internet to determine whether and copy-paste happens.&lt;br /&gt;
&lt;br /&gt;
===Our Job===&lt;br /&gt;
The code has many code smells. First, the methods are long and complex, and the codes are not structured well, which makes it not readable and understandable. Second, extremely long if-else branch and loop exists everywhere. Third, the responsibility of sentence_state.rb is heavy, some functions of sentence_state should be given to others. Finally, there are some duplicate codes.&lt;br /&gt;
&lt;br /&gt;
Our job is to refactor the two classes and make it more O-O style and have a clear structure. To eliminate the code smells, we need removing the duplicate code, reconstruct long if-else branch and loop, generating new methods and classes to encapsulate functionality of other complex methods, clear the responsibility of classes and methods. After refactoring, we also need to test the two classes throughoutly without error.&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb sentence_state.rb]&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
The first step in refactoring is to get the tests to pass. This required some debugging to find that some constants were defined in two different files, [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/constants.rb constants.rb] and [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/negations.rb negations.rb], and the NEGATIVE_DESCRIPTORS definition was incomplete in negations.rb file. After updating this, all 18 original tests in sentence_state_test.rb passed.&lt;br /&gt;
&lt;br /&gt;
The first place to refactor was the longest method in SentenceState, the method sentence_state(str_with_pos_tags). There were three for loops, each with deeply nested if-else statements inside of them. To make this method more readable, I extracted three for or if-else statements into their own method to clean up the code. This changed the code from 164 lines of if-else and for statements to:&lt;br /&gt;
 def sentence_state(str_with_pos_tags)&lt;br /&gt;
    state = POSITIVE&lt;br /&gt;
    prev_negative_word =&amp;quot;&amp;quot;  &lt;br /&gt;
    tagged_tokens, tokens = parse_sentence_tokens(str_with_pos_tags)&lt;br /&gt;
    for j  in (0..tokens.length-1)&lt;br /&gt;
      current_token_type = get_token_type(tokens[j..tokens.length-1)&lt;br /&gt;
      state = next_state(state, current_token_type, prev_negative_word, tagged_tokens)&lt;br /&gt;
      if(tokens[j].casecmp(&amp;quot;NO&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NEVER&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NONE&amp;quot;) == 0)&lt;br /&gt;
        prev_negative_word = tokens[j]&lt;br /&gt;
      end&lt;br /&gt;
    end #end of for loop&lt;br /&gt;
    if(state == NEGATIVE_DESCRIPTOR or state == NEGATIVE_WORD or state == NEGATIVE_PHRASE)&lt;br /&gt;
      state = NEGATED&lt;br /&gt;
    end&lt;br /&gt;
    return state&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
This was much easier to read and it revealed that the class SentenceState had too many responsibilities. The class now had two methods which parse the sentence: break_at_coordinating_conjunctions and parse_sentence_tokens. However, parsing a sentence into its sentence clauses and individual tokens (words) could potentially be useful elsewhere, so it is better to decouple this responsibility from SentenceState into a new class. So these two methods were refactored into a TaggedSentence class with the methods break_at_coordinating_conjunctions and parse_sentence_tokens. Now when SentenceState is called, it makes a new TaggedSentence and then calls break_at_coordinating_conjunctions which returns the sentence clauses as arrays of sentence tokens. See the new TaggedSentence class here: [https://github.com/shanfangshuiyuan/expertiza/blob/master/app/models/automated_metareview/tagged_sentence.rb tagged_sentence.rb]&lt;br /&gt;
&lt;br /&gt;
Once this change was done, the next step was to refactor each of the three new methods that were created earlier to clean up the sentence_state method, because these still contain deeply nested if statements. The first method created was parse_sentence_tokens(str_with_pos_tags). Originally this method was as shown below:&lt;br /&gt;
 def parse_sentence_tokens(str_with_pos_tags)&lt;br /&gt;
    tokens = Array.new&lt;br /&gt;
    tagged_tokens = Array.new&lt;br /&gt;
    i = 0&lt;br /&gt;
    interim_noun_verb  = false #0 indicates no interim nouns or verbs&lt;br /&gt;
        &lt;br /&gt;
    #fetching all the tokens&lt;br /&gt;
    for k in (0..st.length-1)&lt;br /&gt;
      ps = st[k]&lt;br /&gt;
      #setting the tagged string&lt;br /&gt;
      tagged_tokens[i] = ps&lt;br /&gt;
      if(ps.include?(&amp;quot;/&amp;quot;))&lt;br /&gt;
        ps = ps[0..ps.index(&amp;quot;/&amp;quot;)-1] &lt;br /&gt;
      end&lt;br /&gt;
      #removing punctuations &lt;br /&gt;
      if(ps.include?(&amp;quot;.&amp;quot;))&lt;br /&gt;
        tokens[i] = ps[0..ps.index(&amp;quot;.&amp;quot;)-1]&lt;br /&gt;
      elsif(ps.include?(&amp;quot;,&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;,&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      elsif(ps.include?(&amp;quot;!&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;!&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      elsif(ps.include?(&amp;quot;;&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      else&lt;br /&gt;
        tokens[i] = ps&lt;br /&gt;
        i+=1&lt;br /&gt;
      end     &lt;br /&gt;
    return tagged_tokens, tokens&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
**Future note. The TaggedSentence class could be refactored by allowing a sentence to be either broken into sentence clauses or into sentence clause arrays of parsed sentence tokens.&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Main Responsibility ===&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism.&lt;br /&gt;
&lt;br /&gt;
===Design Ideas===&lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are: compare_reviews_with_submissions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_questions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_responses, and&lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    &lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      &lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 &lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
 #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Please see code after refactoring in detail on this [https://github.com/shanfangshuiyuan/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb page].&lt;br /&gt;
&lt;br /&gt;
All the tests have been passed without failures since refactoring.&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81171</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81171"/>
		<updated>2013-10-30T19:24:26Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Project description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt;. Expertiza also supports team projects and any document type of submission is acceptable&amp;lt;ref&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza wiki]&amp;lt;/ref&amp;gt;. Expertiza has been deployed for years to help professors and students engaging in the learning process. Expertiza is an open source project, for each year, students in the course of CSC517-Object Oriented Programmning of North Carolina State University will contributes to this project along with teaching assistant and professor.&lt;br /&gt;
&lt;br /&gt;
For this year, we are responsible for refactoring plagiarism_check.rb and sentence_state.rb of the Expertiza project. Expertiza is built using Ruby on Rails with [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller MVC design pattern]. plagiarism_check.rb and sentence_state.rb are parts of the automated_metareview functionality inside models. The responsibility of sentence_state.rb is to determine the state of each clause of a sentence, and the responsibility of plagiarism_check.rb is to determine whether the reviews are just copied from other sources.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
===Classes===&lt;br /&gt;
Classes we are going to refactor are plagiarism_check.rb (155 lines).&lt;br /&gt;
sentence_state.rb (293 lines)&lt;br /&gt;
&lt;br /&gt;
===What it Does===&lt;br /&gt;
The two class files performs functions which are needed in NLP analysis of reviews in the research.&lt;br /&gt;
&lt;br /&gt;
===Our Job===&lt;br /&gt;
The code has many code smells. First, the methods are long and complex, and the codes are not structured well, which makes it not readable and understandable. Second, extremely long if-else branch and loop exists everywhere. Third, the responsibility of sentence_state.rb is heavy, some functions of sentence_state should be given to others. Finally, there are some duplicate codes.&lt;br /&gt;
&lt;br /&gt;
Our job is to refactor the two classes and make it more O-O style and have a clear structure. To eliminate the code smells, we need removing the duplicate code, reconstruct long if-else branch and loop, generating new methods and classes to encapsulate functionality of other complex methods, clear the responsibility of classes and methods. After refactoring, we also need to test the two classes throughoutly without error.&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
The first step in refactoring is to get the tests to pass. This required some debugging to find that some constants were defined in two different files, and one of the definitions was incomplete. After updating this, all 18 original tests in sentence_state_test.rb passed.&lt;br /&gt;
&lt;br /&gt;
The first place to refactor was the longest method in SentenceState, the method sentence_state(str_with_pos_tags). There were three for loops, each with deeply nested if-else statements inside of them. To make this method more readable, I extracted three for or if-else statements into their own method to clean up the code. This changed the code from 164 lines of if-else and for statements to:&lt;br /&gt;
 def sentence_state(str_with_pos_tags)&lt;br /&gt;
    state = POSITIVE&lt;br /&gt;
        &lt;br /&gt;
    tagged_tokens, tokens = parse_sentence_tokens(str_with_pos_tags)&lt;br /&gt;
    &lt;br /&gt;
    #iterating through the tokens to determine state&lt;br /&gt;
    prev_negative_word =&amp;quot;&amp;quot;&lt;br /&gt;
    for j  in (0..tokens.length-1)&lt;br /&gt;
      #checking type of the word&lt;br /&gt;
      #checking for negated words&lt;br /&gt;
      current_token_type = get_token_type(tokens[j..tokens.length-1)&lt;br /&gt;
      &lt;br /&gt;
      #getting next_state of the sentence clause      &lt;br /&gt;
      state = next_state(state, current_token_type, prev_negative_word, tagged_tokens)&lt;br /&gt;
      &lt;br /&gt;
      #setting the prevNegativeWord      &lt;br /&gt;
      if(tokens[j].casecmp(&amp;quot;NO&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NEVER&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NONE&amp;quot;) == 0)&lt;br /&gt;
        prev_negative_word = tokens[j]&lt;br /&gt;
      end  &lt;br /&gt;
          &lt;br /&gt;
    end #end of for loop&lt;br /&gt;
    &lt;br /&gt;
    if(state == NEGATIVE_DESCRIPTOR or state == NEGATIVE_WORD or state == NEGATIVE_PHRASE)&lt;br /&gt;
      state = NEGATED&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    return state&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Main Responsibility ===&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism.&lt;br /&gt;
&lt;br /&gt;
===Design Ideas===&lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are: compare_reviews_with_submissions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_questions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_responses, and&lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    &lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      &lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 &lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
 #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Please see code after refactoring in detail on this [https://github.com/shanfangshuiyuan/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb page].&lt;br /&gt;
&lt;br /&gt;
All the tests have been passed without failures since refactoring.&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81170</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81170"/>
		<updated>2013-10-30T19:23:25Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Project description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt;. Expertiza also supports team projects and any document type of submission is acceptable&amp;lt;ref&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza wiki]&amp;lt;/ref&amp;gt;. Expertiza has been deployed for years to help professors and students engaging in the learning process. Expertiza is an open source project, for each year, students in the course of CSC517-Object Oriented Programmning of North Carolina State University will contributes to this project along with teaching assistant and professor.&lt;br /&gt;
&lt;br /&gt;
For this year, we are responsible for refactoring plagiarism_check.rb and sentence_state.rb of the Expertiza project. Expertiza is built using Ruby on Rails with [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller MVC design pattern]. plagiarism_check.rb and sentence_state.rb are parts of the automated_metareview functionality inside models. The responsibility of sentence_state.rb is to determine the state of each clause of a sentence, and the responsibility of plagiarism_check.rb is to determine whether the reviews are just copied from other sources.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
===Classes===&lt;br /&gt;
Classes we are going to refactor are plagiarism_check.rb (155 lines).&lt;br /&gt;
sentence_state.rb (293 lines)&lt;br /&gt;
&lt;br /&gt;
===What it Does===&lt;br /&gt;
The two class files performs functions which are needed in NLP analysis of reviews in the research.&lt;br /&gt;
&lt;br /&gt;
===Our Job===&lt;br /&gt;
The code has many code smells. First, the methods are long and complex, and the codes are not structured well, which makes it not readable and understandable. Second, extremely long if-else branch and loop exists everywhere. Third, the responsibility of sentence_state.rb is heavy, some functions of sentence_state should be given to others. Finally, there are some duplicate codes.&lt;br /&gt;
&lt;br /&gt;
Our job is to refactor the two classes and make it more O-O style and have a clear structure. To eliminate the code smells, we need removing the duplicate code, reconstruct long if-else branch and loop, generating new methods and classes to encapsulate functionality of other complex methods, clear the responsibility of classes and methods. After refactoring, we need to test the two classes throughoutly without error.&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
The first step in refactoring is to get the tests to pass. This required some debugging to find that some constants were defined in two different files, and one of the definitions was incomplete. After updating this, all 18 original tests in sentence_state_test.rb passed.&lt;br /&gt;
&lt;br /&gt;
The first place to refactor was the longest method in SentenceState, the method sentence_state(str_with_pos_tags). There were three for loops, each with deeply nested if-else statements inside of them. To make this method more readable, I extracted three for or if-else statements into their own method to clean up the code. This changed the code from 164 lines of if-else and for statements to:&lt;br /&gt;
 def sentence_state(str_with_pos_tags)&lt;br /&gt;
    state = POSITIVE&lt;br /&gt;
        &lt;br /&gt;
    tagged_tokens, tokens = parse_sentence_tokens(str_with_pos_tags)&lt;br /&gt;
    &lt;br /&gt;
    #iterating through the tokens to determine state&lt;br /&gt;
    prev_negative_word =&amp;quot;&amp;quot;&lt;br /&gt;
    for j  in (0..tokens.length-1)&lt;br /&gt;
      #checking type of the word&lt;br /&gt;
      #checking for negated words&lt;br /&gt;
      current_token_type = get_token_type(tokens[j..tokens.length-1)&lt;br /&gt;
      &lt;br /&gt;
      #getting next_state of the sentence clause      &lt;br /&gt;
      state = next_state(state, current_token_type, prev_negative_word, tagged_tokens)&lt;br /&gt;
      &lt;br /&gt;
      #setting the prevNegativeWord      &lt;br /&gt;
      if(tokens[j].casecmp(&amp;quot;NO&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NEVER&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NONE&amp;quot;) == 0)&lt;br /&gt;
        prev_negative_word = tokens[j]&lt;br /&gt;
      end  &lt;br /&gt;
          &lt;br /&gt;
    end #end of for loop&lt;br /&gt;
    &lt;br /&gt;
    if(state == NEGATIVE_DESCRIPTOR or state == NEGATIVE_WORD or state == NEGATIVE_PHRASE)&lt;br /&gt;
      state = NEGATED&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    return state&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Main Responsibility ===&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism.&lt;br /&gt;
&lt;br /&gt;
===Design Ideas===&lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are: compare_reviews_with_submissions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_questions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_responses, and&lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    &lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      &lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 &lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
 #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Please see code after refactoring in detail on this [https://github.com/shanfangshuiyuan/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb page].&lt;br /&gt;
&lt;br /&gt;
All the tests have been passed without failures since refactoring.&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81164</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81164"/>
		<updated>2013-10-30T19:21:04Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Project description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt;. Expertiza also supports team projects and any document type of submission is acceptable&amp;lt;ref&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza wiki]&amp;lt;/ref&amp;gt;. Expertiza has been deployed for years to help professors and students engaging in the learning process. Expertiza is an open source project, for each year, students in the course of CSC517-Object Oriented Programmning of North Carolina State University will contributes to this project along with teaching assistant and professor.&lt;br /&gt;
&lt;br /&gt;
For this year, we are responsible for refactoring plagiarism_check.rb and sentence_state.rb of the Expertiza project. Expertiza is built using Ruby on Rails with [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller MVC design pattern]. plagiarism_check.rb and sentence_state.rb are parts of the automated_metareview functionality inside models. The responsibility of sentence_state.rb is to determine the state of each clause of a sentence, and the responsibility of plagiarism_check.rb is to determine whether the reviews are just copied from other sources.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
===Classes===&lt;br /&gt;
Classes we are going to refactor are plagiarism_check.rb (155 lines).&lt;br /&gt;
sentence_state.rb (293 lines)&lt;br /&gt;
&lt;br /&gt;
===What it Does===&lt;br /&gt;
The two class files performs functions which are needed in NLP analysis of reviews in the research.&lt;br /&gt;
&lt;br /&gt;
===Our Job===&lt;br /&gt;
The code has many code smells. First, the methods are long and complex, and the codes are not structured well, which makes it not readable and understandable. Second, extremely long if-else branch and loop exists everywhere. Third, the responsibility of sentence_state.rb is heavy, some functions of sentence_state should be given to others. Finally, there are some duplicate codes.&lt;br /&gt;
&lt;br /&gt;
Our job is to refactor the two classes and make it more O-O style and have a clear structure. To eliminate the code smells, we need removing the duplicate code, reconstruct long if-else branch and loop, generating new methods and classes to encapsulate functionality of other complex methods, clear the responsibility of classes and methods.&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
The first step in refactoring is to get the tests to pass. This required some debugging to find that some constants were defined in two different files, and one of the definitions was incomplete. After updating this, all 18 original tests in sentence_state_test.rb passed.&lt;br /&gt;
&lt;br /&gt;
The first place to refactor was the longest method in SentenceState, the method sentence_state(str_with_pos_tags). There were three for loops, each with deeply nested if-else statements inside of them. To make this method more readable, I extracted three for or if-else statements into their own method to clean up the code. This changed the code from 164 lines of if-else and for statements to:&lt;br /&gt;
 def sentence_state(str_with_pos_tags)&lt;br /&gt;
    state = POSITIVE&lt;br /&gt;
        &lt;br /&gt;
    tagged_tokens, tokens = parse_sentence_tokens(str_with_pos_tags)&lt;br /&gt;
    &lt;br /&gt;
    #iterating through the tokens to determine state&lt;br /&gt;
    prev_negative_word =&amp;quot;&amp;quot;&lt;br /&gt;
    for j  in (0..tokens.length-1)&lt;br /&gt;
      #checking type of the word&lt;br /&gt;
      #checking for negated words&lt;br /&gt;
      current_token_type = get_token_type(tokens[j..tokens.length-1)&lt;br /&gt;
      &lt;br /&gt;
      #getting next_state of the sentence clause      &lt;br /&gt;
      state = next_state(state, current_token_type, prev_negative_word, tagged_tokens)&lt;br /&gt;
      &lt;br /&gt;
      #setting the prevNegativeWord      &lt;br /&gt;
      if(tokens[j].casecmp(&amp;quot;NO&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NEVER&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NONE&amp;quot;) == 0)&lt;br /&gt;
        prev_negative_word = tokens[j]&lt;br /&gt;
      end  &lt;br /&gt;
          &lt;br /&gt;
    end #end of for loop&lt;br /&gt;
    &lt;br /&gt;
    if(state == NEGATIVE_DESCRIPTOR or state == NEGATIVE_WORD or state == NEGATIVE_PHRASE)&lt;br /&gt;
      state = NEGATED&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    return state&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Main Responsibility ===&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism.&lt;br /&gt;
&lt;br /&gt;
===Design Ideas===&lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are: compare_reviews_with_submissions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_questions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_responses, and&lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    &lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      &lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 &lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
 #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Please see code after refactoring in detail on this [https://github.com/shanfangshuiyuan/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb page].&lt;br /&gt;
&lt;br /&gt;
All the tests have been passed without failures since refactoring.&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81162</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81162"/>
		<updated>2013-10-30T19:20:54Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Project description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt;. Expertiza also supports team projects and any document type of submission is acceptable&amp;lt;ref&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza wiki]&amp;lt;/ref&amp;gt;. Expertiza has been deployed for years to help professors and students engaging in the learning process. Expertiza is an open source project, for each year, students in the course of CSC517-Object Oriented Programmning of North Carolina State University will contributes to this project along with teaching assistant and professor.&lt;br /&gt;
&lt;br /&gt;
For this year, we are responsible for refactoring plagiarism_check.rb and sentence_state.rb of the Expertiza project. Expertiza is built using Ruby on Rails with [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller MVC design pattern]. plagiarism_check.rb and sentence_state.rb are parts of the automated_metareview functionality inside models. The responsibility of sentence_state.rb is to determine the state of each clause of a sentence, and the responsibility of plagiarism_check.rb is to determine whether the reviews are just copied from other sources.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
===Classes===&lt;br /&gt;
Classes we are going to refactor are plagiarism_check.rb (155 lines)&lt;br /&gt;
sentence_state.rb (293 lines)&lt;br /&gt;
&lt;br /&gt;
===What it Does===&lt;br /&gt;
The two class files performs functions which are needed in NLP analysis of reviews in the research.&lt;br /&gt;
&lt;br /&gt;
===Our Job===&lt;br /&gt;
The code has many code smells. First, the methods are long and complex, and the codes are not structured well, which makes it not readable and understandable. Second, extremely long if-else branch and loop exists everywhere. Third, the responsibility of sentence_state.rb is heavy, some functions of sentence_state should be given to others. Finally, there are some duplicate codes.&lt;br /&gt;
&lt;br /&gt;
Our job is to refactor the two classes and make it more O-O style and have a clear structure. To eliminate the code smells, we need removing the duplicate code, reconstruct long if-else branch and loop, generating new methods and classes to encapsulate functionality of other complex methods, clear the responsibility of classes and methods.&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
The first step in refactoring is to get the tests to pass. This required some debugging to find that some constants were defined in two different files, and one of the definitions was incomplete. After updating this, all 18 original tests in sentence_state_test.rb passed.&lt;br /&gt;
&lt;br /&gt;
The first place to refactor was the longest method in SentenceState, the method sentence_state(str_with_pos_tags). There were three for loops, each with deeply nested if-else statements inside of them. To make this method more readable, I extracted three for or if-else statements into their own method to clean up the code. This changed the code from 164 lines of if-else and for statements to:&lt;br /&gt;
 def sentence_state(str_with_pos_tags)&lt;br /&gt;
    state = POSITIVE&lt;br /&gt;
        &lt;br /&gt;
    tagged_tokens, tokens = parse_sentence_tokens(str_with_pos_tags)&lt;br /&gt;
    &lt;br /&gt;
    #iterating through the tokens to determine state&lt;br /&gt;
    prev_negative_word =&amp;quot;&amp;quot;&lt;br /&gt;
    for j  in (0..tokens.length-1)&lt;br /&gt;
      #checking type of the word&lt;br /&gt;
      #checking for negated words&lt;br /&gt;
      current_token_type = get_token_type(tokens[j..tokens.length-1)&lt;br /&gt;
      &lt;br /&gt;
      #getting next_state of the sentence clause      &lt;br /&gt;
      state = next_state(state, current_token_type, prev_negative_word, tagged_tokens)&lt;br /&gt;
      &lt;br /&gt;
      #setting the prevNegativeWord      &lt;br /&gt;
      if(tokens[j].casecmp(&amp;quot;NO&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NEVER&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NONE&amp;quot;) == 0)&lt;br /&gt;
        prev_negative_word = tokens[j]&lt;br /&gt;
      end  &lt;br /&gt;
          &lt;br /&gt;
    end #end of for loop&lt;br /&gt;
    &lt;br /&gt;
    if(state == NEGATIVE_DESCRIPTOR or state == NEGATIVE_WORD or state == NEGATIVE_PHRASE)&lt;br /&gt;
      state = NEGATED&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    return state&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Main Responsibility ===&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism.&lt;br /&gt;
&lt;br /&gt;
===Design Ideas===&lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are: compare_reviews_with_submissions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_questions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_responses, and&lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    &lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      &lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 &lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
 #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Please see code after refactoring in detail on this [https://github.com/shanfangshuiyuan/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb page].&lt;br /&gt;
&lt;br /&gt;
All the tests have been passed without failures since refactoring.&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81160</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81160"/>
		<updated>2013-10-30T19:20:26Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Project description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt;. Expertiza also supports team projects and any document type of submission is acceptable&amp;lt;ref&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza wiki]&amp;lt;/ref&amp;gt;. Expertiza has been deployed for years to help professors and students engaging in the learning process. Expertiza is an open source project, for each year, students in the course of CSC517-Object Oriented Programmning of North Carolina State University will contributes to this project along with teaching assistant and professor.&lt;br /&gt;
&lt;br /&gt;
For this year, we are responsible for refactoring plagiarism_check.rb and sentence_state.rb of the Expertiza project. Expertiza is built using Ruby on Rails with [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller MVC design pattern]. plagiarism_check.rb and sentence_state.rb are parts of the automated_metareview functionality inside models. The responsibility of sentence_state.rb is to determine the state of each clause of a sentence, and the responsibility of plagiarism_check.rb is to determine whether the reviews are just copied from other sources.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
===Classes===&lt;br /&gt;
plagiarism_check.rb (155 lines)&lt;br /&gt;
sentence_state.rb (293 lines)&lt;br /&gt;
&lt;br /&gt;
===What it Does===&lt;br /&gt;
The two class files performs functions which are needed in NLP analysis of reviews in the research.&lt;br /&gt;
&lt;br /&gt;
===Our Job===&lt;br /&gt;
The code has many code smells. First, the methods are long and complex, and the codes are not structured well, which makes it not readable and understandable. Second, extremely long if-else branch and loop exists everywhere. Third, the responsibility of sentence_state.rb is heavy, some functions of sentence_state should be given to others. Finally, there are some duplicate codes.&lt;br /&gt;
&lt;br /&gt;
Our job is to refactor the two classes and make it more O-O style and have a clear structure. To eliminate the code smells, we need removing the duplicate code, reconstruct long if-else branch and loop, generating new methods and classes to encapsulate functionality of other complex methods, clear the responsibility of classes and methods.&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
The first step in refactoring is to get the tests to pass. This required some debugging to find that some constants were defined in two different files, and one of the definitions was incomplete. After updating this, all 18 original tests in sentence_state_test.rb passed.&lt;br /&gt;
&lt;br /&gt;
The first place to refactor was the longest method in SentenceState, the method sentence_state(str_with_pos_tags). There were three for loops, each with deeply nested if-else statements inside of them. To make this method more readable, I extracted three for or if-else statements into their own method to clean up the code. This changed the code from 164 lines of if-else and for statements to:&lt;br /&gt;
 def sentence_state(str_with_pos_tags)&lt;br /&gt;
    state = POSITIVE&lt;br /&gt;
        &lt;br /&gt;
    tagged_tokens, tokens = parse_sentence_tokens(str_with_pos_tags)&lt;br /&gt;
    &lt;br /&gt;
    #iterating through the tokens to determine state&lt;br /&gt;
    prev_negative_word =&amp;quot;&amp;quot;&lt;br /&gt;
    for j  in (0..tokens.length-1)&lt;br /&gt;
      #checking type of the word&lt;br /&gt;
      #checking for negated words&lt;br /&gt;
      current_token_type = get_token_type(tokens[j..tokens.length-1)&lt;br /&gt;
      &lt;br /&gt;
      #getting next_state of the sentence clause      &lt;br /&gt;
      state = next_state(state, current_token_type, prev_negative_word, tagged_tokens)&lt;br /&gt;
      &lt;br /&gt;
      #setting the prevNegativeWord      &lt;br /&gt;
      if(tokens[j].casecmp(&amp;quot;NO&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NEVER&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NONE&amp;quot;) == 0)&lt;br /&gt;
        prev_negative_word = tokens[j]&lt;br /&gt;
      end  &lt;br /&gt;
          &lt;br /&gt;
    end #end of for loop&lt;br /&gt;
    &lt;br /&gt;
    if(state == NEGATIVE_DESCRIPTOR or state == NEGATIVE_WORD or state == NEGATIVE_PHRASE)&lt;br /&gt;
      state = NEGATED&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    return state&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Main Responsibility ===&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism.&lt;br /&gt;
&lt;br /&gt;
===Design Ideas===&lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are: compare_reviews_with_submissions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_questions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_responses, and&lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    &lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      &lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 &lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  &lt;br /&gt;
 #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Please see code after refactoring in detail on this [https://github.com/shanfangshuiyuan/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb page].&lt;br /&gt;
&lt;br /&gt;
All the tests have been passed without failures since refactoring.&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81069</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81069"/>
		<updated>2013-10-30T18:49:25Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Introduction to Refactoring plagiarism_check.rb and sentence_state.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt;. Expertiza also supports team projects and any document type of submission is acceptable&amp;lt;ref&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza wiki]&amp;lt;/ref&amp;gt;. Expertiza has been deployed for years to help professors and students engaging in the learning process. Expertiza is an open source project, for each year, students in the course of CSC517-Object Oriented Programmning of North Carolina State University will contributes to this project along with teaching assistant and professor.&lt;br /&gt;
&lt;br /&gt;
For this year, we are responsible for refactoring plagiarism_check.rb and sentence_state.rb of the Expertiza project. Expertiza is built using Ruby on Rails with [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller MVC design pattern]. plagiarism_check.rb and sentence_state.rb are parts of the automated_metareview functionality inside models. The responsibility of sentence_state.rb is to determine the state of each clause of a sentence, and the responsibility of plagiarism_check.rb is to determine whether the reviews are just copied from other sources.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
The first step in refactoring is to get the tests to pass. This required some debugging to find that some constants were defined in two different files, and one of the definitions was incomplete. After updating this, all 18 original tests in sentence_state_test.rb passed.&lt;br /&gt;
&lt;br /&gt;
The first place to refactor was the longest method in SentenceState, the method sentence_state(str_with_pos_tags). There were three for loops, each with deeply nested if-else statements inside of them. To make this method more readable, I extracted three for or if-else statements into their own method to clean up the code.&lt;br /&gt;
&lt;br /&gt;
[[collapsible show=&amp;quot;+ Show whatever&amp;quot; hide=&amp;quot;- Hide whatever&amp;quot;]]&lt;br /&gt;
Whatever text to show/hide.&lt;br /&gt;
[[/collapsible]]&lt;br /&gt;
 def sentence_state(str_with_pos_tags)&lt;br /&gt;
    state = POSITIVE&lt;br /&gt;
    #checking single tokens for negated words&lt;br /&gt;
    st = str_with_pos_tags.split(&amp;quot; &amp;quot;)&lt;br /&gt;
    count = st.length&lt;br /&gt;
    tokens = Array.new&lt;br /&gt;
    tagged_tokens = Array.new&lt;br /&gt;
    i = 0&lt;br /&gt;
    interim_noun_verb  = false #0 indicates no interim nouns or verbs&lt;br /&gt;
        &lt;br /&gt;
    #fetching all the tokens&lt;br /&gt;
    for k in (0..st.length-1)&lt;br /&gt;
      ps = st[k]&lt;br /&gt;
      #setting the tagged string&lt;br /&gt;
      tagged_tokens[i] = ps&lt;br /&gt;
      if(ps.include?(&amp;quot;/&amp;quot;))&lt;br /&gt;
        ps = ps[0..ps.index(&amp;quot;/&amp;quot;)-1] &lt;br /&gt;
      end&lt;br /&gt;
      #removing punctuations &lt;br /&gt;
      if(ps.include?(&amp;quot;.&amp;quot;))&lt;br /&gt;
        tokens[i] = ps[0..ps.index(&amp;quot;.&amp;quot;)-1]&lt;br /&gt;
      elsif(ps.include?(&amp;quot;,&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;,&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      elsif(ps.include?(&amp;quot;!&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;!&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      elsif(ps.include?(&amp;quot;;&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      else&lt;br /&gt;
        tokens[i] = ps&lt;br /&gt;
        i+=1&lt;br /&gt;
      end     &lt;br /&gt;
    end#end of the for loop&lt;br /&gt;
    &lt;br /&gt;
    #iterating through the tokens to determine state&lt;br /&gt;
    prev_negative_word =&amp;quot;&amp;quot;&lt;br /&gt;
    for j  in (0..i-1)&lt;br /&gt;
      #checking type of the word&lt;br /&gt;
      #checking for negated words&lt;br /&gt;
      if(is_negative_word(tokens[j]) == NEGATED)  &lt;br /&gt;
        returned_type = NEGATIVE_WORD&lt;br /&gt;
      #checking for a negative descriptor (indirect indicators of negation)&lt;br /&gt;
      elsif(is_negative_descriptor(tokens[j]) == NEGATED)&lt;br /&gt;
        returned_type = NEGATIVE_DESCRIPTOR&lt;br /&gt;
      #2-gram phrases of negative phrases&lt;br /&gt;
      elsif(j+1 &amp;lt; count &amp;amp;&amp;amp; !tokens[j].nil? &amp;amp;&amp;amp; !tokens[j+1].nil? &amp;amp;&amp;amp; &lt;br /&gt;
        is_negative_phrase(tokens[j]+&amp;quot; &amp;quot;+tokens[j+1]) == NEGATED)&lt;br /&gt;
        returned_type = NEGATIVE_PHRASE&lt;br /&gt;
        j = j+1      &lt;br /&gt;
      #if suggestion word is found&lt;br /&gt;
      elsif(is_suggestive(tokens[j]) == SUGGESTIVE)&lt;br /&gt;
        returned_type = SUGGESTIVE&lt;br /&gt;
      #2-gram phrases suggestion phrases&lt;br /&gt;
      elsif(j+1 &amp;lt; count &amp;amp;&amp;amp; !tokens[j].nil? &amp;amp;&amp;amp; !tokens[j+1].nil? &amp;amp;&amp;amp;&lt;br /&gt;
         is_suggestive_phrase(tokens[j]+&amp;quot; &amp;quot;+tokens[j+1]) == SUGGESTIVE)&lt;br /&gt;
        returned_type = SUGGESTIVE&lt;br /&gt;
        j = j+1&lt;br /&gt;
      #else set to positive&lt;br /&gt;
      else&lt;br /&gt;
        returned_type = POSITIVE&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      #----------------------------------------------------------------------&lt;br /&gt;
      #comparing 'returnedType' with the existing STATE of the sentence clause&lt;br /&gt;
      #after returnedType is identified, check its state and compare it to the existing state&lt;br /&gt;
      #if present state is negative and an interim non-negative or non-suggestive word was found, set the flag to true&lt;br /&gt;
      if((state == NEGATIVE_WORD or state == NEGATIVE_DESCRIPTOR or state == NEGATIVE_PHRASE) and returned_type == POSITIVE)&lt;br /&gt;
        if(interim_noun_verb == false and (tagged_tokens[j].include?(&amp;quot;NN&amp;quot;) or tagged_tokens[j].include?(&amp;quot;PR&amp;quot;) or tagged_tokens[j].include?(&amp;quot;VB&amp;quot;) or tagged_tokens[j].include?(&amp;quot;MD&amp;quot;)))&lt;br /&gt;
          interim_noun_verb = true&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
      &lt;br /&gt;
      if(state == POSITIVE and returned_type != POSITIVE)&lt;br /&gt;
        state = returned_type&lt;br /&gt;
      #when state is a negative word&lt;br /&gt;
      elsif(state == NEGATIVE_WORD) #previous state&lt;br /&gt;
        if(returned_type == NEGATIVE_WORD)&lt;br /&gt;
          #these words embellish the negation, so only if the previous word was not one of them you make it positive&lt;br /&gt;
          if(prev_negative_word.casecmp(&amp;quot;NO&amp;quot;) != 0 and prev_negative_word.casecmp(&amp;quot;NEVER&amp;quot;) != 0 and prev_negative_word.casecmp(&amp;quot;NONE&amp;quot;) != 0)&lt;br /&gt;
            state = POSITIVE #e.g: &amp;quot;not had no work..&amp;quot;, &amp;quot;doesn't have no work..&amp;quot;, &amp;quot;its not that it doesn't bother me...&amp;quot;&lt;br /&gt;
          else&lt;br /&gt;
            state = NEGATIVE_WORD #e.g: &amp;quot;no it doesn't help&amp;quot;, &amp;quot;no there is no use for ...&amp;quot;&lt;br /&gt;
          end  &lt;br /&gt;
          interim_noun_verb = false #resetting         &lt;br /&gt;
        elsif(returned_type == NEGATIVE_DESCRIPTOR or returned_type == NEGATIVE_PHRASE)&lt;br /&gt;
          state = POSITIVE #e.g.: &amp;quot;not bad&amp;quot;, &amp;quot;not taken from&amp;quot;, &amp;quot;I don't want nothing&amp;quot;, &amp;quot;no code duplication&amp;quot;// [&amp;quot;It couldn't be more confusing..&amp;quot;- anomaly we dont handle this for now!]&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == SUGGESTIVE)&lt;br /&gt;
          #e.g. &amp;quot; it is not too useful as people could...&amp;quot;, what about this one?&lt;br /&gt;
          if(interim_noun_verb == true) #there are some words in between&lt;br /&gt;
            state = NEGATIVE_WORD&lt;br /&gt;
          else&lt;br /&gt;
            state = SUGGESTIVE #e.g.:&amp;quot;I do not(-) suggest(S) ...&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        end&lt;br /&gt;
      #when state is a negative descriptor&lt;br /&gt;
      elsif(state == NEGATIVE_DESCRIPTOR)&lt;br /&gt;
        if(returned_type == NEGATIVE_WORD)&lt;br /&gt;
          if(interim_noun_verb == true)#there are some words in between&lt;br /&gt;
            state = NEGATIVE_WORD #e.g: &amp;quot;hard(-) to understand none(-) of the comments&amp;quot;&lt;br /&gt;
          else&lt;br /&gt;
            state = POSITIVE #e.g.&amp;quot;He hardly not....&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == NEGATIVE_DESCRIPTOR)&lt;br /&gt;
          if(interim_noun_verb == true)#there are some words in between&lt;br /&gt;
            state = NEGATIVE_DESCRIPTOR #e.g:&amp;quot;there is barely any code duplication&amp;quot;&lt;br /&gt;
          else &lt;br /&gt;
            state = POSITIVE #e.g.&amp;quot;It is hardly confusing..&amp;quot;, but what about &amp;quot;it is a little confusing..&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == NEGATIVE_PHRASE)&lt;br /&gt;
          if(interim_noun_verb == true)#there are some words in between&lt;br /&gt;
            state = NEGATIVE_PHRASE #e.g:&amp;quot;there is barely any code duplication&amp;quot;&lt;br /&gt;
          else &lt;br /&gt;
            state = POSITIVE #e.g.:&amp;quot;it is hard and appears to be taken from&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == SUGGESTIVE)&lt;br /&gt;
          state = SUGGESTIVE #e.g.:&amp;quot;I hardly(-) suggested(S) ...&amp;quot;&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        end&lt;br /&gt;
      #when state is a negative phrase&lt;br /&gt;
      elsif(state == NEGATIVE_PHRASE)&lt;br /&gt;
        if(returned_type == NEGATIVE_WORD)&lt;br /&gt;
          if(interim_noun_verb == true)#there are some words in between&lt;br /&gt;
            state = NEGATIVE_WORD #e.g.&amp;quot;It is too short the text and doesn't&amp;quot;&lt;br /&gt;
          else&lt;br /&gt;
            state = POSITIVE #e.g.&amp;quot;It is too short not to contain..&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == NEGATIVE_DESCRIPTOR)&lt;br /&gt;
          state = NEGATIVE_DESCRIPTOR #e.g.&amp;quot;It is too short barely covering...&amp;quot;&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == NEGATIVE_PHRASE)&lt;br /&gt;
          state = NEGATIVE_PHRASE #e.g.:&amp;quot;it is too short, taken from ...&amp;quot;&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == SUGGESTIVE)&lt;br /&gt;
          state = SUGGESTIVE #e.g.:&amp;quot;I too short and I suggest ...&amp;quot;&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        end&lt;br /&gt;
      #when state is suggestive&lt;br /&gt;
      elsif(state == SUGGESTIVE) #e.g.:&amp;quot;I might(S) not(-) suggest(S) ...&amp;quot;&lt;br /&gt;
        if(returned_type == NEGATIVE_DESCRIPTOR)&lt;br /&gt;
          state = NEGATIVE_DESCRIPTOR&lt;br /&gt;
        elsif(returned_type == NEGATIVE_PHRASE)&lt;br /&gt;
          state = NEGATIVE_PHRASE&lt;br /&gt;
        end&lt;br /&gt;
        #e.g.:&amp;quot;I suggest you don't..&amp;quot; -&amp;gt; suggestive&lt;br /&gt;
        interim_noun_verb = false #resetting&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      #setting the prevNegativeWord&lt;br /&gt;
      if(tokens[j].casecmp(&amp;quot;NO&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NEVER&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NONE&amp;quot;) == 0)&lt;br /&gt;
        prev_negative_word = tokens[j]&lt;br /&gt;
      end  &lt;br /&gt;
          &lt;br /&gt;
    end #end of for loop&lt;br /&gt;
    &lt;br /&gt;
    if(state == NEGATIVE_DESCRIPTOR or state == NEGATIVE_WORD or state == NEGATIVE_PHRASE)&lt;br /&gt;
      state = NEGATED&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    return state&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Main Responsibility ===&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism.&lt;br /&gt;
&lt;br /&gt;
===Design Ideas===&lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are: compare_reviews_with_submissions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_questions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_responses, and&lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Please see code after refactoring in detail on this [https://github.com/shanfangshuiyuan/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb page].&lt;br /&gt;
&lt;br /&gt;
All the tests have been passed without failures since refactoring.&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81056</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81056"/>
		<updated>2013-10-30T18:46:32Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Introduction to Refactoring plagiarism_check.rb and sentence_state.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt;. Expertiza also supports team projects and any document type of submission is acceptable&amp;lt;ref&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza wiki]&amp;lt;/ref&amp;gt;. Expertiza has been deployed for years to help professors and students engaging in the learning process. Expertiza is an open source project, for each year, students in the course of CSC517-Object Oriented Programmning of North Carolina State University will contributes to this project along with teaching assistant and professor.&lt;br /&gt;
&lt;br /&gt;
For this year, we are responsible for refactoring plagiarism_check.rb and sentence_state.rb of the Expertiza project. Expertiza is built using Ruby on Rails with MVC design pattern. plagiarism_check.rb and sentence_state.rb are parts of the automated_metareview functionality inside models. The responsibility of sentence_state.rb is to determine the state of each clause of a sentence, and the responsibility of plagiarism_check.rb is to determine whether the reviews are just copied from other sources.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
The first step in refactoring is to get the tests to pass. This required some debugging to find that some constants were defined in two different files, and one of the definitions was incomplete. After updating this, all 18 original tests in sentence_state_test.rb passed.&lt;br /&gt;
&lt;br /&gt;
The first place to refactor was the longest method in SentenceState, the method sentence_state(str_with_pos_tags). There were three for loops, each with deeply nested if-else statements inside of them. To make this method more readable, I extracted three for or if-else statements into their own method to clean up the code.&lt;br /&gt;
&lt;br /&gt;
[[collapsible]]&lt;br /&gt;
 def sentence_state(str_with_pos_tags)&lt;br /&gt;
    state = POSITIVE&lt;br /&gt;
    #checking single tokens for negated words&lt;br /&gt;
    st = str_with_pos_tags.split(&amp;quot; &amp;quot;)&lt;br /&gt;
    count = st.length&lt;br /&gt;
    tokens = Array.new&lt;br /&gt;
    tagged_tokens = Array.new&lt;br /&gt;
    i = 0&lt;br /&gt;
    interim_noun_verb  = false #0 indicates no interim nouns or verbs&lt;br /&gt;
        &lt;br /&gt;
    #fetching all the tokens&lt;br /&gt;
    for k in (0..st.length-1)&lt;br /&gt;
      ps = st[k]&lt;br /&gt;
      #setting the tagged string&lt;br /&gt;
      tagged_tokens[i] = ps&lt;br /&gt;
      if(ps.include?(&amp;quot;/&amp;quot;))&lt;br /&gt;
        ps = ps[0..ps.index(&amp;quot;/&amp;quot;)-1] &lt;br /&gt;
      end&lt;br /&gt;
      #removing punctuations &lt;br /&gt;
      if(ps.include?(&amp;quot;.&amp;quot;))&lt;br /&gt;
        tokens[i] = ps[0..ps.index(&amp;quot;.&amp;quot;)-1]&lt;br /&gt;
      elsif(ps.include?(&amp;quot;,&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;,&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      elsif(ps.include?(&amp;quot;!&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;!&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      elsif(ps.include?(&amp;quot;;&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      else&lt;br /&gt;
        tokens[i] = ps&lt;br /&gt;
        i+=1&lt;br /&gt;
      end     &lt;br /&gt;
    end#end of the for loop&lt;br /&gt;
    &lt;br /&gt;
    #iterating through the tokens to determine state&lt;br /&gt;
    prev_negative_word =&amp;quot;&amp;quot;&lt;br /&gt;
    for j  in (0..i-1)&lt;br /&gt;
      #checking type of the word&lt;br /&gt;
      #checking for negated words&lt;br /&gt;
      if(is_negative_word(tokens[j]) == NEGATED)  &lt;br /&gt;
        returned_type = NEGATIVE_WORD&lt;br /&gt;
      #checking for a negative descriptor (indirect indicators of negation)&lt;br /&gt;
      elsif(is_negative_descriptor(tokens[j]) == NEGATED)&lt;br /&gt;
        returned_type = NEGATIVE_DESCRIPTOR&lt;br /&gt;
      #2-gram phrases of negative phrases&lt;br /&gt;
      elsif(j+1 &amp;lt; count &amp;amp;&amp;amp; !tokens[j].nil? &amp;amp;&amp;amp; !tokens[j+1].nil? &amp;amp;&amp;amp; &lt;br /&gt;
        is_negative_phrase(tokens[j]+&amp;quot; &amp;quot;+tokens[j+1]) == NEGATED)&lt;br /&gt;
        returned_type = NEGATIVE_PHRASE&lt;br /&gt;
        j = j+1      &lt;br /&gt;
      #if suggestion word is found&lt;br /&gt;
      elsif(is_suggestive(tokens[j]) == SUGGESTIVE)&lt;br /&gt;
        returned_type = SUGGESTIVE&lt;br /&gt;
      #2-gram phrases suggestion phrases&lt;br /&gt;
      elsif(j+1 &amp;lt; count &amp;amp;&amp;amp; !tokens[j].nil? &amp;amp;&amp;amp; !tokens[j+1].nil? &amp;amp;&amp;amp;&lt;br /&gt;
         is_suggestive_phrase(tokens[j]+&amp;quot; &amp;quot;+tokens[j+1]) == SUGGESTIVE)&lt;br /&gt;
        returned_type = SUGGESTIVE&lt;br /&gt;
        j = j+1&lt;br /&gt;
      #else set to positive&lt;br /&gt;
      else&lt;br /&gt;
        returned_type = POSITIVE&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      #----------------------------------------------------------------------&lt;br /&gt;
      #comparing 'returnedType' with the existing STATE of the sentence clause&lt;br /&gt;
      #after returnedType is identified, check its state and compare it to the existing state&lt;br /&gt;
      #if present state is negative and an interim non-negative or non-suggestive word was found, set the flag to true&lt;br /&gt;
      if((state == NEGATIVE_WORD or state == NEGATIVE_DESCRIPTOR or state == NEGATIVE_PHRASE) and returned_type == POSITIVE)&lt;br /&gt;
        if(interim_noun_verb == false and (tagged_tokens[j].include?(&amp;quot;NN&amp;quot;) or tagged_tokens[j].include?(&amp;quot;PR&amp;quot;) or tagged_tokens[j].include?(&amp;quot;VB&amp;quot;) or tagged_tokens[j].include?(&amp;quot;MD&amp;quot;)))&lt;br /&gt;
          interim_noun_verb = true&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
      &lt;br /&gt;
      if(state == POSITIVE and returned_type != POSITIVE)&lt;br /&gt;
        state = returned_type&lt;br /&gt;
      #when state is a negative word&lt;br /&gt;
      elsif(state == NEGATIVE_WORD) #previous state&lt;br /&gt;
        if(returned_type == NEGATIVE_WORD)&lt;br /&gt;
          #these words embellish the negation, so only if the previous word was not one of them you make it positive&lt;br /&gt;
          if(prev_negative_word.casecmp(&amp;quot;NO&amp;quot;) != 0 and prev_negative_word.casecmp(&amp;quot;NEVER&amp;quot;) != 0 and prev_negative_word.casecmp(&amp;quot;NONE&amp;quot;) != 0)&lt;br /&gt;
            state = POSITIVE #e.g: &amp;quot;not had no work..&amp;quot;, &amp;quot;doesn't have no work..&amp;quot;, &amp;quot;its not that it doesn't bother me...&amp;quot;&lt;br /&gt;
          else&lt;br /&gt;
            state = NEGATIVE_WORD #e.g: &amp;quot;no it doesn't help&amp;quot;, &amp;quot;no there is no use for ...&amp;quot;&lt;br /&gt;
          end  &lt;br /&gt;
          interim_noun_verb = false #resetting         &lt;br /&gt;
        elsif(returned_type == NEGATIVE_DESCRIPTOR or returned_type == NEGATIVE_PHRASE)&lt;br /&gt;
          state = POSITIVE #e.g.: &amp;quot;not bad&amp;quot;, &amp;quot;not taken from&amp;quot;, &amp;quot;I don't want nothing&amp;quot;, &amp;quot;no code duplication&amp;quot;// [&amp;quot;It couldn't be more confusing..&amp;quot;- anomaly we dont handle this for now!]&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == SUGGESTIVE)&lt;br /&gt;
          #e.g. &amp;quot; it is not too useful as people could...&amp;quot;, what about this one?&lt;br /&gt;
          if(interim_noun_verb == true) #there are some words in between&lt;br /&gt;
            state = NEGATIVE_WORD&lt;br /&gt;
          else&lt;br /&gt;
            state = SUGGESTIVE #e.g.:&amp;quot;I do not(-) suggest(S) ...&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        end&lt;br /&gt;
      #when state is a negative descriptor&lt;br /&gt;
      elsif(state == NEGATIVE_DESCRIPTOR)&lt;br /&gt;
        if(returned_type == NEGATIVE_WORD)&lt;br /&gt;
          if(interim_noun_verb == true)#there are some words in between&lt;br /&gt;
            state = NEGATIVE_WORD #e.g: &amp;quot;hard(-) to understand none(-) of the comments&amp;quot;&lt;br /&gt;
          else&lt;br /&gt;
            state = POSITIVE #e.g.&amp;quot;He hardly not....&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == NEGATIVE_DESCRIPTOR)&lt;br /&gt;
          if(interim_noun_verb == true)#there are some words in between&lt;br /&gt;
            state = NEGATIVE_DESCRIPTOR #e.g:&amp;quot;there is barely any code duplication&amp;quot;&lt;br /&gt;
          else &lt;br /&gt;
            state = POSITIVE #e.g.&amp;quot;It is hardly confusing..&amp;quot;, but what about &amp;quot;it is a little confusing..&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == NEGATIVE_PHRASE)&lt;br /&gt;
          if(interim_noun_verb == true)#there are some words in between&lt;br /&gt;
            state = NEGATIVE_PHRASE #e.g:&amp;quot;there is barely any code duplication&amp;quot;&lt;br /&gt;
          else &lt;br /&gt;
            state = POSITIVE #e.g.:&amp;quot;it is hard and appears to be taken from&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == SUGGESTIVE)&lt;br /&gt;
          state = SUGGESTIVE #e.g.:&amp;quot;I hardly(-) suggested(S) ...&amp;quot;&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        end&lt;br /&gt;
      #when state is a negative phrase&lt;br /&gt;
      elsif(state == NEGATIVE_PHRASE)&lt;br /&gt;
        if(returned_type == NEGATIVE_WORD)&lt;br /&gt;
          if(interim_noun_verb == true)#there are some words in between&lt;br /&gt;
            state = NEGATIVE_WORD #e.g.&amp;quot;It is too short the text and doesn't&amp;quot;&lt;br /&gt;
          else&lt;br /&gt;
            state = POSITIVE #e.g.&amp;quot;It is too short not to contain..&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == NEGATIVE_DESCRIPTOR)&lt;br /&gt;
          state = NEGATIVE_DESCRIPTOR #e.g.&amp;quot;It is too short barely covering...&amp;quot;&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == NEGATIVE_PHRASE)&lt;br /&gt;
          state = NEGATIVE_PHRASE #e.g.:&amp;quot;it is too short, taken from ...&amp;quot;&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == SUGGESTIVE)&lt;br /&gt;
          state = SUGGESTIVE #e.g.:&amp;quot;I too short and I suggest ...&amp;quot;&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        end&lt;br /&gt;
      #when state is suggestive&lt;br /&gt;
      elsif(state == SUGGESTIVE) #e.g.:&amp;quot;I might(S) not(-) suggest(S) ...&amp;quot;&lt;br /&gt;
        if(returned_type == NEGATIVE_DESCRIPTOR)&lt;br /&gt;
          state = NEGATIVE_DESCRIPTOR&lt;br /&gt;
        elsif(returned_type == NEGATIVE_PHRASE)&lt;br /&gt;
          state = NEGATIVE_PHRASE&lt;br /&gt;
        end&lt;br /&gt;
        #e.g.:&amp;quot;I suggest you don't..&amp;quot; -&amp;gt; suggestive&lt;br /&gt;
        interim_noun_verb = false #resetting&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      #setting the prevNegativeWord&lt;br /&gt;
      if(tokens[j].casecmp(&amp;quot;NO&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NEVER&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NONE&amp;quot;) == 0)&lt;br /&gt;
        prev_negative_word = tokens[j]&lt;br /&gt;
      end  &lt;br /&gt;
          &lt;br /&gt;
    end #end of for loop&lt;br /&gt;
    &lt;br /&gt;
    if(state == NEGATIVE_DESCRIPTOR or state == NEGATIVE_WORD or state == NEGATIVE_PHRASE)&lt;br /&gt;
      state = NEGATED&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    return state&lt;br /&gt;
 end&lt;br /&gt;
[[/collapsible]]&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
===Main funcitions===&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism. &lt;br /&gt;
&lt;br /&gt;
===Design ideas===&lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are: compare_reviews_with_submissions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_questions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_responses, and&lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Refactor steps in general===&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Please see code after refactoring in detail on this [https://github.com/shanfangshuiyuan/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb page].&lt;br /&gt;
&lt;br /&gt;
All the tests have been passed without failures since refactoring.&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81055</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81055"/>
		<updated>2013-10-30T18:45:40Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Introduction to Refactoring plagiarism_check.rb and sentence_state.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt;. Expertiza also supports team projects and any document type of submission is acceptable&amp;lt;ref&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza wiki]&amp;lt;/ref&amp;gt;. Expertiza has been deployed for years to help professors and students engaging in the learning process. Expertiza is an open source project, for each year, students in the course of CSC517-Object Oriented Programmning of North Carolina State University will contributes to this project along with teaching assistant and professor.&lt;br /&gt;
&lt;br /&gt;
For this year, we are responsible for refactoring plagiarism_check.rb and sentence_state.rb of the Expertiza project. Expertiza is built using Ruby on Rails with MVC design pattern. plagiarism_check.rb and sentence_state.rb are parts of the models inside the automated_metareview functionality. The responsibility of sentence_state.rb is to determine the state of each clause of a sentence, and the responsibility of plagiarism_check.rb is to determine whether the reviews are just copied from other sources.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
===Refactor Steps===&lt;br /&gt;
The first step in refactoring is to get the tests to pass. This required some debugging to find that some constants were defined in two different files, and one of the definitions was incomplete. After updating this, all 18 original tests in sentence_state_test.rb passed.&lt;br /&gt;
&lt;br /&gt;
The first place to refactor was the longest method in SentenceState, the method sentence_state(str_with_pos_tags). There were three for loops, each with deeply nested if-else statements inside of them. To make this method more readable, I extracted three for or if-else statements into their own method to clean up the code.&lt;br /&gt;
&lt;br /&gt;
[[collapsible]]&lt;br /&gt;
 def sentence_state(str_with_pos_tags)&lt;br /&gt;
    state = POSITIVE&lt;br /&gt;
    #checking single tokens for negated words&lt;br /&gt;
    st = str_with_pos_tags.split(&amp;quot; &amp;quot;)&lt;br /&gt;
    count = st.length&lt;br /&gt;
    tokens = Array.new&lt;br /&gt;
    tagged_tokens = Array.new&lt;br /&gt;
    i = 0&lt;br /&gt;
    interim_noun_verb  = false #0 indicates no interim nouns or verbs&lt;br /&gt;
        &lt;br /&gt;
    #fetching all the tokens&lt;br /&gt;
    for k in (0..st.length-1)&lt;br /&gt;
      ps = st[k]&lt;br /&gt;
      #setting the tagged string&lt;br /&gt;
      tagged_tokens[i] = ps&lt;br /&gt;
      if(ps.include?(&amp;quot;/&amp;quot;))&lt;br /&gt;
        ps = ps[0..ps.index(&amp;quot;/&amp;quot;)-1] &lt;br /&gt;
      end&lt;br /&gt;
      #removing punctuations &lt;br /&gt;
      if(ps.include?(&amp;quot;.&amp;quot;))&lt;br /&gt;
        tokens[i] = ps[0..ps.index(&amp;quot;.&amp;quot;)-1]&lt;br /&gt;
      elsif(ps.include?(&amp;quot;,&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;,&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      elsif(ps.include?(&amp;quot;!&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;!&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      elsif(ps.include?(&amp;quot;;&amp;quot;))&lt;br /&gt;
        tokens[i] = ps.gsub(&amp;quot;;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
      else&lt;br /&gt;
        tokens[i] = ps&lt;br /&gt;
        i+=1&lt;br /&gt;
      end     &lt;br /&gt;
    end#end of the for loop&lt;br /&gt;
    &lt;br /&gt;
    #iterating through the tokens to determine state&lt;br /&gt;
    prev_negative_word =&amp;quot;&amp;quot;&lt;br /&gt;
    for j  in (0..i-1)&lt;br /&gt;
      #checking type of the word&lt;br /&gt;
      #checking for negated words&lt;br /&gt;
      if(is_negative_word(tokens[j]) == NEGATED)  &lt;br /&gt;
        returned_type = NEGATIVE_WORD&lt;br /&gt;
      #checking for a negative descriptor (indirect indicators of negation)&lt;br /&gt;
      elsif(is_negative_descriptor(tokens[j]) == NEGATED)&lt;br /&gt;
        returned_type = NEGATIVE_DESCRIPTOR&lt;br /&gt;
      #2-gram phrases of negative phrases&lt;br /&gt;
      elsif(j+1 &amp;lt; count &amp;amp;&amp;amp; !tokens[j].nil? &amp;amp;&amp;amp; !tokens[j+1].nil? &amp;amp;&amp;amp; &lt;br /&gt;
        is_negative_phrase(tokens[j]+&amp;quot; &amp;quot;+tokens[j+1]) == NEGATED)&lt;br /&gt;
        returned_type = NEGATIVE_PHRASE&lt;br /&gt;
        j = j+1      &lt;br /&gt;
      #if suggestion word is found&lt;br /&gt;
      elsif(is_suggestive(tokens[j]) == SUGGESTIVE)&lt;br /&gt;
        returned_type = SUGGESTIVE&lt;br /&gt;
      #2-gram phrases suggestion phrases&lt;br /&gt;
      elsif(j+1 &amp;lt; count &amp;amp;&amp;amp; !tokens[j].nil? &amp;amp;&amp;amp; !tokens[j+1].nil? &amp;amp;&amp;amp;&lt;br /&gt;
         is_suggestive_phrase(tokens[j]+&amp;quot; &amp;quot;+tokens[j+1]) == SUGGESTIVE)&lt;br /&gt;
        returned_type = SUGGESTIVE&lt;br /&gt;
        j = j+1&lt;br /&gt;
      #else set to positive&lt;br /&gt;
      else&lt;br /&gt;
        returned_type = POSITIVE&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      #----------------------------------------------------------------------&lt;br /&gt;
      #comparing 'returnedType' with the existing STATE of the sentence clause&lt;br /&gt;
      #after returnedType is identified, check its state and compare it to the existing state&lt;br /&gt;
      #if present state is negative and an interim non-negative or non-suggestive word was found, set the flag to true&lt;br /&gt;
      if((state == NEGATIVE_WORD or state == NEGATIVE_DESCRIPTOR or state == NEGATIVE_PHRASE) and returned_type == POSITIVE)&lt;br /&gt;
        if(interim_noun_verb == false and (tagged_tokens[j].include?(&amp;quot;NN&amp;quot;) or tagged_tokens[j].include?(&amp;quot;PR&amp;quot;) or tagged_tokens[j].include?(&amp;quot;VB&amp;quot;) or tagged_tokens[j].include?(&amp;quot;MD&amp;quot;)))&lt;br /&gt;
          interim_noun_verb = true&lt;br /&gt;
        end&lt;br /&gt;
      end &lt;br /&gt;
      &lt;br /&gt;
      if(state == POSITIVE and returned_type != POSITIVE)&lt;br /&gt;
        state = returned_type&lt;br /&gt;
      #when state is a negative word&lt;br /&gt;
      elsif(state == NEGATIVE_WORD) #previous state&lt;br /&gt;
        if(returned_type == NEGATIVE_WORD)&lt;br /&gt;
          #these words embellish the negation, so only if the previous word was not one of them you make it positive&lt;br /&gt;
          if(prev_negative_word.casecmp(&amp;quot;NO&amp;quot;) != 0 and prev_negative_word.casecmp(&amp;quot;NEVER&amp;quot;) != 0 and prev_negative_word.casecmp(&amp;quot;NONE&amp;quot;) != 0)&lt;br /&gt;
            state = POSITIVE #e.g: &amp;quot;not had no work..&amp;quot;, &amp;quot;doesn't have no work..&amp;quot;, &amp;quot;its not that it doesn't bother me...&amp;quot;&lt;br /&gt;
          else&lt;br /&gt;
            state = NEGATIVE_WORD #e.g: &amp;quot;no it doesn't help&amp;quot;, &amp;quot;no there is no use for ...&amp;quot;&lt;br /&gt;
          end  &lt;br /&gt;
          interim_noun_verb = false #resetting         &lt;br /&gt;
        elsif(returned_type == NEGATIVE_DESCRIPTOR or returned_type == NEGATIVE_PHRASE)&lt;br /&gt;
          state = POSITIVE #e.g.: &amp;quot;not bad&amp;quot;, &amp;quot;not taken from&amp;quot;, &amp;quot;I don't want nothing&amp;quot;, &amp;quot;no code duplication&amp;quot;// [&amp;quot;It couldn't be more confusing..&amp;quot;- anomaly we dont handle this for now!]&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == SUGGESTIVE)&lt;br /&gt;
          #e.g. &amp;quot; it is not too useful as people could...&amp;quot;, what about this one?&lt;br /&gt;
          if(interim_noun_verb == true) #there are some words in between&lt;br /&gt;
            state = NEGATIVE_WORD&lt;br /&gt;
          else&lt;br /&gt;
            state = SUGGESTIVE #e.g.:&amp;quot;I do not(-) suggest(S) ...&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        end&lt;br /&gt;
      #when state is a negative descriptor&lt;br /&gt;
      elsif(state == NEGATIVE_DESCRIPTOR)&lt;br /&gt;
        if(returned_type == NEGATIVE_WORD)&lt;br /&gt;
          if(interim_noun_verb == true)#there are some words in between&lt;br /&gt;
            state = NEGATIVE_WORD #e.g: &amp;quot;hard(-) to understand none(-) of the comments&amp;quot;&lt;br /&gt;
          else&lt;br /&gt;
            state = POSITIVE #e.g.&amp;quot;He hardly not....&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == NEGATIVE_DESCRIPTOR)&lt;br /&gt;
          if(interim_noun_verb == true)#there are some words in between&lt;br /&gt;
            state = NEGATIVE_DESCRIPTOR #e.g:&amp;quot;there is barely any code duplication&amp;quot;&lt;br /&gt;
          else &lt;br /&gt;
            state = POSITIVE #e.g.&amp;quot;It is hardly confusing..&amp;quot;, but what about &amp;quot;it is a little confusing..&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == NEGATIVE_PHRASE)&lt;br /&gt;
          if(interim_noun_verb == true)#there are some words in between&lt;br /&gt;
            state = NEGATIVE_PHRASE #e.g:&amp;quot;there is barely any code duplication&amp;quot;&lt;br /&gt;
          else &lt;br /&gt;
            state = POSITIVE #e.g.:&amp;quot;it is hard and appears to be taken from&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == SUGGESTIVE)&lt;br /&gt;
          state = SUGGESTIVE #e.g.:&amp;quot;I hardly(-) suggested(S) ...&amp;quot;&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        end&lt;br /&gt;
      #when state is a negative phrase&lt;br /&gt;
      elsif(state == NEGATIVE_PHRASE)&lt;br /&gt;
        if(returned_type == NEGATIVE_WORD)&lt;br /&gt;
          if(interim_noun_verb == true)#there are some words in between&lt;br /&gt;
            state = NEGATIVE_WORD #e.g.&amp;quot;It is too short the text and doesn't&amp;quot;&lt;br /&gt;
          else&lt;br /&gt;
            state = POSITIVE #e.g.&amp;quot;It is too short not to contain..&amp;quot;&lt;br /&gt;
          end&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == NEGATIVE_DESCRIPTOR)&lt;br /&gt;
          state = NEGATIVE_DESCRIPTOR #e.g.&amp;quot;It is too short barely covering...&amp;quot;&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == NEGATIVE_PHRASE)&lt;br /&gt;
          state = NEGATIVE_PHRASE #e.g.:&amp;quot;it is too short, taken from ...&amp;quot;&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        elsif(returned_type == SUGGESTIVE)&lt;br /&gt;
          state = SUGGESTIVE #e.g.:&amp;quot;I too short and I suggest ...&amp;quot;&lt;br /&gt;
          interim_noun_verb = false #resetting&lt;br /&gt;
        end&lt;br /&gt;
      #when state is suggestive&lt;br /&gt;
      elsif(state == SUGGESTIVE) #e.g.:&amp;quot;I might(S) not(-) suggest(S) ...&amp;quot;&lt;br /&gt;
        if(returned_type == NEGATIVE_DESCRIPTOR)&lt;br /&gt;
          state = NEGATIVE_DESCRIPTOR&lt;br /&gt;
        elsif(returned_type == NEGATIVE_PHRASE)&lt;br /&gt;
          state = NEGATIVE_PHRASE&lt;br /&gt;
        end&lt;br /&gt;
        #e.g.:&amp;quot;I suggest you don't..&amp;quot; -&amp;gt; suggestive&lt;br /&gt;
        interim_noun_verb = false #resetting&lt;br /&gt;
      end&lt;br /&gt;
      &lt;br /&gt;
      #setting the prevNegativeWord&lt;br /&gt;
      if(tokens[j].casecmp(&amp;quot;NO&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NEVER&amp;quot;) == 0 or tokens[j].casecmp(&amp;quot;NONE&amp;quot;) == 0)&lt;br /&gt;
        prev_negative_word = tokens[j]&lt;br /&gt;
      end  &lt;br /&gt;
          &lt;br /&gt;
    end #end of for loop&lt;br /&gt;
    &lt;br /&gt;
    if(state == NEGATIVE_DESCRIPTOR or state == NEGATIVE_WORD or state == NEGATIVE_PHRASE)&lt;br /&gt;
      state = NEGATED&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    return state&lt;br /&gt;
 end&lt;br /&gt;
[[/collapsible]]&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
===Main funcitions===&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism. &lt;br /&gt;
&lt;br /&gt;
===Design ideas===&lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are: compare_reviews_with_submissions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_questions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_responses, and&lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Refactor steps in general===&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Please see code after refactoring in detail on this [https://github.com/shanfangshuiyuan/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb page].&lt;br /&gt;
&lt;br /&gt;
All the tests have been passed without failures since refactoring.&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81032</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81032"/>
		<updated>2013-10-30T18:38:52Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Introduction to Refactoring plagiarism_check.rb and sentence_state.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt;. Expertiza also supports team projects and any document type of submission is acceptable&amp;lt;ref&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza wiki]&amp;lt;/ref&amp;gt;. Expertiza has been deployed for years to help professors and students engaging in the learning process. Expertiza is an open source projects, for each year, students in the course of CSC517-Object Oriented Programmning will contributes to this project along with teaching assistant and professor.&lt;br /&gt;
&lt;br /&gt;
For this year, we are responsible for refactoring plagiarism and sentence_state.rb of the Expertiza project.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The main responsibility of SentenceState should be just to determine the state of a sentence, and another class should be in charge of knowing the parts of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
===Main funcitions===&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism. &lt;br /&gt;
&lt;br /&gt;
===Design ideas===&lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are: compare_reviews_with_submissions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_questions, &lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_responses, and&lt;br /&gt;
&lt;br /&gt;
compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
===Refactor Step===&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81024</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81024"/>
		<updated>2013-10-30T18:35:42Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Introduction to Refactoring plagiarism_check.rb and sentence_state.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt;. Expertiza also supports team projects and any document type of submission is acceptable&amp;lt;ref&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza wiki]&amp;lt;/ref&amp;gt;. Expertiza has been deployed for years to help professors and students engaging in the learning process.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The main responsibility of SentenceState should be just to determine the state of a sentence, and another class should be in charge of knowing the parts of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism. &lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are compare_reviews_with_submissions, compare_reviews_with_questions, &lt;br /&gt;
compare_reviews_with_responses, compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81020</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81020"/>
		<updated>2013-10-30T18:35:10Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Introduction to Refactoring plagiarism_check.rb and sentence_state.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work.&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt; Expertiza also supports team projects and any document type of submission is acceptable.&amp;lt;ref&amp;gt; [http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza wiki]&amp;lt;/ref&amp;gt; Expertiza has been deployed for years to help professors and students engaging in the learning process.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The main responsibility of SentenceState should be just to determine the state of a sentence, and another class should be in charge of knowing the parts of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism. &lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are compare_reviews_with_submissions, compare_reviews_with_questions, &lt;br /&gt;
compare_reviews_with_responses, compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81014</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81014"/>
		<updated>2013-10-30T18:34:27Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work.&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt; Expertiza also supports team projects and any document type of submission is acceptable. Expertiza has been deployed for years to help professors and students engaging in the learning process.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The main responsibility of SentenceState should be just to determine the state of a sentence, and another class should be in charge of knowing the parts of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism. &lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are compare_reviews_with_submissions, compare_reviews_with_questions, &lt;br /&gt;
compare_reviews_with_responses, compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81012</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=81012"/>
		<updated>2013-10-30T18:34:10Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Introduction to Refactoring plagiarism_check.rb and sentence_state.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work.&amp;lt;ref&amp;gt; [https://github.com/expertiza/expertiza Expertiza github]&amp;lt;/ref&amp;gt; Expertiza also supports team projects and any document type of submission is acceptable. Expertiza has been deployed for years to help professors and students engaging in the learning process.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements and duplicated code. Another design smell was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The main responsibility of SentenceState should be just to determine the state of a sentence, and another class should be in charge of knowing the parts of the sentence. The worst problem was the a deeply nested if-else statement which determined the next state of the sentence clause based on the previous state and the next sentence token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between there own state and any sentence token type.&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism. &lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are compare_reviews_with_submissions, compare_reviews_with_questions, &lt;br /&gt;
compare_reviews_with_responses, compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next thing to do is extract the long loop or if-else sentence to a individual method in order to make the initial method too long or confused for others.&lt;br /&gt;
&lt;br /&gt;
Take the 1st method compare_reviews_with_submissions as example, we noticed that the this part: &lt;br /&gt;
&lt;br /&gt;
 if(array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
          rev_len+=1&lt;br /&gt;
          next&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        #generating the sentence segment you'd like to compare&lt;br /&gt;
 rev_phrase = array[rev_len]&lt;br /&gt;
&lt;br /&gt;
can be extracted and made a new method skip_empty_array, since these lines focus on the function of generating the array without backspaces to make comparisons. Once we extract the method, the initial code of the compare_reviews_with_submissions changed:&lt;br /&gt;
&lt;br /&gt;
expertiza/app/models/automated_metareview/plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
 ...&lt;br /&gt;
 review_text.each do |review_arr| #iterating through the review's sentences&lt;br /&gt;
    review = review_arr.to_s&lt;br /&gt;
    subm_text.each do |subm_arr|&lt;br /&gt;
      #iterating though the submission's sentences&lt;br /&gt;
      submission = subm_arr.to_s&lt;br /&gt;
      rev_len = 0&lt;br /&gt;
      #review's tokens, taking 'n' at a time&lt;br /&gt;
      array = review.split(&amp;quot; &amp;quot;)&lt;br /&gt;
      while(rev_len &amp;lt; array.length) do&lt;br /&gt;
        rev_len, rev_phrase = skip_empty_array(array, rev_len)&lt;br /&gt;
      ...&lt;br /&gt;
 def skip_empty_array(array, rev_len)&lt;br /&gt;
  if (array[rev_len] == &amp;quot; &amp;quot;) #skipping empty&lt;br /&gt;
    rev_len+=1&lt;br /&gt;
 end&lt;br /&gt;
  #generating the sentence segment you'd like to compare&lt;br /&gt;
  rev_phrase = array[rev_len]&lt;br /&gt;
  return rev_len, rev_phrase&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
*https://github.com/expertiza/expertiza&lt;br /&gt;
*http://wikis.lib.ncsu.edu/index.php/Expertiza&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80998</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80998"/>
		<updated>2013-10-30T18:28:23Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work. Expertiza also supports team projects and any document type of submission is acceptable. Expertiza has been deployed for years to help professors and students engaging in the learning process.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
===Design Smells===&lt;br /&gt;
The original code had several design smells, mostly deeply-nested if-else statements, and duplicated code. Another problem was that SentenceState had too many responsibilities. It had to first parse the sentence into separate sentence clauses and then separate the sentence clauses into tokens before iterating through the tokens to determine the state of the sentence. The main responsibility of SentenceState should be just to determine the state of a sentence, and another class should be in charge of knowing the parts of the sentence. The worst problem was the if-else statement which determined the next state of the sentence clause based on the previous state and the next token. Instead of the SentenceState class being responsible for all of these relationships, it is better to have subclasses of SentenceState which each know the relationship between themselves and any token type.&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism. &lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are compare_reviews_with_submissions, compare_reviews_with_questions, &lt;br /&gt;
compare_reviews_with_responses, compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
*https://github.com/expertiza/expertiza&lt;br /&gt;
*http://wikis.lib.ncsu.edu/index.php/Expertiza&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80992</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80992"/>
		<updated>2013-10-30T18:26:05Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Introduction to Refactoring plagiarism_check.rb and sentence_state.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
Expertiza is a web application, which allows students to submit assignments and do peer review of each other's work. Expertiza also supports team projects and any document type of submission is acceptable. Expertiza has been deployed for years to help professors and students engaging in the learning process.&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
To see the original code please go to this link: &lt;br /&gt;
https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
==plagiarism_check.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb,&lt;br /&gt;
&lt;br /&gt;
The 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The check_for_plagiarism method compares the review text with submission text. In this case, the review text does not quote the words as well as sentences properly and the reviewer just copies what the author says, which cause a plagiarism. &lt;br /&gt;
&lt;br /&gt;
From above point of view, the refactoring needs to be done with 4 fundamental methods and each method only does one thing correctly.  So as the initial file Plagiarism_check.rb indicates, the compare_reviews_with_questions_responses method has roughly 2 functions : compare reviews with review questions  as well as compare reviews with others’ responses, which makes us confused.  As the refactoring goes, we need to split the two functions up, and make sure such bad smells disappear.&lt;br /&gt;
&lt;br /&gt;
The first thing to do is based on the above statement, we need to define 4 methods with different functions. &lt;br /&gt;
&lt;br /&gt;
They are compare_reviews_with_submissions, compare_reviews_with_questions, &lt;br /&gt;
compare_reviews_with_responses, compare_reviews_with_google_search, each method has its specific functions.   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As showed above, we have to split the method compare_reviews_with_questions _responses up to 2 methods: &lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_questions(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 def compare_reviews_with_responses(auto_metareview, map_id)&lt;br /&gt;
 …&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
Next we need to extract the same part from the long method and make the part a individual method which can be called in class. For example in the method compare_reviews_with_questions and compare_reviews_with_responses they have the common parts: to check whether the reviews are copied fully from the responses/questions,&lt;br /&gt;
&lt;br /&gt;
 if(count_copies &amp;gt; 0) #resetting review_array only when plagiarism was found&lt;br /&gt;
       auto_metareview.review_array = rev_array&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    if(count_copies &amp;gt; 0 and count_copies == scores.length)&lt;br /&gt;
      return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
    elsif(count_copies &amp;gt; 0)&lt;br /&gt;
      return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
To avoid such things to happen, we extract this part and let it be a method to check the state of plagiarism : &lt;br /&gt;
&lt;br /&gt;
 def check_plagiarism_state(auto_metareview, count_copies, rev_array, scores)&lt;br /&gt;
   if count_copies &amp;gt; 0 #resetting review_array only when plagiarism was found&lt;br /&gt;
     auto_metareview.review_array = rev_array&lt;br /&gt;
     if count_copies == scores.length&lt;br /&gt;
       return ALL_RESPONSES_PLAGIARISED #plagiarism, with all other metrics 0&lt;br /&gt;
     else&lt;br /&gt;
       return SOME_RESPONSES_PLAGIARISED #plagiarism, while evaluating other metrics&lt;br /&gt;
     end&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza &amp;lt;ref&amp;gt; [https://github.com/shanfangshuiyuan/expertiza Expertiza fork]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Clone the git repository shown above.&lt;br /&gt;
&lt;br /&gt;
2. Use ruby 1.9.3&lt;br /&gt;
&lt;br /&gt;
3. Setup mysql and start server&lt;br /&gt;
&lt;br /&gt;
4. Command line: bundle install&lt;br /&gt;
&lt;br /&gt;
5. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
&lt;br /&gt;
6. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
&lt;br /&gt;
7. Command line: db:create:all&lt;br /&gt;
&lt;br /&gt;
8. Command line: mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
&lt;br /&gt;
9. Command line: rake db:migrate&lt;br /&gt;
&lt;br /&gt;
10. Command line: rails server&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
&lt;br /&gt;
2. Command line: db:test:prepare&lt;br /&gt;
&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
&lt;br /&gt;
4. Review the refactored files: sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview. Other changed files are shown below.&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
1. text_preprocessing.rb&lt;br /&gt;
&lt;br /&gt;
2. plagiarism_check.rb&lt;br /&gt;
&lt;br /&gt;
3. sentence_state.rb&lt;br /&gt;
&lt;br /&gt;
4. tagged_sentence.rb&lt;br /&gt;
&lt;br /&gt;
5. constants.rb&lt;br /&gt;
&lt;br /&gt;
6. negations.rb&lt;br /&gt;
&lt;br /&gt;
7. plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80954</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80954"/>
		<updated>2013-10-30T18:17:19Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction to Refactoring plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
&lt;br /&gt;
==plagiarism_test.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
the 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. If the first one does not work, please use this one. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
2. Run db:test:prepare&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
4. sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
text_preprocessing.rb&lt;br /&gt;
plagiarism_check.rb&lt;br /&gt;
sentence_state.rb&lt;br /&gt;
tagged_sentence.rb&lt;br /&gt;
constants.rb&lt;br /&gt;
negations.rb&lt;br /&gt;
plagiarism_check_test.rb&lt;br /&gt;
sentence_state_test.rb&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Use ruby 1.9.3&lt;br /&gt;
2. Setup mysql and start server&lt;br /&gt;
3. bundle install&lt;br /&gt;
4. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
5. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
6. db:create:all&lt;br /&gt;
7. mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
8. rake db:migrate&lt;br /&gt;
9. rails server&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80950</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80950"/>
		<updated>2013-10-30T18:16:34Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Refactoring — plagiarism_check.rb and sentence_state.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
&lt;br /&gt;
==plagiarism_test.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment&lt;br /&gt;
 &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
the 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
The purpose of running the VCL server is to let you make sure that expertiza is still working properly using our refactored code. The first VCL link is seeded with the expertiza-scrubbed.sql file which includes questionnaires and courses and assignments so that it is easy to verify that reviews work. You only need to make users and then have them do reviews on one another. The second link is only using the test.sql file but you can still verify that the functionality of expertiza works. If neither of these links work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
&lt;br /&gt;
2. If the first one does not work, please use this one. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
2. Run db:test:prepare&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
4. sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
text_preprocessing.rb&lt;br /&gt;
plagiarism_check.rb&lt;br /&gt;
sentence_state.rb&lt;br /&gt;
tagged_sentence.rb&lt;br /&gt;
constants.rb&lt;br /&gt;
negations.rb&lt;br /&gt;
plagiarism_check_test.rb&lt;br /&gt;
sentence_state_test.rb&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Use ruby 1.9.3&lt;br /&gt;
2. Setup mysql and start server&lt;br /&gt;
3. bundle install&lt;br /&gt;
4. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
5. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
6. db:create:all&lt;br /&gt;
7. mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
8. rake db:migrate&lt;br /&gt;
9. rails server&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80942</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80942"/>
		<updated>2013-10-30T18:13:14Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Refactoring — plagiarism_check.rb and sentence_state.rb''' =&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
&lt;br /&gt;
==plagiarism_test.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link].&lt;br /&gt;
&lt;br /&gt;
The main responsibility of Plagiarism_Check is to determine whether the reviews are just copied from other sources. &lt;br /&gt;
&lt;br /&gt;
Basically, there are four kinds of plagiarism need to be check : &lt;br /&gt;
&lt;br /&gt;
1. whether the review is copied from the submissions of the assignment &lt;br /&gt;
2. whether the review is copied from the review questions&lt;br /&gt;
3. whether the review is copied from other reviews&lt;br /&gt;
4. whether the review is copied from the Internet or other sources, this may be detected through google search&lt;br /&gt;
&lt;br /&gt;
For example, in the test file: expertiza/test/unit/automated_metareview/plagiarism_check_test.rb&lt;br /&gt;
&lt;br /&gt;
the 1st test shows:&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;check for plagiarism true match&amp;quot; do&lt;br /&gt;
    review_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
    subm_text = [&amp;quot;The sweet potatoes in the vegetable bin are green with mold. These sweet potatoes in the vegetable bin are fresh.&amp;quot;]&lt;br /&gt;
   &lt;br /&gt;
    instance = PlagiarismChecker.new&lt;br /&gt;
    assert_equal(true, instance.check_for_plagiarism(review_text, subm_text))&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
2. If the first one does not work, please use this one. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
3. If none of these work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
2. Run db:test:prepare&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
4. sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
text_preprocessing.rb&lt;br /&gt;
plagiarism_check.rb&lt;br /&gt;
sentence_state.rb&lt;br /&gt;
tagged_sentence.rb&lt;br /&gt;
constants.rb&lt;br /&gt;
negations.rb&lt;br /&gt;
plagiarism_check_test.rb&lt;br /&gt;
sentence_state_test.rb&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Use ruby 1.9.3&lt;br /&gt;
2. Setup mysql and start server&lt;br /&gt;
3. bundle install&lt;br /&gt;
4. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
5. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
6. db:create:all&lt;br /&gt;
7. mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
8. rake db:migrate&lt;br /&gt;
9. rails server&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80932</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80932"/>
		<updated>2013-10-30T18:10:25Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Refactoring — plagiarism_check.rb and sentence_state.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Refactoring — plagiarism_check.rb and sentence_state.rb''' =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
&lt;br /&gt;
==plagiarism_test.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link] :&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
2. If the first one does not work, please use this one. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
3. If none of these work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
2. Run db:test:prepare&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
4. sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
text_preprocessing.rb&lt;br /&gt;
plagiarism_check.rb&lt;br /&gt;
sentence_state.rb&lt;br /&gt;
tagged_sentence.rb&lt;br /&gt;
constants.rb&lt;br /&gt;
negations.rb&lt;br /&gt;
plagiarism_check_test.rb&lt;br /&gt;
sentence_state_test.rb&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Use ruby 1.9.3&lt;br /&gt;
2. Setup mysql and start server&lt;br /&gt;
3. bundle install&lt;br /&gt;
4. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
5. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
6. db:create:all&lt;br /&gt;
7. mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
8. rake db:migrate&lt;br /&gt;
9. rails server&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80931</id>
		<title>CSC/ECE 517 Fall 2013/oss E816 cyy</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/oss_E816_cyy&amp;diff=80931"/>
		<updated>2013-10-30T18:09:48Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Refactoring — plagiarism_check.rb and sentence_state.rb =&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
=Project description=&lt;br /&gt;
&lt;br /&gt;
=Design=&lt;br /&gt;
==sentence_state.rb==&lt;br /&gt;
&lt;br /&gt;
==plagiarism_test.rb==&lt;br /&gt;
&lt;br /&gt;
To see the original code please go to this [https://github.com/expertiza/expertiza/blob/master/app/models/automated_metareview/plagiarism_check.rb link] :&lt;br /&gt;
&lt;br /&gt;
=Test Our Code=&lt;br /&gt;
==Link to VCL==&lt;br /&gt;
1. http://152.46.20.30:3000/  Username: admin, password:password&lt;br /&gt;
2. If the first one does not work, please use this one. http://vclv99-129.hpc.ncsu.edu:3000 Username: admin, password: admin&lt;br /&gt;
3. If none of these work, please do not do your review in a hurry, shoot us an email, we will fix it as soon as possible. (yhuang25@ncsu.edu, ysun6@ncsu.edu, grimes.caroline@gmail.com). Thank you so much!&lt;br /&gt;
&lt;br /&gt;
==Test Our Code==&lt;br /&gt;
1. Set up the project following the steps above&lt;br /&gt;
2. Run db:test:prepare&lt;br /&gt;
3. Run plagiarism_check_test.rb and sentence_state_test.rb, they are under /test/unit/automated_metareview. After refactoring, all tests passed without error.&lt;br /&gt;
4. sentence_state.rb and plagiarism_check.rb are under /app/models/automated_metareview&lt;br /&gt;
&lt;br /&gt;
==Files Changed==&lt;br /&gt;
text_preprocessing.rb&lt;br /&gt;
plagiarism_check.rb&lt;br /&gt;
sentence_state.rb&lt;br /&gt;
tagged_sentence.rb&lt;br /&gt;
constants.rb&lt;br /&gt;
negations.rb&lt;br /&gt;
plagiarism_check_test.rb&lt;br /&gt;
sentence_state_test.rb&lt;br /&gt;
&lt;br /&gt;
==Steps to Setup Project==&lt;br /&gt;
1. Use ruby 1.9.3&lt;br /&gt;
2. Setup mysql and start server&lt;br /&gt;
3. bundle install&lt;br /&gt;
4. Download from http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick and copy all files from the lib folder from the download into &amp;lt;Ruby193&amp;gt;\bin&lt;br /&gt;
5. Change /config/database.yml according your mysql root password and mysql port.&lt;br /&gt;
6. db:create:all&lt;br /&gt;
7. mysql -u root -p &amp;lt;YOUR_PASSWORD&amp;gt; pg_development &amp;lt; expertiza-scrubbed_2013_07_10.sql&lt;br /&gt;
8. rake db:migrate&lt;br /&gt;
9. rails server&lt;br /&gt;
&lt;br /&gt;
==Git Forked Repository URL==&lt;br /&gt;
https://github.com/shanfangshuiyuan/expertiza&lt;br /&gt;
&lt;br /&gt;
=Future work=&lt;br /&gt;
&lt;br /&gt;
=References=&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77768</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77768"/>
		<updated>2013-09-18T15:03:36Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Branching Workflow and Remote Branching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-1. Local Version Control'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-2. Centralized Version Control System'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-3. Distributed Version Control System'''&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-4. Git's Snapshots way of thinking data'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-5. Three stages of Git for file to reside in'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 3-1. File status cycle'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
==== Check status of your file ====&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
==== Track your file ====&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
==== Staging Modified Files ====&lt;br /&gt;
&lt;br /&gt;
If you change a previously tracked file called ruby.rb and then run your status command again, you get something that looks like this:&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   modified:   ruby.rb&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
The ruby.rb file appears under a head named “Changes not staged for commit”. It means that a tracked file has been modified in the working directory but it's not yet staged. To stage it, you run the git add command.This git add command is multi-purpose.You use it to track unmodified file and stage files. Now we run git add to stage the ruby.rb file, and then run git status again:&lt;br /&gt;
&lt;br /&gt;
 $ git add ruby.rb&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #   modified:   ruby.rb&lt;br /&gt;
 #&lt;br /&gt;
Both files are staged and will go into your next commit. At this point, suppose you remember one little change that you want to make in ruby.rb before you commit it. You open it again and make that change, and you’re ready to commit. However, let’s run git status one more time:&lt;br /&gt;
&lt;br /&gt;
 $ vim benchmarks.rb&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #   modified:   ruby.rb&lt;br /&gt;
 #&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   modified:   ruby.rb&lt;br /&gt;
 #&lt;br /&gt;
Ta dah! ruby.rb is listed as both staged and unstaged. Well, Git stages a file exactly as it is when you run the git add command. If you commit now, the version of ruby.rb as it was when you last ran the git add command is how it will go into the commit, not the version of the file as it looks in your working directory when you run git commit. If you modify a file after you run git add, you have to run git add again to stage the latest version of the file:&lt;br /&gt;
&lt;br /&gt;
 $ git add ruby.rb&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #   modified:   ruby.rb&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
==== Ignoring Files ====&lt;br /&gt;
You will have a class of files that you don’t want Git to automatically add or even show you as being untracked. Those files are usually automatically generated files like log files or files produced by your build system. In such cases, you can create a file listing patterns to match them named .gitignore. Here is an example .gitignore file:&lt;br /&gt;
&lt;br /&gt;
 $ cat .gitignore&lt;br /&gt;
 *.[oa]&lt;br /&gt;
 *~&lt;br /&gt;
&lt;br /&gt;
The first line tells Git to ignore any files ending in .o or .a. Those files are object and archive files that may be the product of building your code. The second line tells Git to ignore all files that end with a tilde (~), which is used by many text editors such as Emacs to mark temporary files. You may also include a log, tmp, or pid directory; automatically generated documentation; and so on. Setting up a .gitignore file before you get going is generally a good idea so you don’t accidentally commit files that you really don’t want in your Git repository.&lt;br /&gt;
&lt;br /&gt;
==== Commit Changes ====&lt;br /&gt;
When your staging area is set up the way you want it, you can commit your changes. Anything that is still unstaged won’t go into this commit. They will stay as modified files on your disk. In this case, the last time you ran git status, you saw that everything was staged, so you’re ready to commit your changes. The simplest way to commit is to type git commit:&lt;br /&gt;
&lt;br /&gt;
  $ git commit&lt;br /&gt;
Doing so launches your editor of choice. (This is set by your shell’s $EDITOR environment variable — usually vim or emacs).&lt;br /&gt;
&lt;br /&gt;
The editor displays the following text (this example is a Vim screen):&lt;br /&gt;
&lt;br /&gt;
 # Please enter the commit message for your changes. Lines starting&lt;br /&gt;
 # with '#' will be ignored, and an empty message aborts the commit.&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #       new file:   README&lt;br /&gt;
 #       modified:   benchmarks.rb&lt;br /&gt;
 ~&lt;br /&gt;
 ~&lt;br /&gt;
 ~&lt;br /&gt;
 &amp;quot;.git/COMMIT_EDITMSG&amp;quot; 10L, 283C&lt;br /&gt;
You can see that the default commit message contains the latest output of the git status command commented out and one empty line on top. You can remove these comments and type your commit message, or you can leave them there to help you remember what you’re committing. (For an even more explicit reminder of what you’ve modified, you can pass the -v option to git commit. Doing so also puts the diff of your change in the editor so you can see exactly what you did.) When you exit the editor, Git creates your commit with that commit message (with the comments and diff stripped out).&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can type your commit message inline with the commit command by specifying it after a -m flag, like this:&lt;br /&gt;
&lt;br /&gt;
 $ git commit -m &amp;quot;Story 182: Fix benchmarks for speed&amp;quot;&lt;br /&gt;
 [master]: created 463dc4f: &amp;quot;Fix benchmarks for speed&amp;quot;&lt;br /&gt;
 2 files changed, 3 insertions(+), 0 deletions(-)&lt;br /&gt;
 create mode 100644 README&lt;br /&gt;
&lt;br /&gt;
Now you’ve created your first commit! You can see that the commit has given you some output about itself: which branch you committed to (master), what SHA-1 checksum the commit has (463dc4f), how many files were changed, and statistics about lines added and removed in the commit.&lt;br /&gt;
&lt;br /&gt;
Remember that the commit records the snapshot you set up in your staging area. Anything you didn’t stage is still sitting there modified; you can do another commit to add it to your history. Every time you perform a commit, you’re recording a snapshot of your project that you can revert to or compare to later.&lt;br /&gt;
&lt;br /&gt;
=== Commit History &amp;amp; Undo ===&lt;br /&gt;
==== View Commit History ====&lt;br /&gt;
After you have created several commits, or if you have cloned a repository with an existing commit history, you’ll probably want to look back to see what has happened. The most basic and powerful tool to do this is the git log command.&lt;br /&gt;
==== Undo ====&lt;br /&gt;
At any stage, you may want to undo something. Here, we’ll review a few basic tools for undoing changes that you’ve made. Be careful, because you can’t always revert some of these undos. This is one of the few areas in Git where you may lose some work if you do it wrong.&lt;br /&gt;
===== Change Last Commit =====&lt;br /&gt;
One of the common undos takes place when you commit too early and possibly forget to add some files, or you mess up your commit message. If you want to try that commit again, you can run commit with the --amend option:&lt;br /&gt;
&lt;br /&gt;
 $ git commit --amend&lt;br /&gt;
&lt;br /&gt;
You can type the following three commands to replace your last commit.&lt;br /&gt;
&lt;br /&gt;
 $ git commit -m 'initial commit'&lt;br /&gt;
 $ git add forgotten_file&lt;br /&gt;
 $ git commit --amend&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-5. Topic branching'''&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
*'''Local Protocol'''&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
*'''The SSH Protocol'''&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
*'''The Git Protocol'''&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
*'''The HTTP/S Protocol'''&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Git is free and powerful, which helps developers working on small to huge projects in fast speed and high efficiency. By building on snapshot data storage method, Git provides many advantages over other version control software, such as cheap branching management, convenient staging area, and many workflow options. Brief history of Git is introducted and basic operations of Git are listed and explained. To learn more about Git, please visit http://git-scm.com/.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
*http://git-scm.com/book&lt;br /&gt;
*http://en.wikipedia.org/wiki/Branching_(revision_control)&lt;br /&gt;
*http://en.wikipedia.org/wiki/Merge_(revision_control)&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77404</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77404"/>
		<updated>2013-09-18T02:21:27Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Record Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-1. Local Version Control'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-2. Centralized Version Control System'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-3. Distributed Version Control System'''&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-4. Git's Snapshots way of thinking data'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-5. Three stages of Git for file to reside in'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 3-1. File status cycle'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
*'''Local Protocol'''&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
*'''The SSH Protocol'''&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
*'''The Git Protocol'''&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
*'''The HTTP/S Protocol'''&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Git is free and powerful, which helps developers working on small to huge projects in fast speed and high efficiency. By building on snapshot data storage method, Git provides many advantages over other version control software, such as cheap branching management, convenient staging area, and many workflow options. Brief history of Git is introducted and basic operations of Git are listed and explained. To learn more about Git, please visit http://git-scm.com/.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
*http://git-scm.com/book&lt;br /&gt;
*http://en.wikipedia.org/wiki/Branching_(revision_control)&lt;br /&gt;
*http://en.wikipedia.org/wiki/Merge_(revision_control)&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77402</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77402"/>
		<updated>2013-09-18T02:20:12Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* What is Git */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-1. Local Version Control'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-2. Centralized Version Control System'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-3. Distributed Version Control System'''&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-4. Git's Snapshots way of thinking data'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-5. Three stages of Git for file to reside in'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
*'''Local Protocol'''&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
*'''The SSH Protocol'''&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
*'''The Git Protocol'''&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
*'''The HTTP/S Protocol'''&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Git is free and powerful, which helps developers working on small to huge projects in fast speed and high efficiency. By building on snapshot data storage method, Git provides many advantages over other version control software, such as cheap branching management, convenient staging area, and many workflow options. Brief history of Git is introducted and basic operations of Git are listed and explained. To learn more about Git, please visit http://git-scm.com/.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
*http://git-scm.com/book&lt;br /&gt;
*http://en.wikipedia.org/wiki/Branching_(revision_control)&lt;br /&gt;
*http://en.wikipedia.org/wiki/Merge_(revision_control)&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77399</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77399"/>
		<updated>2013-09-18T02:18:48Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* What is Git */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-1. Local Version Control'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-2. Centralized Version Control System'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-3. Distributed Version Control System'''&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-4. Git's Snapshots way of thinking data'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
*'''Local Protocol'''&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
*'''The SSH Protocol'''&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
*'''The Git Protocol'''&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
*'''The HTTP/S Protocol'''&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Git is free and powerful, which helps developers working on small to huge projects in fast speed and high efficiency. By building on snapshot data storage method, Git provides many advantages over other version control software, such as cheap branching management, convenient staging area, and many workflow options. Brief history of Git is introducted and basic operations of Git are listed and explained. To learn more about Git, please visit http://git-scm.com/.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
*http://git-scm.com/book&lt;br /&gt;
*http://en.wikipedia.org/wiki/Branching_(revision_control)&lt;br /&gt;
*http://en.wikipedia.org/wiki/Merge_(revision_control)&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77398</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77398"/>
		<updated>2013-09-18T02:17:56Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Version Control System */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-1. Local Version Control'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-2. Centralized Version Control System'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-3. Distributed Version Control System'''&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
*'''Local Protocol'''&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
*'''The SSH Protocol'''&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
*'''The Git Protocol'''&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
*'''The HTTP/S Protocol'''&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Git is free and powerful, which helps developers working on small to huge projects in fast speed and high efficiency. By building on snapshot data storage method, Git provides many advantages over other version control software, such as cheap branching management, convenient staging area, and many workflow options. Brief history of Git is introducted and basic operations of Git are listed and explained. To learn more about Git, please visit http://git-scm.com/.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
*http://git-scm.com/book&lt;br /&gt;
*http://en.wikipedia.org/wiki/Branching_(revision_control)&lt;br /&gt;
*http://en.wikipedia.org/wiki/Merge_(revision_control)&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77397</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77397"/>
		<updated>2013-09-18T02:17:40Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Version Control System */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-1. Local Version Control'''&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-2. Centralized Version Control System'''&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 1-3. Distributed Version Control System'''&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
*'''Local Protocol'''&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
*'''The SSH Protocol'''&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
*'''The Git Protocol'''&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
*'''The HTTP/S Protocol'''&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Git is free and powerful, which helps developers working on small to huge projects in fast speed and high efficiency. By building on snapshot data storage method, Git provides many advantages over other version control software, such as cheap branching management, convenient staging area, and many workflow options. Brief history of Git is introducted and basic operations of Git are listed and explained. To learn more about Git, please visit http://git-scm.com/.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
*http://git-scm.com/book&lt;br /&gt;
*http://en.wikipedia.org/wiki/Branching_(revision_control)&lt;br /&gt;
*http://en.wikipedia.org/wiki/Merge_(revision_control)&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77396</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77396"/>
		<updated>2013-09-18T02:16:55Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Version Control System */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
&lt;br /&gt;
Figure 1-1. Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
&lt;br /&gt;
Figure 1-2. Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
&lt;br /&gt;
Figure 1-3. Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
*'''Local Protocol'''&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
*'''The SSH Protocol'''&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
*'''The Git Protocol'''&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
*'''The HTTP/S Protocol'''&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Git is free and powerful, which helps developers working on small to huge projects in fast speed and high efficiency. By building on snapshot data storage method, Git provides many advantages over other version control software, such as cheap branching management, convenient staging area, and many workflow options. Brief history of Git is introducted and basic operations of Git are listed and explained. To learn more about Git, please visit http://git-scm.com/.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
*http://git-scm.com/book&lt;br /&gt;
*http://en.wikipedia.org/wiki/Branching_(revision_control)&lt;br /&gt;
*http://en.wikipedia.org/wiki/Merge_(revision_control)&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77395</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77395"/>
		<updated>2013-09-18T02:16:42Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Version Control System */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
&lt;br /&gt;
Figure 1-1. Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
&lt;br /&gt;
Figure 1-2. Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
&lt;br /&gt;
Figure 1-3. Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
*'''Local Protocol'''&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
*'''The SSH Protocol'''&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
*'''The Git Protocol'''&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
*'''The HTTP/S Protocol'''&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Git is free and powerful, which helps developers working on small to huge projects in fast speed and high efficiency. By building on snapshot data storage method, Git provides many advantages over other version control software, such as cheap branching management, convenient staging area, and many workflow options. Brief history of Git is introducted and basic operations of Git are listed and explained. To learn more about Git, please visit http://git-scm.com/.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
*http://git-scm.com/book&lt;br /&gt;
*http://en.wikipedia.org/wiki/Branching_(revision_control)&lt;br /&gt;
*http://en.wikipedia.org/wiki/Merge_(revision_control)&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77390</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77390"/>
		<updated>2013-09-18T02:13:00Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
*'''Local Protocol'''&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
*'''The SSH Protocol'''&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
*'''The Git Protocol'''&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
*'''The HTTP/S Protocol'''&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Git is free and powerful, which helps developers working on small to huge projects in fast speed and high efficiency. By building on snapshot data storage method, Git provides many advantages over other version control software, such as cheap branching management, convenient staging area, and many workflow options. Brief history of Git is introducted and basic operations of Git are listed and explained. To learn more about Git, please visit http://git-scm.com/.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
*http://git-scm.com/book&lt;br /&gt;
*http://en.wikipedia.org/wiki/Branching_(revision_control)&lt;br /&gt;
*http://en.wikipedia.org/wiki/Merge_(revision_control)&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77388</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77388"/>
		<updated>2013-09-18T02:11:52Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
*'''Local Protocol'''&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
*'''The SSH Protocol'''&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
*'''The Git Protocol'''&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
*'''The HTTP/S Protocol'''&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Git is free and powerful, which helps developers working on small to huge projects in fast speed and high efficiency. By building on snapshot data storage method, Git provides many advantages over other version control software. Brief history of Git is introducted and basic operations of Git are listed and explained. To learn more about Git, please visit http://git-scm.com/.&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
*http://git-scm.com/book&lt;br /&gt;
*http://en.wikipedia.org/wiki/Branching_(revision_control)&lt;br /&gt;
*http://en.wikipedia.org/wiki/Merge_(revision_control)&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77377</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77377"/>
		<updated>2013-09-18T02:02:34Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Reference */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
*'''Local Protocol'''&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
*'''The SSH Protocol'''&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
*'''The Git Protocol'''&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
*'''The HTTP/S Protocol'''&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;br /&gt;
*http://git-scm.com/book&lt;br /&gt;
*http://en.wikipedia.org/wiki/Branching_(revision_control)&lt;br /&gt;
*http://en.wikipedia.org/wiki/Merge_(revision_control)&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77372</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77372"/>
		<updated>2013-09-18T02:00:05Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* On the Server */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
*'''Local Protocol'''&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
*'''The SSH Protocol'''&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
*'''The Git Protocol'''&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
*'''The HTTP/S Protocol'''&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77369</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77369"/>
		<updated>2013-09-18T01:57:16Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* On the Server */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
====Local Protocol====&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
====The SSH Protocol====&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
====The Git Protocol====&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
====The HTTP/S Protocol====&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Reference==&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77367</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77367"/>
		<updated>2013-09-18T01:56:12Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Public Access */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
====Local Protocol====&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
====The SSH Protocol====&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
====The Git Protocol====&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
====The HTTP/S Protocol====&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, change the Unix user group of /opt/git to www-data to have your web server has read-access to the repositories.&lt;br /&gt;
&lt;br /&gt;
 $ chgrp -R www-data /opt/git&lt;br /&gt;
&lt;br /&gt;
After restarting your Apache, you can clone your repositories:&lt;br /&gt;
&lt;br /&gt;
 $ git clone http://git.gitserver/project.git&lt;br /&gt;
&lt;br /&gt;
In this way, a HTTP-based read access to your projects with a number of users can be setup within minutes.&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77366</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77366"/>
		<updated>2013-09-18T01:52:43Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Public Access/Git Web */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
====Local Protocol====&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
====The SSH Protocol====&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
====The Git Protocol====&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
====The HTTP/S Protocol====&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access===&lt;br /&gt;
Sometimes you may want host an open source project and allow anonymous read access to your project. Without having to generate SSH keys all the time, the easiest way of smaller setup is to run a static web server with Git repositories under its document root, and then enable the post-update hook.&lt;br /&gt;
&lt;br /&gt;
To enable the hook:&lt;br /&gt;
&lt;br /&gt;
 $ cd project.git&lt;br /&gt;
 $ mv hooks/post-update.sample hooks/post-update&lt;br /&gt;
 $ chmod a+x hooks/post-update&lt;br /&gt;
&lt;br /&gt;
Next, a VirtualHost entry with the document root serves as the root directory should be added to your Apache configuration of your Git projects.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
     ServerName git.gitserver&lt;br /&gt;
     DocumentRoot /opt/git&lt;br /&gt;
     &amp;lt;Directory /opt/git/&amp;gt;&lt;br /&gt;
         Order allow, deny&lt;br /&gt;
         allow from all&lt;br /&gt;
     &amp;lt;/Directory&amp;gt;&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77358</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77358"/>
		<updated>2013-09-18T01:32:45Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Set up Server */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
====Local Protocol====&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
====The SSH Protocol====&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
====The Git Protocol====&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
====The HTTP/S Protocol====&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Public Access/Git Web ===&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77356</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77356"/>
		<updated>2013-09-18T01:29:59Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Getting Git on the Server and Generate Public SSH Key */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
====Local Protocol====&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
====The SSH Protocol====&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
====The Git Protocol====&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
====The HTTP/S Protocol====&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
===Generate Public SSH Key===&lt;br /&gt;
SSH public key is used for Git server authenticate. Each user of the system should have one SSH key. You can check whether you have a SSH key by:&lt;br /&gt;
&lt;br /&gt;
 $ cd ~/.ssh&lt;br /&gt;
 $ ls&lt;br /&gt;
 authorized_keys2  id_dsa       known_hosts&lt;br /&gt;
 config            id_dsa.pub&lt;br /&gt;
&lt;br /&gt;
The files are named something and something.pub are what you should look for. The .pub file contains your public key and the other one has your private key. If you do not have them, you can run ssh-keygen to get them.&lt;br /&gt;
&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key (/Users/schacon/.ssh/id_rsa):&lt;br /&gt;
 Enter passphrase (empty for no passphrase):&lt;br /&gt;
 Enter same passphrase again:&lt;br /&gt;
 Your identification has been saved in /Users/schacon/.ssh/id_rsa.&lt;br /&gt;
 Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub.&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local&lt;br /&gt;
&lt;br /&gt;
Each user should send their public key to the administrator of the Git server.&lt;br /&gt;
&lt;br /&gt;
=== Set up Server ===&lt;br /&gt;
&lt;br /&gt;
=== Public Access/Git Web ===&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77353</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77353"/>
		<updated>2013-09-18T01:24:28Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Putting Git on the Server and Generate Public SSH Key */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
====Local Protocol====&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
====The SSH Protocol====&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
====The Git Protocol====&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
====The HTTP/S Protocol====&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Getting Git on the Server and Generate Public SSH Key ===&lt;br /&gt;
To getting git on a server, the first you need to do is to clone a existing repository into a new bare repository. Using the command:&lt;br /&gt;
&lt;br /&gt;
 $ git clone --bare my_project my_project.git&lt;br /&gt;
 Initialized empty Git repository in /opt/projects/my_project.git/&lt;br /&gt;
&lt;br /&gt;
Now you need to put your bare repository on the server and set up your protocols. Assume your server is called &amp;quot;git.example.com&amp;quot;, and to store your Git repositories under /opt/git. The command to set up your new repository is:&lt;br /&gt;
&lt;br /&gt;
 $ scp -r my_project.git user@git.example.com:/opt/git&lt;br /&gt;
&lt;br /&gt;
=== Set up Server ===&lt;br /&gt;
&lt;br /&gt;
=== Public Access/Git Web ===&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77352</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77352"/>
		<updated>2013-09-18T01:17:12Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* The HTTP/S Protocol */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
====Local Protocol====&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
====The SSH Protocol====&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
====The Git Protocol====&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
====The HTTP/S Protocol====&lt;br /&gt;
HTTP/S protocol is simple to set up, that just putting the bare Git repository under your HTTP document root and then set up a specific post-update hook is all you need to do. HTTPS can be used to serve read-only repositories with content encrypted. HTTP/S also provides better cooperation with firewalls because it is widely used.&lt;br /&gt;
&lt;br /&gt;
The disadvantage of HTTP/S is that it is relatively not efficient for client.&lt;br /&gt;
&lt;br /&gt;
=== Putting Git on the Server and Generate Public SSH Key ===&lt;br /&gt;
&lt;br /&gt;
=== Set up Server ===&lt;br /&gt;
&lt;br /&gt;
=== Public Access/Git Web ===&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77350</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77350"/>
		<updated>2013-09-18T01:10:29Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* The Git Protocol */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
====Local Protocol====&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
====The SSH Protocol====&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
====The Git Protocol====&lt;br /&gt;
The Git protocol is packaged with Git and is a special daemon. Git protocol provides similar service with SSH but without authentication.&lt;br /&gt;
&lt;br /&gt;
Git protocol is the fastest transfer protocol. It is useful in traffic heavy public projects. However, Git protocol does not provide authentication. Git protocol is also the most difficult protocol to set up.&lt;br /&gt;
&lt;br /&gt;
====The HTTP/S Protocol====&lt;br /&gt;
&lt;br /&gt;
=== Putting Git on the Server and Generate Public SSH Key ===&lt;br /&gt;
&lt;br /&gt;
=== Set up Server ===&lt;br /&gt;
&lt;br /&gt;
=== Public Access/Git Web ===&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77349</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77349"/>
		<updated>2013-09-18T01:06:12Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Protocols */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
====Local Protocol====&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
====The SSH Protocol====&lt;br /&gt;
The SSH protocol is the most commonly used transport protocol. In most cases, the SSH access has already been set up and the setting process is also easy. SSH supports read and write while other network protocols do not.&lt;br /&gt;
&lt;br /&gt;
There are many pros of SSH protocol. First, you can have authenticated write access. Second, it is easy to set up. Third, SSH provides security guarantee that all data transferred are encrypted and authenticated.&lt;br /&gt;
&lt;br /&gt;
The cons of SSH is that SSH is not suitable for open source projects that people must have access to your machine and you cannot serve anonymous.&lt;br /&gt;
&lt;br /&gt;
====The Git Protocol====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====The HTTP/S Protocol====&lt;br /&gt;
&lt;br /&gt;
=== Putting Git on the Server and Generate Public SSH Key ===&lt;br /&gt;
&lt;br /&gt;
=== Set up Server ===&lt;br /&gt;
&lt;br /&gt;
=== Public Access/Git Web ===&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77346</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77346"/>
		<updated>2013-09-18T00:59:09Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Protocols */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
====Local Protocol====&lt;br /&gt;
Local protocol is the most basic method. In this case, remote repository is on the same disk but different directory. Local protocol is used when a file system is shared with every developers or everyone logs into the same computer. In the previous case, you can clone, push and pull from a local repository.&lt;br /&gt;
&lt;br /&gt;
The pros of local protocol is it is easy to set up a repository with a shared file system and also convenient to grab others work. The cons of shared access is more difficult to set up and it is not always the fastest option.&lt;br /&gt;
&lt;br /&gt;
====The SSH Protocol====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====The Git Protocol====&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====The HTTP/S Protocol====&lt;br /&gt;
&lt;br /&gt;
=== Putting Git on the Server and Generate Public SSH Key ===&lt;br /&gt;
&lt;br /&gt;
=== Set up Server ===&lt;br /&gt;
&lt;br /&gt;
=== Public Access/Git Web ===&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77338</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77338"/>
		<updated>2013-09-18T00:48:42Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Protocols */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
To transfer data in Git, four protocols can be used: Local, Secure Shell(SSH), Git, and HTTP.&lt;br /&gt;
&lt;br /&gt;
====Local Protocol====&lt;br /&gt;
&lt;br /&gt;
=== Putting Git on the Server and Generate Public SSH Key ===&lt;br /&gt;
&lt;br /&gt;
=== Set up Server ===&lt;br /&gt;
&lt;br /&gt;
=== Public Access/Git Web ===&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77333</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77333"/>
		<updated>2013-09-18T00:36:01Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* On the Server */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
Git server is an intermediate repository that all co-developers have access to and can push to and pull from.&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
&lt;br /&gt;
=== Putting Git on the Server and Generate Public SSH Key ===&lt;br /&gt;
&lt;br /&gt;
=== Set up Server ===&lt;br /&gt;
&lt;br /&gt;
=== Public Access/Git Web ===&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77331</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77331"/>
		<updated>2013-09-18T00:32:09Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Branching Workflow and Remote Branching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
The branches stored in remote repositories are called remote branches. They can only be moved by using network communication. &lt;br /&gt;
&lt;br /&gt;
Pushing is used when you want to share your branch with others. You can push your branch to a remote. The remote branch cannot be updated automatically, you need to explicitly push to update it.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
&lt;br /&gt;
=== Putting Git on the Server and Generate Public SSH Key ===&lt;br /&gt;
&lt;br /&gt;
=== Set up Server ===&lt;br /&gt;
&lt;br /&gt;
=== Public Access/Git Web ===&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77285</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77285"/>
		<updated>2013-09-18T00:01:43Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Branching Workflow and Remote Branching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review. The diagram to show the topic branch is Figure 4-5.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_branch.png]]&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
&lt;br /&gt;
=== Putting Git on the Server and Generate Public SSH Key ===&lt;br /&gt;
&lt;br /&gt;
=== Set up Server ===&lt;br /&gt;
&lt;br /&gt;
=== Public Access/Git Web ===&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Topic_branch.png&amp;diff=77283</id>
		<title>File:Topic branch.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Topic_branch.png&amp;diff=77283"/>
		<updated>2013-09-18T00:00:47Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77282</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w6 zs</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w6_zs&amp;diff=77282"/>
		<updated>2013-09-18T00:00:15Z</updated>

		<summary type="html">&lt;p&gt;Ysun6: /* Branching Workflow and Remote Branching */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2013/ch1w6 zs&lt;br /&gt;
&lt;br /&gt;
=Synopsis of Git book=&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
Git is by far the best Version Control System on the market and it's free.&lt;br /&gt;
&lt;br /&gt;
=== Version Control System ===&lt;br /&gt;
Version control system is a system that keeps track of changes to a set of files for a certain project. You can recall all specific versions of your file later. Actually any file on your computer is placed under version control.  A VCS allows you to revert file to a previous version or even revert the whole project back to a certain version.  It allows you to see what when changes are made and who modified it. It also allows you to recover yourself easily from a messed up project.&lt;br /&gt;
&lt;br /&gt;
Generally, there are three kinds of [http://en.wikipedia.org/wiki/Revision_control version control system], which are local, centralized and distributed VCSs. Figures are illustrated below.&lt;br /&gt;
[[File:Local VCS.png ]]&lt;br /&gt;
Local Version Control&lt;br /&gt;
&lt;br /&gt;
[[File:Centrailized VCS.png]]&lt;br /&gt;
Centralized Version Control System&lt;br /&gt;
&lt;br /&gt;
[[File:Distributed VCS.png]]&lt;br /&gt;
Distributed Version Control System&lt;br /&gt;
&lt;br /&gt;
=== History ===&lt;br /&gt;
Git  was born with a bit of creative destruction and fiery controversy. The linux kernel , which is an open-source software project, kept its changes as patches and archived files from 1991 to 2002 and since 2002. The project switched to a Distributed VCS called BitKeeper.&lt;br /&gt;
 &lt;br /&gt;
When things between the community that developed linux kernel and the commercial company that developed  Bitkeeper went bad. The free version of the BitKeeper was revoked and this prompt the community that developed Linux kernel to develop their own tools. And that is the origin of Git.&lt;br /&gt;
&lt;br /&gt;
For over 7 years since its birth in 2005, Git has matured and it’s now handy to use while keeping the good qualities. It's especially efficient for large projects and it has a amazing branching system(another link here for branching ) for non-linear development .&lt;br /&gt;
&lt;br /&gt;
=== What is Git ===&lt;br /&gt;
Git stores ,process and thinks about information in a different way than any other VCS. Systems like CVS deals with the information they hold as a set of files and changes made to each single file over time. But Git doesn't do it this way.Git takes your file more like a series of snapshots. Every time you commit or save your file, Git takes a snapshot of all your files. And to avoid unnecessary memory consumption , those files that stay unchanged are stored as a link to its previous real version. Illustrated as below.&lt;br /&gt;
&lt;br /&gt;
[[File:snapshots.png]]&lt;br /&gt;
Git's Snapshots way of thinking data&lt;br /&gt;
&lt;br /&gt;
This is a huge difference between Git and other VCSs, actually nearly all other VCSs. Git take care of very aspect of version control at a minimum cost.It's more like a set of mini file system with lots of advanced tools built in.&lt;br /&gt;
&lt;br /&gt;
Most operation in Git is local and no data or information is needed on another computer. You always have an entire history of your project on your local computer. It's so efficient that most operations seems instant. That means you can browse your entire project history on you local database almost instantaneous. Git can look up a file no matter how long ago and compare it with your current version with diff calculation.When you are offline , you can easily make changes to your projects and commit the change once you are connected to the internet. Besides that, if you are off VPN, you can still work. Although it seems trivial, this will make a huge difference.&lt;br /&gt;
  &lt;br /&gt;
Everything you do on Git is known to Git. You won't lose lose anything or get file corruption before Git detecting it. This is done by adopting checksumming using SHA-1 hash. It's a 40 character string composed of hex characters. Git stores everything in the Git database addressable by the hash value of its contents, other than file name.   &lt;br /&gt;
&lt;br /&gt;
Generally Git only adds data to Git database. After committing a snapshot into Git database, it's very hard to lose data. This is especially secured if you regularly push Git database into another repo.&lt;br /&gt;
&lt;br /&gt;
Important: Git has three states for a file to reside in, which are committed, staged and modified.Committed means that your file is safe and sound in Git database. Modified means that you have changed the file but it's not committed into database yet.Staged means that you mark a modified file in its current version and ready for the next snapshots. It's like cache. The three states and their connection is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:Three States.png]]&lt;br /&gt;
&lt;br /&gt;
The repo is where Git stores data for your project.When you clone a repo from another computer, this is the thing copied.&lt;br /&gt;
The working directory is a simple check out for your current version of files.The files on working directory are pulled out of repo and put on disk for you to manipulate.&lt;br /&gt;
The staging area is a simple file which is contained in repo. It stores information that will go into the commit stage.&lt;br /&gt;
&lt;br /&gt;
Generally, the follow three steps are how Git works:&lt;br /&gt;
&lt;br /&gt;
1.You modify files in your working directory.&lt;br /&gt;
&lt;br /&gt;
2.You stage the files, adding snapshots of them to your staging area.&lt;br /&gt;
&lt;br /&gt;
3.You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.&lt;br /&gt;
&lt;br /&gt;
== Getting Started on Git ==&lt;br /&gt;
=== Installing Git ===&lt;br /&gt;
First thing to use Git is to install it. You can either install it from sources or installing package on your platform(Win, Mac and Linux)&lt;br /&gt;
==== Install from Source ====&lt;br /&gt;
One of the advantage of installing from source is you always get the latest version. Each version of Git tend to add some UI enhancement and it will be comfy to compile on that. To start with, there are some must-have libraries that Git depends on, such as curl, zlib, openssl, expat and libiconv.If your system has yum (such as Fedora) or apt-get (such as a Debian based system), then you can use the one of the commands below to install the all the dependencies. &lt;br /&gt;
 $ yum install curl-devel expat-devel gettext-devel \&lt;br /&gt;
  openssl-devel zlib-devel&lt;br /&gt;
&lt;br /&gt;
 $ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \&lt;br /&gt;
  libz-dev libssl-dev&lt;br /&gt;
&lt;br /&gt;
Once this is done, you can go ahead and download the latest version of Git&lt;br /&gt;
&lt;br /&gt;
  http://git-scm.com/download&lt;br /&gt;
&lt;br /&gt;
And then, compile and install&lt;br /&gt;
&lt;br /&gt;
 $ tar -zxf git-1.7.2.2.tar.gz&lt;br /&gt;
 $ cd git-1.7.2.2&lt;br /&gt;
 $ make prefix=/usr/local all&lt;br /&gt;
 $ sudo make prefix=/usr/local install&lt;br /&gt;
&lt;br /&gt;
After this is done, Git is already installed on your local computer. You can use the following command to update your Git to latest version.&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.org/pub/scm/git/git.git&lt;br /&gt;
&lt;br /&gt;
==== Install on Linux ====&lt;br /&gt;
It's way much easier to install Git on Linux. If you are on Fedora, you can use the following yum &lt;br /&gt;
 $ yum install git-core&lt;br /&gt;
If you are on a Debian-based distribution like Ubuntu, use apt-get&lt;br /&gt;
 $ apt-get install git&lt;br /&gt;
&lt;br /&gt;
==== Install on Windows ====&lt;br /&gt;
Suprisingly,it's very east to install Git on Windows. Download the Git installer exe file from Github page and run it. &lt;br /&gt;
 http://msysgit.github.com/&lt;br /&gt;
After installing on windows, you will have both command-line and GUI version.It is suggested that windows users to use msysGit shell, which supports many complex commands.&lt;br /&gt;
&lt;br /&gt;
=== First time set-up===&lt;br /&gt;
You may want to customize your Git environment once and for all. It will persist after each upgrade and you can also make changes to your settings using the commands again.&lt;br /&gt;
&lt;br /&gt;
A tool called git config is built in on Git , it allows you to get and set configs that control all things about how Git looks and runs.The config variables are stored in three different places:&lt;br /&gt;
&lt;br /&gt;
1. /etc/gitconfig file:  Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.&lt;br /&gt;
&lt;br /&gt;
2. ~/.gitconfig file:  Specific to your user. You can make Git read and write to this file specifically by passing the --global option.&lt;br /&gt;
&lt;br /&gt;
3. config file in the git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository. Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.&lt;br /&gt;
&lt;br /&gt;
==== Identity, Editor, Diff tool and Check ====&lt;br /&gt;
You should set your user name and email address once you get your Git installed. Every Git commits uses this info and it's etched in your commits.&lt;br /&gt;
 $ git config --global user.name &amp;quot;John Doe&amp;quot;&lt;br /&gt;
 $ git config --global user.email johndoe@example.com&lt;br /&gt;
Because you passed the --global option, you only need to do this once.&lt;br /&gt;
&lt;br /&gt;
You can config your default editor when Git asks you to type any message. If you want to use another editor other than your system's default editor like emacs, you can use the following command. Usually it's Vi or Vim by default.&lt;br /&gt;
 $ git config --global core.editor emacs&lt;br /&gt;
&lt;br /&gt;
You will want to use diff tools for detecting and resolving emerge conflicts.There are many diff tools and let's assume you want to use vimdiff, you should type the following command&lt;br /&gt;
 $ git config --global merge.tool vimdiff&lt;br /&gt;
Git also accept kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.&lt;br /&gt;
&lt;br /&gt;
If you want to check your settings, Git has provided a --list option for you to view all your settings. By typing &amp;quot;git config --list&amp;quot;, you will get the following:&lt;br /&gt;
 $ git config --list&lt;br /&gt;
 user.name=Scott Chacon&lt;br /&gt;
 user.email=schacon@gmail.com&lt;br /&gt;
 color.status=auto&lt;br /&gt;
 color.branch=auto&lt;br /&gt;
 color.interactive=auto&lt;br /&gt;
 color.diff=auto&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=== Get help from Git ===&lt;br /&gt;
 If you ever need help while using Git, there are three ways to get the manual page help for any of the Git commands:&lt;br /&gt;
 $ git help &amp;lt;verb&amp;gt;&lt;br /&gt;
 $ git &amp;lt;verb&amp;gt; --help&lt;br /&gt;
 $ man git-&amp;lt;verb&amp;gt;&lt;br /&gt;
For example, you can get the manpage help for the config command by running&lt;br /&gt;
 $ git help config&lt;br /&gt;
These commands are nice because you can access them anywhere, even offline. If the manual pages and this book aren’t enough and you need in-person help, you can try the #git or #github channel on the Freenode IRC server (irc.freenode.net). These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.&lt;br /&gt;
&lt;br /&gt;
== Basic Operation on Git ==&lt;br /&gt;
To initiate a Git repository , you generally have two ways. One is using an existing project or directory and imports it into Git. The other is to clone an existing Git repo from another server.&lt;br /&gt;
=== Initializing a Repository in an Existing Directory ===&lt;br /&gt;
&lt;br /&gt;
If you’re starting to track an existing project in Git, you need to go to the project’s directory and type&lt;br /&gt;
 $ git init&lt;br /&gt;
This creates a new subdirectory named .git that contains all of your necessary repository files, which is a Git repository skeleton. At this point, nothing in your project is tracked yet. &lt;br /&gt;
&lt;br /&gt;
If you want to start version-controlling existing files (as opposed to an empty directory), you should probably begin tracking those files and do an initial commit. You can accomplish that with a few git add commands that specify the files you want to track, followed by a commit:&lt;br /&gt;
&lt;br /&gt;
 $ git add *.c&lt;br /&gt;
 $ git add README&lt;br /&gt;
 $ git commit -m 'initial project version'&lt;br /&gt;
At this point, you have a Git repository with tracked files and an initial commit.&lt;br /&gt;
&lt;br /&gt;
=== Cloning an Existing Repo ===&lt;br /&gt;
If you want to copy from an existing Git repository , for example, a project you want to contribute to . The command you need is &amp;quot;git clone&amp;quot;.  Git receives a copy of nearly all data that the server has. Every version of every file for the history of the project is pulled down when you run git clone. &lt;br /&gt;
&lt;br /&gt;
To clone a repository , you should use git clone [url]. For example, if you want to clone the Ruby Git library called Ruby, you can do so like this:&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git&lt;br /&gt;
That creates a directory named grit, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new grit directory, you’ll see the project files in there, ready to be worked on or used. If you want to clone the repository into a directory named something other than grit, you can specify that as the next command-line option:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://github.com/schacon/ruby.git ruby&lt;br /&gt;
That command does the same thing as the previous one, but the target directory is called myruby.&lt;br /&gt;
&lt;br /&gt;
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or user@server:/path.git, which uses the SSH transfer protocol. It will be discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
=== Record Changes ===&lt;br /&gt;
Now we have a repo of the project , we can start to make changes and commit the changes into repo each time you think appropriate to mark a milestone.&lt;br /&gt;
&lt;br /&gt;
Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else. Any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because you just checked them out and haven’t edited anything.&lt;br /&gt;
&lt;br /&gt;
As you edit files, Git sees them as modified, because you’ve changed them since your last commit. You stage these modified files and then commit all your staged changes, and the cycle repeats. This cycle is illustrated in the figure below.&lt;br /&gt;
&lt;br /&gt;
[[File:cycle.png]]&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;quot;git status&amp;quot; to check the status of each file.Assuming you add a simple README file to your project and the file didn't exist before. When you run &amp;quot;git status&amp;quot; ,you can see this untracked file like this in below:&lt;br /&gt;
&lt;br /&gt;
 $ vim README&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Untracked files:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 #&lt;br /&gt;
 #   README&lt;br /&gt;
 nothing added to commit but untracked files present (use &amp;quot;git add&amp;quot; to track)&lt;br /&gt;
&lt;br /&gt;
Your new file is in the &amp;quot;untracked file&amp;quot; output. It means that Git doesn't find it in any previous snapshots and if you want Git to include it, you have to explicitly tell him so. &lt;br /&gt;
&lt;br /&gt;
To track a new file like the README file you just added, you can use the command &amp;quot;git add&amp;quot; like this &lt;br /&gt;
 $ git add README&lt;br /&gt;
Then you can run your status command again and you will get the following:&lt;br /&gt;
 $ git status&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes to be committed:&lt;br /&gt;
 #   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 #&lt;br /&gt;
 #   new file:   README&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
It’s under the “Changes to be committed” heading.If you commit now, this version of the file will be in the snapshot if you run git add. The git add command takes both file name or directory name.If it's a directory, the command will adds all the files in that directory recursively.&lt;br /&gt;
&lt;br /&gt;
=== Commit History ===&lt;br /&gt;
=== Undo ===&lt;br /&gt;
=== Work Remotely with Git ===&lt;br /&gt;
=== Tag ===&lt;br /&gt;
=== Tips ===&lt;br /&gt;
&lt;br /&gt;
== Branching ==&lt;br /&gt;
&lt;br /&gt;
=== Introduction for Branching ===&lt;br /&gt;
Branching is a concept inn area of version control software, which allows users to duplicate source code and doing development parallel among different branches at the same time without messing up. Branching makes Git more special because of its extremely lightweight compared to other version control software. Branching in Git is fast and flexible. To development fast and powerful, it is important to master this feature.&lt;br /&gt;
&lt;br /&gt;
Git stores data in a series of snapshots. Every commit in Git stores a pointer to any commit that came earlier. Similarly, a branch in Git is also a pointer to one commit. &amp;quot;Master&amp;quot; is the default name for branching. It is used when you first make commits, and it is always points to the last commit when more commits happen later.&lt;br /&gt;
&lt;br /&gt;
[[File:Master_branch.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-1. Master branching pointing to commit history'''&lt;br /&gt;
&lt;br /&gt;
The command '''''git branch''''' is used to create a new branch, which creates a new pointer into the current commit.&lt;br /&gt;
&lt;br /&gt;
 $ git branch test&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' is a special pointer which helps git to remember the current branch. '''''git branch''''' only creates a new branch without switching branching. Thus, you are still on the master branch. To switch branch, '''''git checkout''''' is used. The following command is for switching to the new test branch. It moves the '''HEAD''' pointer into the test branch.&lt;br /&gt;
&lt;br /&gt;
 $ git checkout test&lt;br /&gt;
&lt;br /&gt;
At this time, when more commits happen, branch test that '''HEAD''' points to moves forward with new commits. However, branch master still points to the commit when we use '''''git checkout''''' to switch the branch as shown in Figure 4-2.&lt;br /&gt;
&lt;br /&gt;
[[File:HEAD_move.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-2. Pointer HEAD moves to another branch on command checkout'''&lt;br /&gt;
&lt;br /&gt;
'''HEAD''' points to the current branch and the current branch points into the working directory. If we continue to make some changes and commits, the changes made at this point will diverge from the old version of the project as shown in Figure 4-3.&lt;br /&gt;
&lt;br /&gt;
[[File:Branch_diverge.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-3. Branch diverged'''&lt;br /&gt;
&lt;br /&gt;
Branch in Git is cheap to create and destroy because it only contains 40 character SHA-1 checksum of the commit that it points to. The speed to create a branch is as fast as writing 41 bytes to file, which is a great advantage compared to other version control software.&lt;br /&gt;
&lt;br /&gt;
=== Merging ===&lt;br /&gt;
Merging is a basic operation in Git, which reconciles multiple changes. It is an important functionality in version control software which helps multiple developers works on the same project. Command is used to merge is:&lt;br /&gt;
&lt;br /&gt;
 $ git merge branch&lt;br /&gt;
&lt;br /&gt;
There are two conditions might happen in Git when merging branches.&lt;br /&gt;
&lt;br /&gt;
The first condition is when you are trying to merge a commit with another commit which can be find directly by following the first commit's upstream. In this case, no divergent work needs to be considered and the only work for Git to do is to move the pointer forward, which is called &amp;quot;fast forward&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In the second condition the two commits to be merged are not in the same commits stream that there are some divergent work needs to be taken care of. In this case, Git does a three-way merge. The two snapshots pointed to by the branches and the common ancestor of the two commits are used. In the process of three-way merging, Git creates a new snapshot to record and automatically creates a new commit for the new snapshot. &lt;br /&gt;
&lt;br /&gt;
Developers do not need to worry about finding the best common ancestor that Git will does this work and saves time for developers.&lt;br /&gt;
&lt;br /&gt;
There are some conflicts may happen in merging when the same part of the same file are changed differently in two branches. Developers have to resolve this problem before merging, otherwise you will get a merge conflict message looks like:&lt;br /&gt;
&lt;br /&gt;
 $ git merge iss53&lt;br /&gt;
 Auto-merging index.html&lt;br /&gt;
 CONFLICT (content): Merge conflict in index.html&lt;br /&gt;
 Automatic merge failed; fix conflicts and then commit the result.&lt;br /&gt;
&lt;br /&gt;
'''''git status''''' is used to check which files are not merged.&lt;br /&gt;
&lt;br /&gt;
 [master*]$ git status&lt;br /&gt;
 index.html: needs merge&lt;br /&gt;
 # On branch master&lt;br /&gt;
 # Changes not staged for commit:&lt;br /&gt;
 #   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
 #   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 #&lt;br /&gt;
 #   unmerged:   index.html&lt;br /&gt;
 #&lt;br /&gt;
&lt;br /&gt;
You can open the files that have conflicts manually and fix the problem. &lt;br /&gt;
&lt;br /&gt;
You can also use merge tools which can be listed by command:&lt;br /&gt;
&lt;br /&gt;
 $ git mergetool&lt;br /&gt;
&lt;br /&gt;
All the merge tools available are listed after &amp;quot;merge tool candidates&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Once you finish using merge tool and exit. Git will ask you whether you solve the conflicts successfully. If you answer yes, Git will stages file and records that as resolved. To finish merging, type command:&lt;br /&gt;
&lt;br /&gt;
 $ git commit&lt;br /&gt;
&lt;br /&gt;
=== Manage your Branch ===&lt;br /&gt;
Many branch-management tools are available in using branches.&lt;br /&gt;
&lt;br /&gt;
The command &amp;quot;git branch&amp;quot; has been introduced before, but it can do more than just creating and deleting branches. If there are no arguments come after &amp;quot;git branch&amp;quot;, all current branches will be listed.&lt;br /&gt;
&lt;br /&gt;
 $ git branch&lt;br /&gt;
   iss53&lt;br /&gt;
 * master&lt;br /&gt;
   testing&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;*&amp;quot; which prefix master indicates master is the branch which just check out.&lt;br /&gt;
&lt;br /&gt;
If you want to have the last commit list after each branch, using &amp;quot;git branch -v&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 $ git branch -v&lt;br /&gt;
   iss53   93b412c fix javascript issue&lt;br /&gt;
 * master  7a98805 Merge branch 'iss53'&lt;br /&gt;
   testing 782fd34 add scott to the author list in the readmes&lt;br /&gt;
&lt;br /&gt;
If you want to filter the branches list as only merged or unmerged, &amp;quot;--merged&amp;quot; and &amp;quot;--no-merged&amp;quot; can be used respectively as the argument.&lt;br /&gt;
&lt;br /&gt;
To delete a branch that has not been merged will fail. The argument used to delete a branch is &amp;quot;-d&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Branching Workflow and Remote Branching ===&lt;br /&gt;
Long-running branches and topic branches are two kinds of workflows that developers can adopt in their development cycle.&lt;br /&gt;
&lt;br /&gt;
In the workflow which has long-running branches, typically there are there branches: master, develop, and topic. Only codes are entirely stable are in the master branch, usually the codes are going to release are have been. And codes in develop are used for testing stability, which is not always stable. Develop is a parallel branch to master. When the codes in develop are make sure stable, the codes can be merged into master. Topic are temporary branch which still contains bugs and has not passe the test. Figure 4-4 shows the three branches.&lt;br /&gt;
&lt;br /&gt;
[[File:long_running.png]]&lt;br /&gt;
&lt;br /&gt;
'''Figure 4-4. Branches master, develop, and topic'''&lt;br /&gt;
&lt;br /&gt;
In the workflow adopts topic branches, each branch is short-lived and used to develop a particular functionality of the software. Topic branches workflow can be used in any size projects. The advantage of topic branches is that all changes made within a branch are only related to a certain topic, which makes it easier to see what happened during code review.&lt;br /&gt;
&lt;br /&gt;
== On the Server ==&lt;br /&gt;
&lt;br /&gt;
=== Protocols ===&lt;br /&gt;
&lt;br /&gt;
=== Putting Git on the Server and Generate Public SSH Key ===&lt;br /&gt;
&lt;br /&gt;
=== Set up Server ===&lt;br /&gt;
&lt;br /&gt;
=== Public Access/Git Web ===&lt;/div&gt;</summary>
		<author><name>Ysun6</name></author>
	</entry>
</feed>