留学生作业代写 USING Version Control

USING Version Control
Computer Science and Engineering  College of Engineering  The Ohio State University

Basic Workflow: Overview

Copyright By PowCoder代写 加微信 powcoder

Computer Science and Engineering  The Ohio State University
1. Configure git (everyone)
2. Create central repo (1 person) 3. Create local repo (everyone)
4. As you work (everyone):
Commit locally Fetch/merge as appropriate Push to share

Step 1: Configure Git
Computer Science and Engineering  The Ohio State University
Each team member, in their own VM
Set identity for authoring commits
$ git config –global user.name ” ”
$ git config –global user.email
Optional: diff and merge tool (eg meld)
$ sudo apt install meld # to get tool $ git config –global merge.tool meld $ git config –global diff.tool meld # example use:
$ git difftool e9d36

Step 2: Initialize Central Rep
Computer Science and Engineering  The Ohio State University
One person, once per project:
Hosting services (GitHub, BitBucket…)
use a web interface for this step
Or, could use stdlinux instead:
Create central repository in group’s project
directory (/project/c3901aa03)
$ cd /project/c3901aa03
$ mkdir rep.git # ordinary directory
Initialize central repository as bare and
shared within the group
$ git init –bare –shared rep.git

Step 3: Create Local Repository
Computer Science and Engineering  The Ohio State University
Each team member, once, in their VM Create local repository by cloning the central repository
$ git clone

state.edu//project/c3901aa03/proj1.git
You will be prompted for your (stdlinux) password (every time you fetch and push too)
To avoid having to enter your password each time, create an ssh key-pair (see VM setup instructions)

Step 4: Local Development
Computer Science and Engineering  The Ohio State University
Each team member repeats:
Edit and commit (to local repository) often
$ git status/add/rm/commit
Pull others’ work when can benefit
$ git fetch origin # bring in changes
$ git log/checkout # examine new work
$ git merge, commit # merge work
Push to central repository when confident
$ git push origin main # share

Commit/Branch Conventions
Computer Science and Engineering  The Ohio State University
Team strategy for managing the
structure of the DAG (ie the store)
Main is always deployable
All work is done on other branches, merged with main only when result compiles
Feature branches vs developer branches Each feature developed on its own branch vs. each developer works on their own branch
Rebase instead of merge
Always build on top of latest origin/HEAD

Example: Branch-Based Dev
Computer Science and Engineering  The Ohio State University

Example: Trunk-Based Dev
Computer Science and Engineering  The Ohio State University

What Goes Into Central Repo?
Computer Science and Engineering  The Ohio State University
Avoid developer-specific environment settings Passwords, file paths on local machine
Use classpath variables ($OSU_CSE_LIB) for
external libraries
Avoid IDE-specific files (.settings)
But OK to keep .project and .classpath in repo so it
is easier to get started by cloning Avoid living binaries (docx, pdf)
Meaningless diffs Avoid generated files
Javadoc HTML, .class, .jar, compiled files Agree on code formatting
Auto-format is good, but only if everyone uses the same format settings!
Spaces vs tabs, brace position, etc

