matthieu moy - chamilo · make a git push after each git commit -a (use git pull if needed); do git...

22
Intro Git Advices Séance Machine Using Git Matthieu Moy [email protected] 2018-2019 Matthieu Moy ([email protected]) Git 2018-2019 < 1 / 13 >

Upload: others

Post on 21-Jul-2020

32 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Using Git

Matthieu Moy

[email protected]

2018-2019

Matthieu Moy ([email protected]) Git 2018-2019 < 1 / 13 >

Page 2: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Outline

1 Revision Control System

2 Git: Basic Principles

3 Advices Using Git

4 Séance Machine

Matthieu Moy ([email protected]) Git 2018-2019 < 2 / 13 >

Page 3: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Backups: The Old Good Time

Basic problems:I “Oh, my disk crashed.” / “Someone has stolen my laptop!”I “@#%!!, I’ve just deleted this important file!”I “Oops, I introduced a bug a long time ago in my code, how can I

see how it was before?”

Historical solutions:

I Replicate:$ cp -r ~/project/ ~/backup/(or better, copy to a remote machine like your Ensimag account)

I Keep history:$ cp -r ~/project/ ~/backup/project-2013-02-02

I . . .

Matthieu Moy ([email protected]) Git 2018-2019 < 3 / 13 >

Page 4: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Backups: The Old Good Time

Basic problems:I “Oh, my disk crashed.” / “Someone has stolen my laptop!”I “@#%!!, I’ve just deleted this important file!”I “Oops, I introduced a bug a long time ago in my code, how can I

see how it was before?”Historical solutions:

I Replicate:$ cp -r ~/project/ ~/backup/(or better, copy to a remote machine like your Ensimag account)

I Keep history:$ cp -r ~/project/ ~/backup/project-2013-02-02

I . . .

Matthieu Moy ([email protected]) Git 2018-2019 < 3 / 13 >

Page 5: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Collaborative Development: The Old Good Time

Basic problems: Several persons working on the same set of files1 “Hey, you’ve modified the same file as me, how do we merge?”,2 “Your modifications are broken, your code doesn’t even compile. Fix

your changes before sending it to me!”,

Historical solutions:

I Never two person work at the same time. ⇒ Doesn’t scale up!Unsafe.

I People work on the same directory (same machine, NFS, ACLs . . . )⇒ Painful because of (2) above.

I People work trying to avoid conflicts, and merge later.

Matthieu Moy ([email protected]) Git 2018-2019 < 4 / 13 >

Page 6: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Collaborative Development: The Old Good Time

Basic problems: Several persons working on the same set of files1 “Hey, you’ve modified the same file as me, how do we merge?”,2 “Your modifications are broken, your code doesn’t even compile. Fix

your changes before sending it to me!”,Historical solutions:

I Never two person work at the same time. ⇒ Doesn’t scale up!Unsafe.

I People work on the same directory (same machine, NFS, ACLs . . . )⇒ Painful because of (2) above.

I People work trying to avoid conflicts, and merge later.

Matthieu Moy ([email protected]) Git 2018-2019 < 4 / 13 >

Page 7: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Merging: Problem and Solution

My version

#include <stdio.h>

int main () {printf("Hello");

return EXIT_SUCCESS;}

Your version

#include <stdio.h>

int main () {printf("Hello!\n");

return 0;}

Common ancestor

#include <stdio.h>

int main () {printf("Hello");

return 0;}

This merge can be done for you by an automatic tool

Merging relies on history!

Collaborative development linked to backups

Matthieu Moy ([email protected]) Git 2018-2019 < 5 / 13 >

Page 8: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Merging: Problem and Solution

My version

#include <stdio.h>

int main () {printf("Hello");

return EXIT_SUCCESS;}

Your version

#include <stdio.h>

int main () {printf("Hello!\n");

return 0;}

Common ancestor

#include <stdio.h>

int main () {printf("Hello");

return 0;}

This merge can be done for you by an automatic tool

Merging relies on history!

Collaborative development linked to backups

Matthieu Moy ([email protected]) Git 2018-2019 < 5 / 13 >

Page 9: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Merging: Problem and Solution

My version

#include <stdio.h>

int main () {printf("Hello");

return EXIT_SUCCESS;}

Your version

#include <stdio.h>

int main () {printf("Hello!\n");

return 0;}

Common ancestor

#include <stdio.h>

int main () {printf("Hello");

return 0;}

This merge can be done for you by an automatic tool

Merging relies on history!

Collaborative development linked to backups

