Git

From Expertiza_Wiki
Revision as of 15:50, 27 April 2013 by Ajkofink (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Common Git Idioms Used in Expertiza

Merging Code Which is Not Derived from the Full History of Expertiza via Fork

  1. Pull their code in as a new remote (ie. rogue). It won't connect to our history line, but we can create a branch there (ie. stray) for comparison.
    git remote add rogue https://github.com/rogue/roguespertiza...
    git branch stray rogue/master
  2. Create another temporary branch (ie. stray0) as a reference point for their first commit.
    git branch stray0 $(git rev-list stray|tail -n1)
  3. Determine a range of commits that could be potentially have been their starting point. I used git log and looked for a commit around the semester start date (ie. a000000) and after when they submitted their work (ie. f999999). Compare the size of the diff (number of lines in the diff, using wc -l) between stray0 and each commit in the range. Find the commit in our history with the minimum diff size with their work. If it's the first or last commit in the list, increase your commit range, they probably started outside your search range.
    for commit in $(git log a000000..f999999 --pretty=%h); do echo $commit $(git diff stray0 $commit | wc -l); done
  4. Let's say we found that commit c444444 was the commit with the smallest diff size. That becomes our branching point where we want to move all the commits from the stray branch.
  5. Create a new copied branch where stray0 is, and move it with its tree state to our history line. Then re-create the commit. (Please don't really name it "copied"... give the branch a meaningful name like E713-custom-rubric)
    git checkout stray0 -b copied
    git reset --soft c444444
    git commit -m "(original commit message)" --author="Original Author <and@email>"
  6. Now cherry-pick (copy) the rest of stray's commits onto the copied branch that we just moved to our history line.
    git cherry-pick stray0..stray
  7. Clean out the remote and branches we added in the process:
    git remote rm rogue
    git br -D stray stray0
  8. Now your copied branch contains all the commits from the project and is based on the project's original start point in our history line. At this point it can be tested, modified, and pushed as usual.

Other Helpful Pages