1 / 25

GIT tutorial

Wing Research Group. GIT tutorial. Introduction . Learn why and how GIT aids software development The outcome of this tutorial: Understand the design and phylosophy of GIT Be able to use GIT for everyday work. Agenda. GIT background GIT design objectives Everyday work with GIT QA.

Mercy
Télécharger la présentation

GIT tutorial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Wing Research Group GIT tutorial

  2. Introduction • Learn why and how GIT aids software development • The outcome of this tutorial: • Understand the design and phylosophy of GIT • Be able to use GIT for everyday work

  3. Agenda • GIT background • GIT design objectives • Everyday work with GIT • QA

  4. Overview • Collaboration is ubiquitous in software development. Consequently, you see CVS, SVN, Mercurial, TLA, Mecurial and GIT. • How such a SCM can help many people to work together effectively?

  5. Terminology • Repository • Pull / Push / Checkout • Branch • Merge • Conflict • Commit • Revert

  6. GIT background • Developed by Linus Torvald • Purpose: to facilitate Linux kernel development • Consider CVS/SVN as the evil

  7. Git design objectives • Distributed • No central repo • Everyone is on her own island • Write access class VS. Network of trust • Performance • Branching and merge is cheap • Diff the whole kernel tree in less than 1 second • Store the KDE tree in less than 2GB while SVN takes 8GB

  8. Git design objectives • Reliability • File corruption, RAM corruption, Macilious users • GIT tracks the content of the whole repo, not single file, not only filenames • GIT use SHA1 for data integrity: file, commit, repo... • Consequently: • May not check in a single file • May not check out a single file • Break a big project to sub projects smartly :)

  9. Everyday tasks with GIT • GIT has many routines: • “git merge” • “git pull” • “git push” • “gitk” • “git init” • “git config” • GIT man page • “man git-merge”

  10. Everyday tasks with GIT • Introduce yourself to GIT • “git config –global user.name “Trung”” • “git config –global user.email “u0407784@nus.edu.sg”” • Create a repo • “git init” • Clone a repo • “git clone git://git.kernel.org/scm/git/git.git” • git clone ssh://trunglt@aye.comp.nus.edu.sg/home/min/forecite/

  11. Everyday tasks with GIT • Lean a bit about GIT concepts: • Repo: your local repo and remote repos • Reference in history: either commit or merge • Branch: “master” is the default branch name. Do not give name such as test1, test2... but test_login, rel_iteration1 • SHA1 • Tag: a friendly name for a commit (version 1.0 vs e74g64a21...) • Head: you see that branch is a series of commits. A branch name also means the latest commit on that branch

  12. Everyday tasks with GIT • HEAD: the commit that you are working on • HEAD^, HEAD^^, HEAD~3 = HEAD^^^, • HEAD^1, HEAD^2

  13. Everyday tasks with GIT • Create a branch: • “git branch <name>” • “git branch <name> <commit-id>” • Delete a branch: • “git branch -d <name>” • List branch: • “git branch” • “git branch -r” //remote branch • Jump to a commit: • “git checkout <commit-id>” • “git checkout -b <name> <commit-id>”

  14. Everyday tasks with GIT • Give remote repo a nicer name: • “git remote add min ssh://<username>@aye.comp.nus.edu.sg/home/min/parcite” • Fetch changes from Min: • “get fetch min” • Merge with the master branch of Min's repo: • “get merge min/master” • Or in one shot: git pull min

  15. Everyday tasks with GIT • View SHA1 of a commit: • Git rev-list HEAD^..HEAD • View logs: • “git log” • “git log HEAD~4..HEAD” • “git log –pretty=oneline v1.0..v2.0 | wc-l • git log --raw -r --abbrev=40 –pretty=oneline origin..HEAD • git archive --format=tar --prefix=project/ HEAD | gzip >latest.tar.gz • “git blame <filename>”

  16. Everyday tasks with GIT • Git commit and merge: • Git has its own index database • When you edit your repo, there are 3 things: • HEAD: the reference in history from that you are editing • Cached: whatever you have just added and run git add • The remaining files that you have not ask git to keep track

  17. Everyday tasks with GIT • Make a commit: • After you edit some files, • look at the output of “git status” • ask GIT to keep track new files: “git add .” • Create new files • “git diff –cached” • “git add .” • “git diff HEAD” • “git commit”

  18. Everyday tasks with GIT • Git merge: • “git pull min” OR (“git fetch min” then “git merge min”) • Conflicts • $ git show :1:file.txt # the file in a common ancestor of both branches • $ git show :2:file.txt # the version from HEAD, but including any • # nonconflicting changes from MERGE_HEAD • $ git show :3:file.txt # the version from MERGE_HEAD, but including any • # nonconflicting changes from HEAD. • Resolve the conflicts / reset and ask others to help

  19. Everyday tasks with GIT • Reset the conflicted merge: use git-reset • “git reset –mixed <commit-id> • Reset the index database to the moment before merging • “git reset –hard <commit-id> • Reset the index database and the working data • “git reset –soft <commit-id> • You made a commit and also made some typo mistake. This commands help us fix those errors without touching the working data and index database

  20. Everyday tasks with GIT • “git reset” help you to revert the most recent commit only • Revert older commit by hiding is bad • Use “git revert” to introduce a patch to revert the merge/commit done. • This is left as an exercise

  21. Everyday tasks with GIT • Last thing: how to ignore files in a repo: • Use .gitignore: list files that you want to ignore • Put .gitignore in the directory containing the files • Example: Ruby on Rails project • Example: C/C++ project

  22. Everyday tasks with GIT • Quality Assurance? How Linux developer keep track of bugs: • “git bisect”: binary search for a bug in a series of commits: • git bisect start • git bisect good v2.6.17 • git bisect bad v2.6.18

  23. Question and Answer • Question and Answer :)

  24. Summary • Git is a great tools for collaboration • New paradigm in SCM • Difficult to master, so learn it through everyday usage • Can always post questions to forum/admin group or :) Trung :)

More Related