Matthieu Moy ([email protected]) Git 2018-2019 < 5 / 13 >

Page 10: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Merging: Problem and Solution

My version

#include <stdio.h>

int main () {printf("Hello");

return EXIT_SUCCESS;}

Your version

#include <stdio.h>

int main () {printf("Hello!\n");

return 0;}

Common ancestor

#include <stdio.h>

int main () {printf("Hello");

return 0;}

This merge can be done for you by an automatic tool

Merging relies on history!

Collaborative development linked to backups

Matthieu Moy ([email protected]) Git 2018-2019 < 5 / 13 >

Page 11: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Merging

Space of possible revisions

(arbitrarily represented in 2D)

Matthieu Moy ([email protected]) Git 2018-2019 < 6 / 13 >

Page 12: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Merging

Space of possible revisions

(arbitrarily represented in 2D)

Mine

Yours

Matthieu Moy ([email protected]) Git 2018-2019 < 6 / 13 >

Page 13: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Merging

Space of possible revisions

(arbitrarily represented in 2D)

Mine

YoursAncestor

Matthieu Moy ([email protected]) Git 2018-2019 < 6 / 13 >

Page 14: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Merging

Space of possible revisions

(arbitrarily represented in 2D)

Mine

YoursAncestor

Merged revision

Matthieu Moy ([email protected]) Git 2018-2019 < 6 / 13 >

Page 15: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Revision Control System: Basic Idea

Keep track of history:I commit = snapshot of the current state,I Meta-data (user’s name, date, descriptive message,. . . ) recorded in

commit.Use it for merging/collaborative development.

I Each user works on its own copy,I User explicitly “takes” modifications from others when (s)he wants.

Matthieu Moy ([email protected]) Git 2018-2019 < 7 / 13 >

Page 16: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Outline

1 Revision Control System

2 Git: Basic Principles

3 Advices Using Git

4 Séance Machine

Matthieu Moy ([email protected]) Git 2018-2019 < 8 / 13 >

Page 17: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Git: Basic concepts

Each working directory contains:I The files you work on (as usual)I The history, or “repository” (in the directory .git/)

Basic operations:I git clone: get a copy of an existing repository (files + history)I git commit: create a new revision in a repositoryI git pull: get revisions from a repositoryI git push: send revisions to a repositoryI git add, git rm and git mv: tell Git which files should be trackedI git status: know what’s going on

For us:I Each team creates a shared repository, in addition to work trees

Matthieu Moy ([email protected]) Git 2018-2019 < 9 / 13 >

Page 18: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Outline

1 Revision Control System

2 Git: Basic Principles

3 Advices Using Git

4 Séance Machine

Matthieu Moy ([email protected]) Git 2018-2019 < 10 / 13 >

Page 19: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Advices Using Git (for beginners)

Never exchange files outside Git’s control (email, scp, usb key),except if you really know what you’re doing;

Always use git commit with -a;Make a git push after each git commit -a (use git pull ifneeded);Do git pull regularly, to remain synchronized with yourteammates. You need to make a git commit -a before you canmake a git pull (this is to avoid mixing manual changes withmerges).Do not make useless changes to your code. Do not let youreditor/IDE reformat code that is not yours.

Matthieu Moy ([email protected]) Git 2018-2019 < 11 / 13 >

Page 20: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Advices Using Git (for beginners)

Never exchange files outside Git’s control (email, scp, usb key),except if you really know what you’re doing;Always use git commit with -a;Make a git push after each git commit -a (use git pull ifneeded);Do git pull regularly, to remain synchronized with yourteammates. You need to make a git commit -a before you canmake a git pull (this is to avoid mixing manual changes withmerges).Do not make useless changes to your code. Do not let youreditor/IDE reformat code that is not yours.

Matthieu Moy ([email protected]) Git 2018-2019 < 11 / 13 >

Page 21: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Outline

1 Revision Control System

2 Git: Basic Principles

3 Advices Using Git

4 Séance Machine

Matthieu Moy ([email protected]) Git 2018-2019 < 12 / 13 >

Page 22: Matthieu Moy - Chamilo · Make a git push after each git commit -a (use git pull if needed); Do git pull regularly, to remain synchronized with your teammates. You need to make a

Intro Git Advices Séance Machine

Séance Machine

Énoncé : Stage Unix, Partie Unix Avancé, Séance 1 (Ensiwiki)À terminer en libre service après la séance encadréecf. aussi « Introduction à Git » dans EnsiWiki

Matthieu Moy ([email protected]) Git 2018-2019 < 13 / 13 >