If 6 cats kill 6 rats in 6 minutes, how many cats will be needed to kill 100 rats in 50 minutes?
(Hint: it’s not 50 cats)
Computer Science and Engineering The Ohio State University
Copyright By PowCoder代写 加微信 powcoder
Version Control
Computer Science and Engineering College of Engineering The Ohio State University
The Need for Version Control
Computer Science and Engineering The Ohio State University
Track evolution of a software artifact
Newer versions need to be developed Development is non-monotonic
May need to undo some work, go back to an older version, or track down when a mistake was introduced
Development is often non-linear Older versions need to be supported
Facilitate team-based development Multiple developers working on a common code base
How can project be edited simultaneously?
Key Idea: A Repository
Computer Science and Engineering The Ohio State University
Repository= working tree + store + index
Warning: “Repo” often used (incorrectly) to mean just the store or just the working tree
Working tree = project itself
Ordinary directory with files & subdirectories
Store = history of project
Hidden directory: don’t touch!
Index = virtual snapshot
Gateway for moving changes in the working tree into the store (aka “stage”, “cache”)
History = DAG of commits
Each commit represents a complete snapshot of the entire project
File Structure of a Repository
Computer Science and Engineering The Ohio State University
│ ├── buckeye-alert-resp.css
│ └── demo.css
├── demo-js.html
├── Gemfile
├── Gemfile.lock
│ ├── HEAD
│ ├── index
│ └── …etc… ├── .gitignore ├── Rakefile
├── README.md └── …etc…
Conceptual Structure
Computer Science and Engineering The Ohio State University
working tree
~/mashup/.git/
~/mashup/.git/index
A History of Commits
revision β
d’s parent is c
wt working tree ~/mashup/
Computer Science and Engineering The Ohio State University
~/mashup/.git/
~/mashup/.git/index
History is a DAG
Every commit (except the first) has 1
or more parents
e has 1 parent
i has 2 h parents
Computer Science and Engineering The Ohio State University
Initial commit has no parents
Example View of DAG
Computer Science and Engineering The Ohio State University
Example View of DAG
Computer Science and Engineering The Ohio State University
$ git log –oneline –graph
* 1618849 clean up css
* d579fa2 merge in improvements from master
| * 0f10869 replace image-url helper in css
* | b595b10 add buckeye alert notes
* | a6e8eb3 add raw buckeye alert download
* b4e201c wrap osu layout around content
* e9d3686 add Rakefile and refactor schedule loop
* 515aaa3 create README.md
* eb26605 initial commit
Computer Science and Engineering The Ohio State University
Each commit is identified by a hash
160 bits (i.e., 40 hex digits) Practically guaranteed to be unique Can use short prefix of hash if unique
$ git show –name-only
16188493c252f6924baa17c9b84a4c1baaed438b
Date: Mon Mar 31 15:30:50 2014 +0200
clean up css
source/stylesheets/_site.css
History is a DAG
Computer Science and Engineering The Ohio State University
A better picture would label each commit with its hash (prefix)
eca7 96c9 d1bf c0a2 850a
But in these slides we abbreviate the hash id’s as just: ‘a’, ‘b’, ‘c’…
Nomenclature: Branch
Computer Science and Engineering The Ohio State University
Branch: a pointer to a commit Different from “branch” in DAG’s shape
maint main rankings
abdgi cfjk
Nomenclature: HEAD
Computer Science and Engineering The Ohio State University
HEAD: a special reference, (usually) points to a branch
maint main rankings
abdgi cfjk
Nomenclature: HEAD
Computer Science and Engineering The Ohio State University
Useful to think of HEAD as being “attached” to a particular branch
maint main rankings
abdgi cfjk
View of DAG with Branches
Computer Science and Engineering The Ohio State University
$ git log –oneline –graph –decorate
* 1618849 (HEAD -> master) clean up css
* d579fa2 (alert) merge in improvements from master
| * 0f10869 replace image-url helper in css
* | b595b10 add buckeye alert notes
* | a6e8eb3 add raw buckeye alert download
* b4e201c wrap osu layout around content
* e9d3686 add Rakefile and refactor schedule loop
* 515aaa3 create README.md
* eb26605 initial commit
A “Clean” Repository
Computer Science and Engineering The Ohio State University
HEAD maint main
(“wd clean”)
$ git status
On branch main
nothing to commit,
working directory clean
same (“nothing
to commit”)
Edit Files in Working Tree
Computer Science and Engineering The Ohio State University
Add files, remove files, edit files…
HEAD maint main
now differs from index
Edit Files in Working Tree
Computer Science and Engineering The Ohio State University
Add files, remove files, edit files…
HEAD maint main
$ git status
On branch main
Changes not staged for commit:
now differs from index
modified: css/demo.css
Add: Working Tree -> Index
Computer Science and Engineering The Ohio State University
$ git add –all .
HEAD maint main
index = wt, both differ from HEAD
Add: Working Tree -> Index
Computer Science and Engineering The Ohio State University
$ git add –all .
HEAD maint main
$ git status
On branch main
Changes to be committed:
index = wt, both differ from HEAD
modified: css/demo.css
Commit: Index -> Store
$ git commit
Computer Science and Engineering The Ohio State University
HEAD advanced
(with attached branch!)
new commit HEAD added to store
unaffected (but now clean)
Store changed! DAG extended
parent is old HEAD
The (New) State of Repository
Computer Science and Engineering The Ohio State University
HEAD maint main
Creating a
$ git branch fix
HEAD maint main
Computer Science and Engineering The Ohio State University
Checkout: Changing Branch
$ git checkout fix
maint main
Store unaffected (apart from HEAD) Same DAG, branches
HEAD moved
Computer Science and Engineering The Ohio State University
Checkout: Changing Branch
$ git checkout maint
HEAD maint
HEAD moved
Computer Science and Engineering The Ohio State University
now same as maint
Advice: checkout only when wt is clean
Edit Files in Working Tree
Computer Science and Engineering The Ohio State University
Add files, remove files, edit files…
maint main
now differs from index
Add & Commit: Update Store
$ git add –all .
$ git commit
HEAD maint
Computer Science and Engineering The Ohio State University
Merge: Bringing History together
Computer Science and Engineering The Ohio State University
Bring work from another branch into current branch
Implemented features, fixed bugs, etc. Updates current branch, not other
HEAD HEAD current other other current
Merge – Case 1: Ancestor
Computer Science and Engineering The Ohio State University
HEAD is an ancestor of other branch
maint main
Fast-Forward Merge
$ git merge main
Computer Science and Engineering The Ohio State University
maint main
Merge – Case 2: No Conflicts
Computer Science and Engineering The Ohio State University
Merge Automatically Commits
$ git merge maint
Computer Science and Engineering The Ohio State University
Merge – Case 3: Conflicts Exist
$ git merge maint
Computer Science and Engineering The Ohio State University
files with conflicts marked
files that could be merged automatically
Merge: Resolve Conflicts
$ emacs somefile
Computer Science and Engineering The Ohio State University
files with conflicts resolved
Merge with Conflicts: Add
$ git add somefile
Computer Science and Engineering The Ohio State University
Merge with Conflicts: Commit
Computer Science and Engineering The Ohio State University
$ git commit
Repository = working tree + store
Store contains history History is a DAG of commits References, tags, and HEAD
Commit/checkout are local operations Former changes store, latter working tree
Directional (merge A “into” B)
Computer Science and Engineering The Ohio State University
Computer Science and Engineering The Ohio State University
Demo (in Office Hrs)
Computer Science and Engineering The Ohio State University
Prep: Empty (but initialized) repo
Linear development:
Create, edit, rename, ls -la files Git: add, status, commit, log
Checkout (time travel, detach HEAD) Branch (re-attach HEAD)
More commits, see split in history
No conflict Fast-forward
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com