Ignoring Files from Working Tree
Computer Science and Engineering  The Ohio State University
Use a .gitignore file in root of project Committed as part of the project
Consistent policy for everyone on team Example:
# see github:gitignore/Ruby, /Global/ # Ignore auto-saved emacs files
# Ignore bundler config
# Ignore the default SQLite database
/db/*.sqlite3
# Ignore all logfiles and tempfiles

Problem: End-of-line Confusion
Computer Science and Engineering  The Ohio State University
Differences between OS’s in how a “new line” is encoded in a text file
Windows: CR + LF (ie “\r\n”, 0x0D 0x0A)
Unix/Mac: LF (ie “\n”, 0x0A) Difference is hidden by most editors
An IDE might recognize either when opening a
file, but convert all to \r\n when saving
But difference matters to git when comparing
Problem: OS differences within team
Changing 1 line causes every line to be modified
Flood of spurious changes masks the real edit

Solution: Normalization
Computer Science and Engineering  The Ohio State University
Git convention: use \n in the store
Working tree uses OS’s native eol Convert when moving data between the two (e.g., commit, checkout)
Note: Applies to text files only
A “binary” file, like a jpg, might contain these bytes (0x0D and/or 0x0A), but they should never be converted
How does git know whether a file is
text or binary?
Heuristics: auto-detect based on contents Configuration: filename matches a pattern

Normalization With .gitattributes
Computer Science and Engineering  The Ohio State University
Use a .gitattributes file in root of project Committed as part of the project
Consistent policy for everyone on team Example:
# Auto detect text files and perform LF normalization
* text=auto
# These files are text, should be normalized (crlf=>lf)
*.java text
*.md text
*.txt text
*.classpath text
*.project text
# These files are binary, should be left untouched
*.class binary
*.jar binary

Ninja Git: Advanced Moves
Computer Science and Engineering  The Ohio State University
Temporary storage
Undoing big and small mistakes in the working tree
reset, checkout
Undoing mistakes in store
DAG surgery

Advanced: Temporary Storage
Computer Science and Engineering  The Ohio State University
Say you have uncommitted work and want to look at a different branch Checkout won’t work!
HEAD maint main
uncommited changes

Stash: Push Work Onto A Stack
Computer Science and Engineering  The Ohio State University
$ git stash # repo now clean
$ git checkout …etc… # feel free to poke around
wt maint main stash

Stash: Pop Work Off the Stack
Computer Science and Engineering  The Ohio State University
$ git stash pop # restores state of wt (and store)
# equivalent to:
$ git stash apply # restore wt and index $ git stash drop # restore store
HEAD maint main
uncommited changes

Advanced: Undoing Mistakes
Computer Science and Engineering  The Ohio State University
Say you want to throw away all your uncommitted work
ie “Roll back” to last committed state Checkout won’t work!
HEAD maint main
uncommitted changes

Reset: Discarding Changes
Computer Science and Engineering  The Ohio State University
$ git reset –hard
$ git clean –-dry-run # list untracked files $ git clean –-force # remove untracked files
HEAD maint main
replaced to be same as HEAD

Reset: Discarding Commits
Computer Science and Engineering  The Ohio State University
$ git reset –hard HEAD~1
# no need to git clean, since wt was already clean
HEAD moved (and attached branch)
HEAD maint main
replaced to be same as HEAD~1
now unreachable

The Power to Change History
Computer Science and Engineering  The Ohio State University
Changing the store lets us:
Fix mistakes in recent commits
Clean up messy DAGs to make history look more linear
Rule: Never change shared history Once something has been pushed to a remote repo (e.g., origin), do not change that part of the DAG
So: A push is really a commitment!

Advanced: Rewriting History
Computer Science and Engineering  The Ohio State University
Problem 1: Wrong or incomplete commit
uncommitted changes

Advanced: Rewriting History
Computer Science and Engineering  The Ohio State University
Problem 1: Wrong or incomplete commit

Advanced: Rewriting History
Computer Science and Engineering  The Ohio State University
Oops! That wasn’t quite right…
Problem 1: Wrong or incomplete commit
uncommitted changes

Advanced: Rewriting History
Computer Science and Engineering  The Ohio State University
Oops! That wasn’t quite right…
Problem 1: Wrong or incomplete commit

Advanced: Rewriting History
Computer Science and Engineering  The Ohio State University
Problem 1: Wrong or incomplete commit
Oops! That wasn’t quite right…

Advanced: Rewriting History
Computer Science and Engineering  The Ohio State University
Problem 1: Wrong or incomplete commit
Result: Lots of tiny “fix it”, “oops”, “retry” commits

Commit –amend: Tip Repair
Computer Science and Engineering  The Ohio State University
Alternative: Change most recent commit(s)
uncommitted changes

Commit –amend: Tip Repair
Computer Science and Engineering  The Ohio State University
$ git add –-all .
$ git commit –-amend –-no-edit
# no-edit keeps the same commit message
Brand new commit, different hash

Advanced: Rewriting History
Computer Science and Engineering  The Ohio State University
Problem 2: As an independent branch is being developed, main also evolves

Advanced: Rewriting History
Computer Science and Engineering  The Ohio State University
Problem 2: As an independent branch is being developed, main also evolves Result: Need periodic merges of main with (incomplete) branch

Advanced: Rewriting History
Computer Science and Engineering  The Ohio State University
Problem 2: As an independent branch is being developed, main also evolves Result: Need periodic merges of main with (incomplete) branch

Advanced: Rewriting History
Computer Science and Engineering  The Ohio State University
Problem 2: As an independent branch is being developed, main also evolves Result: Need periodic merges of main with (incomplete) branch

Rebase: DAG Surgery
Computer Science and Engineering  The Ohio State University
Alternative: Move commits to a different part of the DAG
HEAD main menu

Rebase: DAG Surgery
Computer Science and Engineering  The Ohio State University
$ git rebase main
# merging main into menu is now a fast-forward
HEAD main menu
Rule: Never change shared history

Git Clients and Hosting Services
Computer Science and Engineering  The Ohio State University
Recommended client: Command line! Alternative: Various GUIs
Linux: gitg, git-gui, git-cola, giggle Win/mac GUI: SourceTree
IDEs: RubyMine
Lots of sites for hosting your repos:
GitHub, Bitbucket, SourceForge, Google Code, …
These cloud services provide Storage space
Pretty web interface
Issues, bug tracking
Workflow with “forks” and “pull requests” to promote contributions from others

Computer Science and Engineering  The Ohio State University
git != GitHub

Warning: Academic Misconduct
Computer Science and Engineering  The Ohio State University
GitHub is a very popular service
3901 has an account (“organization”) for private repo’s (see class web site)
Bitbucket has free private repo’s, for small teams (< 5 collaborators) Public repo's containing coursework can create academic misconduct Problems for poster Problems for plagiarist Computer Science and Engineering  The Ohio State University Central repo is a shared resource Contains common (source) code Normalize line endings and formats Fetch/push frequency Respect team conventions for how/when to use different branches Advanced techniques Stash, reset, rebase Learn by using the command line Beware academic misconduct 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com