Source Code Management wih git

Similar documents
Source Code Management wih git

Computer Science Design I Version Control with Git

git commit --amend git rebase <base> git reflog git checkout -b Create and check out a new branch named <branch>. Drop the -b

Introduction to distributed version control with git

2 Initialize a git repository on your machine, add a README file, commit and push

Index. Alias syntax, 31 Author and commit attributes, 334

Fundamentals of Git 1

Git. A Distributed Version Control System. Carlos García Campos

Version Control System - Git. zswu

Version Control: Gitting Started

GIT Princípy tvorby softvéru, FMFI UK Jana Kostičová,

Versioning with git. Moritz August Git/Bash/Python-Course for MPE. Moritz August Versioning with Git

Topics covered. Introduction to Git Git workflows Git key concepts Hands on session Branching models. Git 2

git the SCM system Jan-Simon Möller training.linuxfoundation.org

Introduction to GIT. Jordi Blasco 14 Oct 2011

Introduction to Version Control

GUIDE TO MAKE A REAL CONTRIBUTION TO AN OPEN SOURCE PROJECT 1. 1

Submitting your Work using GIT

Version control with Git.

Agenda. Several projects are using GIT Developer(s) Junio Hamano, Linus Torvalds. Qt Stable release (January 31, 2011)

Git for Version Control

git Version: 2.0b Merge combines trees, and checks out the result Pull does a fetch, then a merge If you only can remember one command:

Common Git Commands. Git Crash Course. Teon Banek April 7, Teon Banek (TakeLab) Common Git Commands TakeLab 1 / 18

GIT for companies Mark Struberg, INSO TU Vienna

Version Control with Git

Git Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : October, More documents are freely available at PythonDSP

Git. Ľubomír Prda. IT4Innovations.

Git AN INTRODUCTION. Introduction to Git as a version control system: concepts, main features and practical aspects.

an introduction to git

Git AN INTRODUCTION. Introduction to Git as a version control system: concepts, main features and practical aspects.

Git. (Why not CVS?... because Git.) Karel Zak Florian Festi Bart Trojanowski December 20, 2007

Version Control with GIT

GIT CHEAT SHEET. CONFIG --global => write to ~/.gitconfig, otherwise to.git/config. git config [--global] -l git config [--global] -e

E, F. deleteall command, 352 directory structure, 350 export_data method, 353 inline_data method, 353 print_export method, 351 target directory, 351

INET

Version Control with Git

Distributed Version Control (with Git)

Ingegneria del Software Corso di Laurea in Informatica per il Management (D)VCS. Davide Rossi Dipartimento di Informatica Università di Bologna

Introduction to GIT. The distributed SCM

Tools for software development:

Git. Charles J. Geyer School of Statistics University of Minnesota. Stat 8054 Lecture Notes

FEEG Applied Programming 3 - Version Control and Git II


February 2 nd Jean Parpaillon

CSE 391 Lecture 9. Version control with Git

Windows. Everywhere else

Human Version Control

Version Control. Version Control. Human Version Control. Version Control Systems

Git version control with Eclipse (EGit) Tutorial

Git and GitHub. Dan Wysocki. February 12, Dan Wysocki Git and GitHub February 12, / 48

Chapter 5. Version Control: Git

Lab Exercise Git: A distributed version control system

Crash course in version control (focusing mainly on git)

GIT tutorial. David Parsons, Soraya Arias, Thomas Calmant November, Preamble 2

Git. Presenter: Haotao (Eric) Lai Contact:

GIT. CS 490MT/5555, Spring 2017, Yongjie Zheng

About SJTUG. SJTU *nix User Group SJTU Joyful Techie User Group

Git Introduction CS 400. February 11, 2018

Θερινό Σχολείο, Ιουλίου git. Αχιλλέας Πιπινέλης. Μονάδα Αριστείας ΕΛ/ΛΑΚ ΤΕΙ Αθήνας

Revision control. INF5750/ Lecture 2 (Part I)

Revision Control and GIT

Git Workflows. Sylvain Bouveret, Grégory Mounié, Matthieu Moy

TDDC88 Lab 4 Software Configuration Management

Git: Distributed Version Control

VCS VERSION CONTROL SYSTEMS

[Software Development] Development Tools. Davide Balzarotti. Eurecom Sophia Antipolis, France

CESSDA Expert Seminar 13 & 14 September 2016 Prague, Czech Republic

How to be a git. Dominic Mitchell

Git & Github Fundamental by Rajesh Kumar.

Git for Newbies. ComMouse Dongyue Studio

Assumptions. GIT Commands. OS Commands

Algorithm Engineering

Introduction to Git. Let us list below some of the best known and most widely used version control systems:

Advanced Git. Luc Sarzyniec. Xilopix, February / 88

Git. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

An introduction to git

