Download - Version Control Systems: Git

Transcript
Page 1: Version Control Systems: Git

Version Control Systems: Git

Αλέξανδρος Χατζηγεωργίου – Μεταπτυχιακό Πρόγραμμα Σπουδών, Τμ. Εφαρμοσμένης Πληροφορικής, 2012

Page 2: Version Control Systems: Git

Version Control System

• Ένα σύστημα ελέγχου εκδόσεων (version control system VCS – ή revision control system) είναι λογισμικό που επιτρέπει τη διαχείριση και παρακολούθηση αλλαγών που συμβαίνουν σε οποιοδήποτε έγγραφο ενός έργου

Page 3: Version Control Systems: Git

Version Control System

Οφέλη από τη χρήση VCS:

- Backup

-Οργάνωση αρχείων που έχουν δημιουργηθεί σε διαφορετικές χρονικές στιγμές (χωρίς συμβάσεις για ονοματοδοσία φακέλων βάσει ημερομηνίας)

- θα μπορούσα να κάνω “Save As..” σε διαφορετικό φάκελο κάθε φορά, να συμπιέζω για να κερδίσω χώρο….χρονοβόρο και κουραστικό

- Ανάκτηση προηγούμενων εκδόσεων και σύγκριση μεταξύ εκδόσεων (εξοικονόμηση χώρου εγγυημένη..)

- αν έχω μια συλλογή αρχείων που αποτελούν ένα έργο (πηγαίος κώδικας, βιβλιοθήκες, εικόνες κλπ) θα πρέπει να αρχειοθετώ ένα ολόκληρο directory κάθε φορά…..!

Page 4: Version Control Systems: Git

Version Control System

Οφέλη από τη χρήση VCS:

- Διατήρηση log για τις αλλαγές που έχουν γίνει

- εναλλακτικά θα έπρεπε να έχω ένα αρχείο στο οποίο να καταγράφω στοιχεία για κάθε αλλαγή που γίνεται

- Δυνατότητα εργασίας πολλών ατόμων επί του ιδίου έργου, ανεξαρτήτως της γεωγραφικής τους θέσης ή χρονικής στιγμής

- εναλλακτικά θα έπρεπε να αποθηκεύω σε κοινόχρηστο φάκελο ενημερώνοντας τους συναδέλφους για το πότε μπορούν να δουλέψουν επί ενός αρχείου

Page 5: Version Control Systems: Git

Version Control System

In a VCS:

- Files cannot be overwritten

- There is a common repository that holds all the latest files

- Allows you to revert back to an older version of the file/project if needed

- Allows you to inspect differences (diff) between versions

Page 6: Version Control Systems: Git

Version Control System

Οφέλη από τη χρήση VCS:

- Διαχείριση συγκρούσεων

Suppose Alice modifies class A, and Bob modifies class B. They both upload their changes. Most systems will automatically deduce a reasonable course of action: accept and merge their changes, so both Alice’s and Bob’s edits are applied.

Now suppose both Alice and Bob have made distinct edits to the same line. Then it is impossible to proceed without human intervention. The second person to upload is informed of a merge conflict, and must choose one edit over another, or revise the line entirely.

More complex situations can arise. Version control systems handle the simpler cases themselves, and leave the difficult cases for humans.

Page 7: Version Control Systems: Git

Git

• Το Git είναι ένα κατανεμημένο σύστημα ελέγχου εκδόσεων (distributed version control system – DVCS) που σημαίνει ότι επιτρέπει την παράλληλη εργασία πολλαπλών ατόμων σε ένα έργο ακόμα και χωρίς την ύπαρξη σύνδεσης σε κεντρικό δίκτυο. Η εργασία τους μπορεί να καταχωρηθεί (push) στο έργο όταν είναι έτοιμη.

Page 8: Version Control Systems: Git

Centralized vs. Distributed

each action has to pass through the network  —  leaving a developer unable to work if they happen to have no network connection

Page 9: Version Control Systems: Git

Centralized vs. Distributed

In distributed systems, each developer has their own full-fledged repository on their computer. In most set-ups there’s an additional central repository on a server that’s used for sharing. However, this is not a requirement; every developer can perform all important actions in their local repository: committing changes, viewing differences between revisions, switching branches, etc

Page 10: Version Control Systems: Git

Git

• Git is an open source project, that has been active for several years and is written mostly in C

Page 11: Version Control Systems: Git

Git

• Eclipse usage: Project & code repository breakdown as of 2012-03-25

Page 12: Version Control Systems: Git

Git popularity

• Google Trends (blue: Git, red: svn)

Page 13: Version Control Systems: Git

Git

•Operations (local)

Page 14: Version Control Systems: Git

Git

•Operations (with remote)

Page 15: Version Control Systems: Git

Git Workflow

Subversion-Style WorkflowA centralized workflow is very common, especially from people transitioning from a centralized system. Git will not allow you to push if someone has pushed since the last time you fetched, so a centralized model where all developers push to the same server works just fine.

