علیرضا فراهانی استاد درس: جعفری نژاد مهر 1393
Version Control ▪Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. ▪Why? –Revert files back to a previous state –Compare changes over time –see who last modified something –Generally, if you screw things up or lose files, you can easily recover
Local, Centralized, Distributed ▪Local: –Storing backup versions in hard drive (Perhaps a time- stamped directory) ▪Centralized: –need to collaborate with developers on other systems –single server that contains all the versioned files, and a number of clients that check out files from that central place –CVS, Subversion, and Perforce
CVCS (Pros & Cons) ▪Pros –Access level (admin, write, read) –Knowing what others are doing ▪Cons –Single point of failure
Local, Centralized, Distributed ▪Distributed –Every client has whole repository with its history –Git, Mercurial, Bazaar
DVCS (Pros & Cons) ▪Pros –Fast –Even with server being down, every client can continue to work and save its code changes. ▪Cons –Greater redundancy
Git Vs SVN
A short history of Git
▪Linux kernel development ▪ –Changes passed around as archived file ▪ –Using a DVCS called BitKeeper ▪2005 –Relationship broke down between two comunity
A short history of Git ▪Goals –Speed – Simple design – Strong support for non-linear development (thousands of parallel branches) – Fully distributed – Able to handle large projects like the Linux kernel efficiently (speed and data size)
A short history of Git ▪Popularity –Git is now the most widely used source code management tool –33.3% of professional software developers use Git or GitHub as their primary source control system
Git Basics ▪Snapshots, not changes –a picture of what all your files look like at that moment –If a file has not changed, store a reference ▪Nearly Every Operation Is Local –Browsing the history of project –See changes between two versions
Git Basics (Cont.)
▪Git has Integrity –Everything is check-summed before it is stored and is then referred to by that checksum –40-character string (e.g. 24b9da aa493b52f8696cd6d3b00373) –Git stores everything not by file name but in the Git database addressable by the hash value of its contents ▪Git Generally Only Adds Data –very difficult to get the system to do anything that is not undoable or to make it erase data in any way
Git Basics (Cont.) ▪The Three States –Modified ▪File has changed but not committed –Staged ▪Marked to go to next commit snapshot –Committed ▪Safely stored in local database –Untracked! ▪Newly added or removed files
Git Basics (Cont.) ▪Three Main Section of a Git Project –Working Directory ▪Single checkout of one version of the project. –Staging Area ▪Simple file storing information about what will go into your next commit –Git Directory ▪What is copied when cloning a repository
Git Basics (Cont.) ▪Three Main Section of a Git Project
Git Setup ▪Installation –You’ve done it already! ▪Your identity –$ git config --global user.name "John Doe" –$ git config --global user. ▪Github distinguish you account from others by this data ▪Getting help –$ git help –$ git --helpe.g. git help commit –$ man git-
Authenticating with git servers ▪Https –You’ll be asked for your git server username and password with each remote command (pull, push,..) ▪SSH –Generate new SSH key –Add SSH key to Git server
Using Git ▪Initializing new repository –git init ▪Staging untracked files –Git add ▪Git add README.md ▪Git add. ▪Git add src/ ▪Git add *.java
Using Git (Cont.) ▪Clone a repo –git clone ▪git clone git://github.com/schacon/grit.git ▪git clone ssh://github.com/schacon/grit.git ▪Checking the Status of Your Files –git status
Using Git (Cont.) –Git status ▪Shows which files are in which state ▪git status –s (shorter version) ▪A file can in staged and modified state at the same time
Using Git (Cont.) ▪Ignoring files –Class of files that you don’t want Git to automatically add or even show –Log files, generated files –Solution?. gitignore
.Gitignore file ▪A specific file –My.txt ▪Ignore by file name –*.[oa](all files with either.o or.a extension) –*~(temporary files) ▪Excluding a file from extension pattern –!lib.a(do track the lib.a file) ▪Ignore by folder –gen/
Using Git (Cont.) ▪Committing your changes –must provide a message –git commit ▪git commit(launches your editor of choice) –git config --global core.editor –git commit –m ▪inline message with commit command ▪$ git commit –m “job’s done” –-a ▪automatically stage files already tracked before ▪git commit –am “main activity finished”
Using Git (Cont.) ▪Removing files –git rm ▪removes file(s) from staging area and working directory –--cached ▪keep file on disk but not have Git track in anymore ▪removing accidentally added files ▪$ git rm log/\*.log –all files ending in “.log” which are in “log” folder
Using Git (Cont.) ▪Viewing commit history –log command ▪$ git log ▪$ git log -2 –limits number of commits shown
Using Git (Cont.) ▪Undoing things –Unmodifying a Modified File ▪git checkout -- (to last committed version) –Unstaging a Staged File ▪git reset HEAD –Reset the staging area and the working directory to match the target commit ▪Git reset –hard (deletes history) –Rolling back to a commit making it the head ▪Git revert
Git branches
Using Git (Cont.) ▪Working with remotes –Pushing to Your Remotes ▪push command –$ git push origin (e.g. master) –pulling from your remote ▪pull command –pull is fetch and then a merge –$ git pull origin –fetch and merge is better
Useful links ▪Undoing things –atlassian.com/git/tutorials/undoing-changes/git-resetatlassian.com/git/tutorials/undoing-changes/git-reset ▪git GUIs –stackoverflow.com/questions/315911/git-for- beginners-the-definitive-practical-guidestackoverflow.com/questions/315911/git-for- beginners-the-definitive-practical-guide ▪step by step guide –try.github.comtry.github.com
Useful links مدلسازي موضوعپيادهسازينتايججمعبندي
با سپاس فراوان مدلسازي موضوعپيادهسازينتايججمعبندي