Introduction to Git. Database Systems DataLab, CS, NTHU Spring, 2018

Software Development I

Using Git to Manage Source RTL

Decentralized Version Control Systems

Git. all meaningful operations can be expressed in terms of the rebase command. -Linus Torvalds, 2015

Advanced Operating Systems Control Versioning with GIT. Giuseppe Massari

Gitting things done. Hands-on introduction to git niceties. Jan Urbański Ducksboard

Push up your code next generation version control with (E)Git

Version Control. Version Control

! #Running this command from the top directory of your project will add all your changes."! $ git add."

How to version control like a pro: a roadmap to your reproducible & collaborative research

Introduction to Git and Github

GETTING TO KNOW GIT: PART II JUSTIN ELLIOTT PENN STATE UNIVERSITY

Revision Control. An Introduction Using Git 1/15

Git AN INTRODUCTION. Introduction to Git as a version control system: concepts, main features and practical aspects.

CPSC 491. Lecture 19 & 20: Source Code Version Control. VCS = Version Control Software SCM = Source Code Management

Working in Teams CS 520 Theory and Practice of Software Engineering Fall 2018

Git tutorial. Katie Osterried C2SM. October 22, 2015

Working with GIT. Florido Paganelli Lund University MNXB Florido Paganelli MNXB Working with git 1/47

Version Control Systems (VCS)

CSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Subversion (and Git) Winter 2019

GIT DISTRIBUTED IS THE NEW CENTRALISED

CS 320 Introduction to Software Engineering Spring February 06, 2017

Git Tutorial. André Sailer. ILD Technical Meeting April 24, 2017 CERN-EP-LCD. ILD Technical Meeting, Apr 24, 2017 A. Sailer: Git Tutorial 1/36

Transcription:

Source Code Management wih git Matthieu Herrb December 22 http://homepages.laas.fr/matthieu/cours/git.pdf

Licence This work is licensed under a Creative Commons Attribution-ShareAlike 3. Unported License. To get a copy of the license, use the following address: http://creativecommons.org/licenses/by-sa/3./ Parts of this document have been re-used and translated from Johan Moreau, «Outils de construction» et de Konrad Hinsen «Packaging en Python» for the ENVOL 2 CNRS school. December 22 2/54

Agenda Introduction 2 Git concepts 3 Individual developper 4 Using branches 5 Working together 6 Other goodies 7 Appendix December 22 3/54

Agenda Introduction 2 Git concepts 3 Individual developper 4 Using branches 5 Working together 6 Other goodies 7 Appendix December 22 4/54

Introduction Distributed version control system by opposition to CVS or SVN which are Centralized Developped by Linus Torvalds for the Linux kernel Similar to Monotone, Darcs, Mercurial, Bazaar, etc. December 22 5/54

Version Control concepts () Repository Directory or other form of storage: keeps the history of modifications. Revision Each state of the source files has a unique identifier revision. Also called commit as language shortcut. A B C Sorted sequence Marketing project version VCS revision! December 22 6/54

Version Contol concepts (2) Branches G E F A B C D I J H K December 22 7/54

Handling branches Branches can be used for : fixing a bug in an released version develop new ideas in parallel manage a customized version of the software merge back a version that diverged for some reason track local modifications to externally maintained sources... December 22 8/54

Working in teams No locks on source code. Each developper has its own copy of the source and repository. Conflicts handling: First merge other people s contribution Automated merges as much as possible Conflict detection manual resolution No new commit before solving the conflict. December 22 9/54

Centralized model Pull Pull Push Anne Bernard Carole Denis Central repository Pull Pull Push December 22 /54

Distributed model Commit Commit pull push pull Gérard pull push pull Fabienne Commit pull Hélène Eric December 22 /54

Agenda Introduction 2 Git concepts 3 Individual developper 4 Using branches 5 Working together 6 Other goodies 7 Appendix December 22 2/54

Git concepts () repository all the history of the project, stored in the.git directory diff or patch differences between 2 versions of a file. commit (verb) action to register a version of a set of files to the repository. commit (noun) the result of a commit action, represented by a 28 hexadecimal SHA- hash. branch one line of development. by default all development is done in master. tag a symbolic identifier for a commit or a branch December 22 3/54

Git concepts (2) Working tree the set of files being worked on currently. Index an object tracking modified, added, removed files. Blob binary data used to store files, objects, and other data December 22 4/54

Git Interfaces Command line Git GUIs gitk, git-gui (part of git distribution) git-cola http://git-cola.github.com/ TortoiseGit (Windows) http://code.google.com/p/tortoisegit/ Eclipse plugin (http://eclipse.org/egit/) Web browsers: cgit, gitweb. December 22 5/54

Git forges Web sites dedicated to git projects hosting. gitorious http://gitorious.org/ github https://github.com/ Include interesting features for collaboration. Better suited for distributed developement than traditional centralized forges December 22 6/54