Page 16: Version Control Systems: Git

Git Workflow

Integration Manager: single person who commits to the “blessed” repository

Page 17: Version Control Systems: Git

Git Workflow

Dictator and Lieutenants WorkflowFor more massive projects, a development workflow like that of the Linux kernel is often effective. In this model, some people ('lieutenants') are in charge of a specific subsystem of the project and they merge in all changes related to that subsystem. Another integrator (the 'dictator') can pull changes from only his/her lieutenants and then push to the 'blessed' repository that everyone then clones from again.

Page 18: Version Control Systems: Git

Prerequisites

• Install EGit

• Create a project in a remote repository (e.g. GitHub)

• Put project under version control

Page 19: Version Control Systems: Git

Basic Usage

Page 20: Version Control Systems: Git

Basic Usage

retrieved from “Git the basics”, B. Trojanowski, 2008

Page 21: Version Control Systems: Git

Basic Usage

Page 22: Version Control Systems: Git

Basic Usage

Page 23: Version Control Systems: Git

Basic Usage

Page 24: Version Control Systems: Git

Basic Usage

Page 25: Version Control Systems: Git

Basic Usage

Page 26: Version Control Systems: Git

Basic Usage

Page 27: Version Control Systems: Git

Git internally…

Page 28: Version Control Systems: Git

Git internally…

Page 29: Version Control Systems: Git

Git internally…

Page 30: Version Control Systems: Git

Git internally…

Page 31: Version Control Systems: Git

Branching

• Έστω ότι εργαζόμαστε σε ένα έργο και έχουμε ήδη πραγματοποιήσει ορισμένα commit

Page 32: Version Control Systems: Git

Branching

• Αποφασίζουμε να εργαστούμε επάνω στο πρόβλημα #53 και για το λόγο αυτό θέλουμε να δημιουργήσουμε ένα καινούργιο κλάδο (branch) στον οποίο να επιλύσουμε το πρόβλημα

Page 33: Version Control Systems: Git

Branching

• Αφού κάνουμε ορισμένες αλλαγές (σχετικά με το πρόβλημα) πραγματοποιούμε ένα commit. Η ενέργεια αυτή «προχωρά» τον κλάδο iss53 προς τα εμπρός.

Page 34: Version Control Systems: Git

Branching

• Στην πορεία γίνεται γνωστό ότι κάτι πρέπει να διορθωθεί άμεσα στο λογισμικό που υπήρχε. Επειδή οι αλλαγές στο πρόβλημα #53 δεν έχουν ολοκληρωθεί επιστρέφουμε στον κλάδο «master».

• Στο σημείο αυτό, η δομή του working directory είναι ως είχε

Page 35: Version Control Systems: Git

Branching

• Δημιουργούμε έναν καινούργιο κλάδο (hotfix) και διορθώνουμε το πρόβλημα που υπήρχε και καταχωρούμε τις αλλαγές κάνοντας ένα νέο commit.

Page 36: Version Control Systems: Git

Branching

• Αφού βεβαιωθούμε ότι η λύση είναι σωστή συγχωνεύουμε (merge) τον κλάδο hotfix επί του κλάδου master.

• Η συγχώνευση είναι εύκολη (fast-forward) δεδομένου ότι το hotfix είχε «χτιστεί» επί του master. Η συγχώνευση συνίσταται απλά στην προώθηση του δείκτη “merge”

Page 37: Version Control Systems: Git

Branching

• O κλάδος hotfix μπορεί πλέον να διαγραφεί

• επιστρέφουμε στον κλάδο (‘switch to’) iss53.

• Κάνουμε τις αλλαγές και commit

Page 38: Version Control Systems: Git

Branching

•Υποθέτοντας ότι το πρόβλημα #53 επιλύθηκε πλήρως, αποφασίζεται η συγχώνευσης της λύσης στο master branch

• Η συγχώνευση εδώ είναι δυσκολότερη (three-way merge)

Page 39: Version Control Systems: Git

Branching

•Αν δεν συναντηθούν conflicts και η συγχώνευση γίνει αυτόματα θα προκύψει η εξής εικόνα του συστήματος:

Page 40: Version Control Systems: Git

Branching

•Conflicts θα δημιουργηθούν εάν έχουν τροποποιηθεί ίδια σημεία στο ίδιο αρχείο. O προγραμματιστής θα πρέπει να επιλύσει το conflict κάνοντας add το αντίστοιχο αρχείο για να υποδηλώσει την ολοκλήρωση του merging

Page 41: Version Control Systems: Git

Reading Stuff

• Git with Eclipse (EGit) Tutorial: http://www.vogella.com/articles/EGit/article.html

• EGit tutorial: http://unicase.blogspot.gr/2011/01/egit-tutorial-for-beginners.html

• Top 10 Git Tutorials: http://sixrevisions.com/resources/git-tutorials-beginners/

• Pro Git Book: http://git-scm.com/book