Initial setup Sets defaults for commit messages: user name & email preferred text editor % git config --global --add user.name "Matthieu Herrb" % git config --global --add user.email \ "<matthieu.herrb@laas.fr>" % git config --global --add core.editor emacs -nw % cat ~/.gitconfig [user] name = Matthieu Herrb email = <matthieu.herrb@laas.fr> [core] editor = emacs -nw December 22 7/54

Agenda Introduction 2 Git concepts 3 Individual developper 4 Using branches 5 Working together 6 Other goodies 7 Appendix December 22 8/54

Creating a repository git init creates an empty repository in the current directory. % mkdir git-tutorial % cd git-tutorial % git init Initialized empty Git repository in /home/mh/git-tuturial/.git/ % ls -l.git total 24 -rw-r--r-- mh mh 23 Oct 26 9:4 HEAD -rw-r--r-- mh mh Oct 26 9:4 config -rw-r--r-- mh mh 58 Oct 26 9:4 description drwxr-xr-x 2 mh mh 48 Oct 26 9:4 hooks drwxr-xr-x 3 mh mh 2 Oct 26 9:4 info drwxr-xr-x 4 mh mh 36 Oct 26 9:4 objects drwxr-xr-x 4 mh mh 36 Oct 26 9:4 refs December 22 9/54

Adding files git add adds new or modified files to the index. % echo "Hello World" > file.txt % git add. December 22 2/54

Querying status Shows the status of the repository and the index. % git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: file.txt # December 22 2/54

Committing changes % git commit Created initial commit ba7bd8: Initial version files changed, insertions(+), deletions(-) create mode 644 file.txt % echo "Hello Matthieu" > file.txt % git commit -a Created commit 7fbf4cb: Modif files changed, insertions(+), deletions(-) Opens a text editor to enter a commit message and commits the change to the repository. December 22 22/54

The git index Represents modifications pending commit. 2 stages : add modified files to the index (add,rm) 2 flush the index to the repository (commit) Short-cuts chaining both operations: git commit file git commit dir (or git commit.) git commit -a December 22 23/54

Commits Adds a node at the end of the current branch. A B C Includes: the patch from old to new revision for text files the full new revision for binary files attributes of the commited file (access modes) name and e-mail address of the committer a log message optionnally, a digital signature December 22 24/54

Commits Adds a node at the end of the current branch. A B C D Includes: the patch from old to new revision for text files the full new revision for binary files attributes of the commited file (access modes) name and e-mail address of the committer a log message optionnally, a digital signature December 22 24/54

Interactive add % git add -i [files] Enters an interactive session to pick up changes to be added to next commit. Allows to have several unrelated un-committed modifications, and still do clean, separate commits. December 22 25/54

Looking back Various ways to display the history of modifications. % git log commit 7fbf4cb7c89776fbfb696f544e833a3ac Author: Matthieu Herrb <matthieu.herrb@laas.fr> Date: Tue Oct 28 2:29:33 28 + Modif commit ba7bd8b93ef9ddd89784bde8cbdaaf9732559 Author: Matthieu Herrb <matthieu.herrb@laas.fr> Date: Tue Oct 28 2:28:38 28 + Initial version % git log --stat % git log -p December 22 26/54

Examining changes Display the changes between the working files and the index, or between the index and the repository. echo "Good bye" > file.txt % git diff diff --git a/file.txt b/file.txt index 6bd8f3c..cee9ab 644 --- a/file.txt +++ b/file.txt @@ - + @@ -Hello Matthieu +Good bye % git add file.txt % git diff --cached December 22 27/54

Marking a version Create a tag object, containing a name and a comment. Opens the text editor to ender the comment. % git tag -a git-tuto-. % git tag -l git-tuto-. December 22 28/54

Fixing mistakes, reverting to a good version Restore the working dir to a given committed version, loosing all local changes: % git reset --hard [commit-id] If commit-id is missing, defaults to HEAD. Revert a given commit % git revert 3bace Finished one revert. Created commit c333ab5: Revert "3rd version" files changed, insertions(+), deletions(-) December 22 29/54

Agenda Introduction 2 Git concepts 3 Individual developper 4 Using branches 5 Working together 6 Other goodies 7 Appendix December 22 3/54

Branches A B C Existing history December 22 3/54

Branches D A B C Existing history Branch creation December 22 3/54

Branches D E A B C Existing history Branch creation commits in the new branch December 22 3/54

Branches D E A B C F Existing history Branch creation commits in the new branch commits in master December 22 3/54

Branches D E A B C F G Existing history Branch creation commits in the new branch commits in master merge the branch into master December 22 3/54

Branches D E H A B C F G Existing history Branch creation commits in the new branch commits in master merge the branch into master further commits in the branch December 22 3/54

Branches D E H I A B C F G J Existing history Branch creation commits in the new branch commits in master merge the branch into master further commits in the branch etc... December 22 3/54

Branches D E H I A B C F G J K Existing history Branch creation commits in the new branch commits in master merge the branch into master further commits in the branch etc... December 22 3/54

Branches D E H I L A B C F G J K Existing history Branch creation commits in the new branch commits in master merge the branch into master further commits in the branch etc... December 22 3/54

Switching branches Create a new branch: % git checkout -b newbranch Switch back to master: % git checkout master December 22 32/54

Listing available branches % git branch * master newbranch December 22 33/54

Merging changes from another branch % git merge branch Merge commits from branch and commits the result. 2 kinds of merges: fast forward: no conflicts, only new commits to add to your version normal merge: there are local changes - use a 3 way merge algorithm. December 22 34/54

Handling conflicts Conflicts happen when changes in a merged branch are incompatible with changes in the target branch Files with conflicts contain conflict markers They are not automatically added to the index. Resolve the conflict Add the files to the index Commit the result December 22 35/54

Tools to help with merge To help solving conflicts, git can use existing tools to help merging: kdiff3, tkdiff, meld, xxdiff, opendiff,... % git config --global merge.tool meld % git mergetool December 22 36/54

Picking individual changes Take one commit from another branch (bug fix) and apply it to the working branch. % git cherry-pick SHA_HASH December 22 37/54

Replaying changes from a branch Merges create lots of unwanted links in the git data graph. When a branch has only few local commits, rebase is more efficient. % git rebase master December 22 38/54

Rebase A B Existing commits December 22 39/54

Rebase C D E A B Existing commits Development branch December 22 39/54

Rebase C D E A B F G Existing commits Development branch Commits in master December 22 39/54

Rebase A B F G Existing commits Development branch Commits in master Start of rebase : remove commits from the branch December 22 39/54

Rebase C D E A B F G Existing commits Development branch Commits in master Start of rebase : remove commits from the branch End of rebase : recreate commits starting from HEAD de master December 22 39/54

Interactive rebase Useful to re-arrange commits locally, in order to clean up the history. % git rebase -i COMMITS opens a text editor with the list of commits specified. Rearrange the list according to instructions and save it. history will be re-written, following the new list. Don t use that afer pushing your commits December 22 4/54

Agenda Introduction 2 Git concepts 3 Individual developper 4 Using branches 5 Working together 6 Other goodies 7 Appendix December 22 4/54

Copying a repository git clone repo repo: an url to the remote repository. Can be: a pathname to a local repository on the same filesystem ssh://[user@]host/path - use SSH with given user git://host/path - anonymous acces with the GIT protocol http://host/path - anonymous acces with HTTP protocol December 22 42/54

Remote repository Remote repo A B C D master December 22 43/54

Remote repository Remote repo A B C D master clone Local repo A B C D origin/master master December 22 43/54

Updating from a repository % git pull Pulls the remote branches to the local repository, merges the default remote branch into the current one. (Including commit) Can produce a conflict: Solve the conflict Commit the result December 22 44/54

Remote branches % git branch -r lists remote branches (origin/branch). Remote branches can be tracked (automatically merged/pushed) using: % git checkout -t -b newbranch origin/newbranch December 22 45/54

Using rebase with remote branches fecth fetches remote commits without merging them. % git fetch Fetch and rebase at once % git pull --rebase equivalent to: % git fetch % git rebase origin/master December 22 46/54

Sending changes to a repository % git push Sends local commits to remote tracked branches. Produces an error if not up-to-date (need to pull or rebase first). Tags need to be pushed separatly: % git push --tags December 22 47/54

Managing remote repositories git remote command add name url add a remote set-url name url changes the url rename old new renames rm name removes a remote December 22 48/54

Agenda Introduction 2 Git concepts 3 Individual developper 4 Using branches 5 Working together 6 Other goodies 7 Appendix December 22 49/54

Identifying authors % git blame -- file.txt for each line of the file, shows the id and author of the last modification. December 22 5/54

Making a relase with git (Alternative to automake s make dist) Commit all changes, including the new macro revision number. Tag the result Use archive to produce a release. % git tag -a foo-.3 % git archive --prefix=foo-.3/ foo-.3 \ gzip -c - > foo-.3.tar.gz December 22 5/54

Submodules Submodules provide a way to glue several existing repositories into a bigger project. git submodule add url path adds a submodule, at path git submodule init init the sub-modules git submodule update clone or pull the submodules git submodule status display information about submodule status December 22 52/54

Agenda Introduction 2 Git concepts 3 Individual developper 4 Using branches 5 Working together 6 Other goodies 7 Appendix December 22 53/54

Git for CVS users CVS checkout update commit add remove diff log git clone pull commit -a + push add rm diff log December 22 54/54