demystifjed Mikael Capelle mikael.capelle@irt-saintexupery.com - - PowerPoint PPT Presentation

demystifjed
SMART_READER_LITE
LIVE PREVIEW

demystifjed Mikael Capelle mikael.capelle@irt-saintexupery.com - - PowerPoint PPT Presentation

demystifjed Mikael Capelle mikael.capelle@irt-saintexupery.com 20182019 Git introduction Goal of this presentation: no more magic command understand each git command you use; never delete a local git repository if you


slide-1
SLIDE 1

…demystifjed

Mikael Capelle — mikael.capelle@irt-saintexupery.com 2018–2019

slide-2
SLIDE 2

Git introduction

Goal of this presentation:

  • no more magic command —

understand each git command you use;

  • never delete a local git repository

if you screwed — hidden secrets of git storage;

  • discover new commands and good

practice when using git as a version-control system.

1

slide-3
SLIDE 3

Git introduction

Goal of this presentation:

  • no more magic command —

understand each git command you use;

  • never delete a local git repository

if you screwed — hidden secrets of git storage;

  • discover new commands and good

practice when using git as a version-control system.

1

slide-4
SLIDE 4

Git introduction

Goal of this presentation:

  • no more magic command —

understand each git command you use;

  • never delete a local git repository

if you screwed — hidden secrets of git storage;

  • discover new commands and good

practice when using git as a version-control system.

1

slide-5
SLIDE 5

Git introduction

Goal of this presentation:

  • no more magic command —

understand each git command you use;

  • never delete a local git repository

if you screwed — hidden secrets of git storage;

  • discover new commands and good

practice when using git as a version-control system.

1

slide-6
SLIDE 6

Git introduction

Goal of this presentation:

  • no more magic command —

understand each git command you use;

  • never delete a local git repository

if you screwed — hidden secrets of git storage;

  • discover new commands and good

practice when using git as a version-control system.

1

slide-7
SLIDE 7

Git history

git = version-control system

  • First commit (!) in April 2005 by Linus Torvalds.
  • Maintained since July 2005 mainly by Junio Hamano (Google).
  • Stable release: 2.19.1 (version < 2.13 no longer supported).
  • Git repository of git itself:
  • https://git.kernel.org/pub/scm/git/git.git/
  • https://github.com/git/git (publish only)
  • Documentation and useful resources:

https://git-scm.com/

2

slide-8
SLIDE 8

Git in one picture

git is graph-based —

5fc67bae 61fc8496 d2e99c42 29a6cbde fa8b1b10 21b70784 11239bea 6fdece84 b7ed7837 f8566319 f8566319 e51c188a 74df16b5 06374286 3038df98 11991bbd 26e3c372 18424f62 3a27c1d9 e2547bf9 30dd3323 684c090f a23902d8 970c6c6c da0515cd 271d81c8 9b603cf0 v1.0.0 v1.0.1 master v1.0.1 add-feature-1 add-feature-2 fix-issue-4 fix-issue-2 add-feature-3 backup-5 HEAD

3

slide-9
SLIDE 9

Git architecture

git manages 3 different zones locally:

  • the working directory;
  • the staging area (or index);
  • the repository.

working directory staging area repository git add git commit

4

slide-10
SLIDE 10

Git architecture — In reality…

stash Temporary zone to backup fjles when performing other git operations. working directory Your actual working directory. This is what other softwares see. index Work to add to your next commit (snapshot). Also called the staging area. local repository Local version of remote repository. Contains all the (synchronized) history of your project. remote repository Remote location of your repository (e.g., Github). Also called upstream.

5

slide-11
SLIDE 11

Git architecture — In reality…

stash Temporary zone to backup fjles when performing other git operations. working directory Your actual working directory. This is what other softwares see. index Work to add to your next commit (snapshot). Also called the staging area. local repository Local version of remote repository. Contains all the (synchronized) history of your project. remote repository Remote location of your repository (e.g., Github). Also called upstream.

5

slide-12
SLIDE 12

Git architecture — In reality…

stash Temporary zone to backup fjles when performing other git operations. working directory Your actual working directory. This is what other softwares see. index Work to add to your next commit (snapshot). Also called the staging area. local repository Local version of remote repository. Contains all the (synchronized) history of your project. remote repository Remote location of your repository (e.g., Github). Also called upstream.

5

slide-13
SLIDE 13

Git architecture — In reality…

stash Temporary zone to backup fjles when performing other git operations. working directory Your actual working directory. This is what other softwares see. index Work to add to your next commit (snapshot). Also called the staging area. local repository Local version of remote repository. Contains all the (synchronized) history of your project. remote repository Remote location of your repository (e.g., Github). Also called upstream.

5

slide-14
SLIDE 14

Git architecture — In reality…

stash Temporary zone to backup fjles when performing other git operations. working directory Your actual working directory. This is what other softwares see. index Work to add to your next commit (snapshot). Also called the staging area. local repository Local version of remote repository. Contains all the (synchronized) history of your project. remote repository Remote location of your repository (e.g., Github). Also called upstream.

5

slide-15
SLIDE 15

Git architecture — In reality…

stash Temporary zone to backup fjles when performing other git operations. working directory Your actual working directory. This is what other softwares see. index Work to add to your next commit (snapshot). Also called the staging area. local repository Local version of remote repository. Contains all the (synchronized) history of your project. remote repository Remote location of your repository (e.g., Github). Also called upstream.

5

slide-16
SLIDE 16

Git architecture — In reality…

working directory stash index local repository remote repository

6

slide-17
SLIDE 17

Git architecture — In reality…

working directory stash index local repository remote repository stash

6

slide-18
SLIDE 18

Git architecture — In reality…

working directory stash index local repository remote repository stash stash apply | pop

6

slide-19
SLIDE 19

Git architecture — In reality…

working directory stash index local repository remote repository stash stash apply | pop add | rm | mv

6

slide-20
SLIDE 20

Git architecture — In reality…

working directory stash index local repository remote repository stash stash apply | pop add | rm | mv checkout

6

slide-21
SLIDE 21

Git architecture — In reality…

working directory stash index local repository remote repository stash stash apply | pop add | rm | mv checkout commit

6

slide-22
SLIDE 22

Git architecture — In reality…

working directory stash index local repository remote repository stash stash apply | pop add | rm | mv checkout commit reset

6

slide-23
SLIDE 23

Git architecture — In reality…

working directory stash index local repository remote repository stash stash apply | pop add | rm | mv checkout commit reset push

6

slide-24
SLIDE 24

Git architecture — In reality…

working directory stash index local repository remote repository stash stash apply | pop add | rm | mv checkout commit reset push pull fetch

6

slide-25
SLIDE 25

Git architecture — In reality…

working directory stash index local repository remote repository stash stash apply | pop add | rm | mv checkout commit reset push pull fetch checkout reset –hard

6

slide-26
SLIDE 26

Where’s my HEAD?

HEAD is a symbolic reference to (usually) the current branch —

  • HEAD is stored in .git/HEAD;
  • HEAD can be detached and points directly to a commit;
  • HEAD is (indirectly) used to determine the parent(s) of new

commits;

  • by default, HEAD points to the refs/heads/master reference;
  • there are many “HEAD”s: HEAD, FETCH_HEAD, ORIG_HEAD, …

7

slide-27
SLIDE 27

Git commands — An introduction

git config [--system|--global|-- local] <name> <value> — Update git confjguration in the repository (default behaviour), globally for the current user or system-wide.

git config --global core.editor emacs git config core.autocrlf true

References: https://git-scm.com/docs/ Cheatsheet: http://ndpsoftware.com/git-cheatsheet.html Windows users? Use Git Bash, included when downloading the

  • ffjcial git at https://git-scm.com/download/win.

8

slide-28
SLIDE 28

Git commands — An introduction

git config [--system|--global|-- local] <name> <value> — Update git confjguration in the repository (default behaviour), globally for the current user or system-wide.

git config --global core.editor emacs git config core.autocrlf true

References: https://git-scm.com/docs/ Cheatsheet: http://ndpsoftware.com/git-cheatsheet.html Windows users? Use Git Bash, included when downloading the

  • ffjcial git at https://git-scm.com/download/win.

8

slide-29
SLIDE 29

Git commands — An introduction

git config [--system|--global|-- local] <name> <value> — Update git confjguration in the repository (default behaviour), globally for the current user or system-wide.

git config --global core.editor emacs git config core.autocrlf true

References: https://git-scm.com/docs/ Cheatsheet: http://ndpsoftware.com/git-cheatsheet.html Windows users? Use Git Bash, included when downloading the

  • ffjcial git at https://git-scm.com/download/win.

8

slide-30
SLIDE 30

Git commands — An introduction

git config [--system|--global|-- local] <name> <value> — Update git confjguration in the repository (default behaviour), globally for the current user or system-wide.

git config --global core.editor emacs git config core.autocrlf true

References: https://git-scm.com/docs/ Cheatsheet: http://ndpsoftware.com/git-cheatsheet.html Windows users? Use Git Bash, included when downloading the

  • ffjcial git at https://git-scm.com/download/win.

8

slide-31
SLIDE 31

Git commands — An introduction

git config [--system|--global|-- local] <name> <value> — Update git confjguration in the repository (default behaviour), globally for the current user or system-wide.

git config --global core.editor emacs git config core.autocrlf true

References: https://git-scm.com/docs/ Cheatsheet: http://ndpsoftware.com/git-cheatsheet.html Windows users? Use Git Bash, included when downloading the

  • ffjcial git at https://git-scm.com/download/win.

8

slide-32
SLIDE 32

Git commands — An introduction

git config [--system|--global|-- local] <name> <value> — Update git confjguration in the repository (default behaviour), globally for the current user or system-wide.

git config --global core.editor emacs git config core.autocrlf true

References: https://git-scm.com/docs/ Cheatsheet: http://ndpsoftware.com/git-cheatsheet.html Windows users? Use Git Bash, included when downloading the

  • ffjcial git at https://git-scm.com/download/win.

8

slide-33
SLIDE 33

Git commands — An introduction

git init [--bare] — Initialize an empty local repository not associated with any upstream. git clone <url> — Initialize a local repository from the given remote repository at <url>. The default name of the remote within the local repository is origin and the default branch master. git remote -v — List remotes associated with the local repository. git remote add <remote> <url> — Add a remote to the local repository with the name <remote> and pointing to the given <url>. git remote remove <remote> — Remove the specifjed remote from the local repository. git remote set-url <remote> <url> — Point the specifjed remote to the specifjed URL.

9

slide-34
SLIDE 34

Git commands — An introduction

git init [--bare] — Initialize an empty local repository not associated with any upstream. git clone <url> — Initialize a local repository from the given remote repository at <url>. The default name of the remote within the local repository is origin and the default branch master. git remote -v — List remotes associated with the local repository. git remote add <remote> <url> — Add a remote to the local repository with the name <remote> and pointing to the given <url>. git remote remove <remote> — Remove the specifjed remote from the local repository. git remote set-url <remote> <url> — Point the specifjed remote to the specifjed URL.

9

slide-35
SLIDE 35

Git commands — An introduction

git init [--bare] — Initialize an empty local repository not associated with any upstream. git clone <url> — Initialize a local repository from the given remote repository at <url>. The default name of the remote within the local repository is origin and the default branch master. git remote -v — List remotes associated with the local repository. git remote add <remote> <url> — Add a remote to the local repository with the name <remote> and pointing to the given <url>. git remote remove <remote> — Remove the specifjed remote from the local repository. git remote set-url <remote> <url> — Point the specifjed remote to the specifjed URL.

9

slide-36
SLIDE 36

Git commands — An introduction

git init [--bare] — Initialize an empty local repository not associated with any upstream. git clone <url> — Initialize a local repository from the given remote repository at <url>. The default name of the remote within the local repository is origin and the default branch master. git remote -v — List remotes associated with the local repository. git remote add <remote> <url> — Add a remote to the local repository with the name <remote> and pointing to the given <url>. git remote remove <remote> — Remove the specifjed remote from the local repository. git remote set-url <remote> <url> — Point the specifjed remote to the specifjed URL.

9

slide-37
SLIDE 37

Git commands — An introduction

git init [--bare] — Initialize an empty local repository not associated with any upstream. git clone <url> — Initialize a local repository from the given remote repository at <url>. The default name of the remote within the local repository is origin and the default branch master. git remote -v — List remotes associated with the local repository. git remote add <remote> <url> — Add a remote to the local repository with the name <remote> and pointing to the given <url>. git remote remove <remote> — Remove the specifjed remote from the local repository. git remote set-url <remote> <url> — Point the specifjed remote to the specifjed URL.

9

slide-38
SLIDE 38

Git commands — An introduction

git init [--bare] — Initialize an empty local repository not associated with any upstream. git clone <url> — Initialize a local repository from the given remote repository at <url>. The default name of the remote within the local repository is origin and the default branch master. git remote -v — List remotes associated with the local repository. git remote add <remote> <url> — Add a remote to the local repository with the name <remote> and pointing to the given <url>. git remote remove <remote> — Remove the specifjed remote from the local repository. git remote set-url <remote> <url> — Point the specifjed remote to the specifjed URL.

9

slide-39
SLIDE 39

Git commands — An introduction

git status [-s] — Display the state of the local repository.

  • s gives you a shorter version.

git diff [--cached] <commit> — Display the difference between the working directory (or the index with the --cached

  • ption) and the specifjed commit (or the index if no commit is

specifjed). git log [--oneline] — Display the history of commits of the current branch. The option --oneline gives a shorter

  • utput.

git log --oneline --left- right <branch1> <branch2>

10

slide-40
SLIDE 40

Git commands — An introduction

git status [-s] — Display the state of the local repository.

  • s gives you a shorter version.

git diff [--cached] <commit> — Display the difference between the working directory (or the index with the --cached

  • ption) and the specifjed commit (or the index if no commit is

specifjed). git log [--oneline] — Display the history of commits of the current branch. The option --oneline gives a shorter

  • utput.

git log --oneline --left- right <branch1> <branch2>

10

slide-41
SLIDE 41

Git commands — An introduction

git status [-s] — Display the state of the local repository.

  • s gives you a shorter version.

git diff [--cached] <commit> — Display the difference between the working directory (or the index with the --cached

  • ption) and the specifjed commit (or the index if no commit is

specifjed). git log [--oneline] — Display the history of commits of the current branch. The option --oneline gives a shorter

  • utput.

git log --oneline --left- right <branch1> <branch2>

10

slide-42
SLIDE 42

Git commands — An introduction

git status [-s] — Display the state of the local repository.

  • s gives you a shorter version.

git diff [--cached] <commit> — Display the difference between the working directory (or the index with the --cached

  • ption) and the specifjed commit (or the index if no commit is

specifjed). git log [--oneline] — Display the history of commits of the current branch. The option --oneline gives a shorter

  • utput.

git log --oneline --left- right <branch1> <branch2>

10

slide-43
SLIDE 43

Git commands — An introduction

git pull — Pull the upstream associated with the current branch, upading the local repository, the index and the working

  • directory. Might fail if there are confmicts between the local state

and the remote one. git push — Push the current branch to its associated remote (git 2+), or all the branches with associated remotes and matching branch (git 1). git push <remote> <local-branch>:<remote- branch> — Update the remote branch of the given <remote> to match the specifjed local branch. git fetch — Update the local repository but not the index nor the working directory.

11

slide-44
SLIDE 44

Git commands — An introduction

git pull — Pull the upstream associated with the current branch, upading the local repository, the index and the working

  • directory. Might fail if there are confmicts between the local state

and the remote one. git push — Push the current branch to its associated remote (git 2+), or all the branches with associated remotes and matching branch (git 1). git push <remote> <local-branch>:<remote- branch> — Update the remote branch of the given <remote> to match the specifjed local branch. git fetch — Update the local repository but not the index nor the working directory.

11

slide-45
SLIDE 45

Git commands — An introduction

git pull — Pull the upstream associated with the current branch, upading the local repository, the index and the working

  • directory. Might fail if there are confmicts between the local state

and the remote one. git push — Push the current branch to its associated remote (git 2+), or all the branches with associated remotes and matching branch (git 1). git push <remote> <local-branch>:<remote- branch> — Update the remote branch of the given <remote> to match the specifjed local branch. git fetch — Update the local repository but not the index nor the working directory.

11

slide-46
SLIDE 46

Git commands — An introduction

git pull — Pull the upstream associated with the current branch, upading the local repository, the index and the working

  • directory. Might fail if there are confmicts between the local state

and the remote one. git push — Push the current branch to its associated remote (git 2+), or all the branches with associated remotes and matching branch (git 1). git push <remote> <local-branch>:<remote- branch> — Update the remote branch of the given <remote> to match the specifjed local branch. git fetch — Update the local repository but not the index nor the working directory.

11

slide-47
SLIDE 47

Git commands — An introduction

git add [-u] <files...> — Add the given fjle to the index, i.e., stage the fjle. The option -u update all fjles already in the index to match the working repository (but not newly created fjles). git rm [--cached] <files...> — Remove a fjle from both the index and the working directory. The option --cached allow to remove a fjle only from the index. git mv <files...> <file> — Rename fjle or move fjles to directory in both the working directory and the index (similar to the mv command). git checkout <files...> — Update fjles in the working directory to match their counterparts in the index.

12

slide-48
SLIDE 48

Git commands — An introduction

git add [-u] <files...> — Add the given fjle to the index, i.e., stage the fjle. The option -u update all fjles already in the index to match the working repository (but not newly created fjles). git rm [--cached] <files...> — Remove a fjle from both the index and the working directory. The option --cached allow to remove a fjle only from the index. git mv <files...> <file> — Rename fjle or move fjles to directory in both the working directory and the index (similar to the mv command). git checkout <files...> — Update fjles in the working directory to match their counterparts in the index.

12

slide-49
SLIDE 49

Git commands — An introduction

git add [-u] <files...> — Add the given fjle to the index, i.e., stage the fjle. The option -u update all fjles already in the index to match the working repository (but not newly created fjles). git rm [--cached] <files...> — Remove a fjle from both the index and the working directory. The option --cached allow to remove a fjle only from the index. git mv <files...> <file> — Rename fjle or move fjles to directory in both the working directory and the index (similar to the mv command). git checkout <files...> — Update fjles in the working directory to match their counterparts in the index.

12

slide-50
SLIDE 50

Git commands — An introduction

git add [-u] <files...> — Add the given fjle to the index, i.e., stage the fjle. The option -u update all fjles already in the index to match the working repository (but not newly created fjles). git rm [--cached] <files...> — Remove a fjle from both the index and the working directory. The option --cached allow to remove a fjle only from the index. git mv <files...> <file> — Rename fjle or move fjles to directory in both the working directory and the index (similar to the mv command). git checkout <files...> — Update fjles in the working directory to match their counterparts in the index.

12

slide-51
SLIDE 51

Git commands — An introduction

git commit [-m <msg>] — Create a new commit (snapshot) using the index with the specifjed message. If no message is specifjed, the default git editor is opened. git commit --amend — Update the last commit with changes from the index. git reset [<files...>] — Update the specifjed fjles (or all fjles) in the index to match their counterparts in the current local repository. git reset --mixed <commit> — Update the index to match the specifjed commit.

13

slide-52
SLIDE 52

Git commands — An introduction

git commit [-m <msg>] — Create a new commit (snapshot) using the index with the specifjed message. If no message is specifjed, the default git editor is opened. git commit --amend — Update the last commit with changes from the index. git reset [<files...>] — Update the specifjed fjles (or all fjles) in the index to match their counterparts in the current local repository. git reset --mixed <commit> — Update the index to match the specifjed commit.

13

slide-53
SLIDE 53

Git commands — An introduction

git commit [-m <msg>] — Create a new commit (snapshot) using the index with the specifjed message. If no message is specifjed, the default git editor is opened. git commit --amend — Update the last commit with changes from the index. git reset [<files...>] — Update the specifjed fjles (or all fjles) in the index to match their counterparts in the current local repository. git reset --mixed <commit> — Update the index to match the specifjed commit.

13

slide-54
SLIDE 54

Git commands — An introduction

git commit [-m <msg>] — Create a new commit (snapshot) using the index with the specifjed message. If no message is specifjed, the default git editor is opened. git commit --amend — Update the last commit with changes from the index. git reset [<files...>] — Update the specifjed fjles (or all fjles) in the index to match their counterparts in the current local repository. git reset --mixed <commit> — Update the index to match the specifjed commit.

13

slide-55
SLIDE 55

Git commands — An introduction

git checkout <branch> — Switch to the specifjed branch, updating the index and the working tree. git checkout <commit> — Switch to the specifjed commit, updating both the index and the working tree and entering a detached HEAD state. git reset --hard [<commit>] — Reset the index and working tree to match the specifjed commit (default to the current HEAD). Discard all changes not already commited!

14

slide-56
SLIDE 56

Git commands — An introduction

git checkout <branch> — Switch to the specifjed branch, updating the index and the working tree. git checkout <commit> — Switch to the specifjed commit, updating both the index and the working tree and entering a detached HEAD state. git reset --hard [<commit>] — Reset the index and working tree to match the specifjed commit (default to the current HEAD). Discard all changes not already commited!

14

slide-57
SLIDE 57

Git commands — An introduction

git checkout <branch> — Switch to the specifjed branch, updating the index and the working tree. git checkout <commit> — Switch to the specifjed commit, updating both the index and the working tree and entering a detached HEAD state. git reset --hard [<commit>] — Reset the index and working tree to match the specifjed commit (default to the current HEAD). Discard all changes not already commited!

14

slide-58
SLIDE 58

Git commands — An introduction

merge — Merging introduces the changes from a different branch into the current one, and create a new commit representing the “merge”. git merge [--no-commit] [-m <msg>] <branch> — Merge the change from the given <branch> into the current

  • branch. The --no-commit performs the merge but does not

commit the result. The -m option can be used to override the default commit message. git merge --abort — Abort the current merge process. git merge --continue — Continue the current merge process after resolving confmicts.

15

slide-59
SLIDE 59

Git commands — An introduction

merge — Merging introduces the changes from a different branch into the current one, and create a new commit representing the “merge”. git merge [--no-commit] [-m <msg>] <branch> — Merge the change from the given <branch> into the current

  • branch. The --no-commit performs the merge but does not

commit the result. The -m option can be used to override the default commit message. git merge --abort — Abort the current merge process. git merge --continue — Continue the current merge process after resolving confmicts.

15

slide-60
SLIDE 60

Git commands — An introduction

merge — Merging introduces the changes from a different branch into the current one, and create a new commit representing the “merge”. git merge [--no-commit] [-m <msg>] <branch> — Merge the change from the given <branch> into the current

  • branch. The --no-commit performs the merge but does not

commit the result. The -m option can be used to override the default commit message. git merge --abort — Abort the current merge process. git merge --continue — Continue the current merge process after resolving confmicts.

15

slide-61
SLIDE 61

Git commands — An introduction

rebase — Rebasing modifjes the history in order to insert commits from a different branches before the commits of the current branch. git rebase <branch> — Rebase the given branch into the current branch. git rebase --abort — Abort the current rebase process. git rebase --continue — Continue the current rebase process after resolving confmicts.

16

slide-62
SLIDE 62

Git commands — An introduction

rebase — Rebasing modifjes the history in order to insert commits from a different branches before the commits of the current branch. git rebase <branch> — Rebase the given branch into the current branch. git rebase --abort — Abort the current rebase process. git rebase --continue — Continue the current rebase process after resolving confmicts.

16

slide-63
SLIDE 63

Git commands — An introduction

rebase — Rebasing modifjes the history in order to insert commits from a different branches before the commits of the current branch. git rebase <branch> — Rebase the given branch into the current branch. git rebase --abort — Abort the current rebase process. git rebase --continue — Continue the current rebase process after resolving confmicts.

16

slide-64
SLIDE 64

Git commands — An introduction

cherry-pick — Cherry-picking applies the change from one or more commits to the current branch, creating new commits. git cherry-pick <commits...> — Cherry-pick the given commit(s) on top of the current branch. git cherry-pick --abort — Abort the current cherry-pick process. git cherry-pick --continue — Continue the current cherry-pick process after resolving confmicts.

17

slide-65
SLIDE 65

Git commands — An introduction

cherry-pick — Cherry-picking applies the change from one or more commits to the current branch, creating new commits. git cherry-pick <commits...> — Cherry-pick the given commit(s) on top of the current branch. git cherry-pick --abort — Abort the current cherry-pick process. git cherry-pick --continue — Continue the current cherry-pick process after resolving confmicts.

17

slide-66
SLIDE 66

Git commands — An introduction

cherry-pick — Cherry-picking applies the change from one or more commits to the current branch, creating new commits. git cherry-pick <commits...> — Cherry-pick the given commit(s) on top of the current branch. git cherry-pick --abort — Abort the current cherry-pick process. git cherry-pick --continue — Continue the current cherry-pick process after resolving confmicts.

17

slide-67
SLIDE 67

Git commands — An introduction

stash — Saves and restores local changes by storing them in the stash stack. git stash — Record local changes by creating a new stash on top of all previous ones. git stash apply — Apply the changes from the stash on top

  • f the stack to your current working directory.

git stash drop — Drop the stash on top of the stack. git stash pop — Equivalent to apply then drop.

18

slide-68
SLIDE 68

Git commands — An introduction

stash — Saves and restores local changes by storing them in the stash stack. git stash — Record local changes by creating a new stash on top of all previous ones. git stash apply — Apply the changes from the stash on top

  • f the stack to your current working directory.

git stash drop — Drop the stash on top of the stack. git stash pop — Equivalent to apply then drop.

18

slide-69
SLIDE 69

Git commands — An introduction

stash — Saves and restores local changes by storing them in the stash stack. git stash — Record local changes by creating a new stash on top of all previous ones. git stash apply — Apply the changes from the stash on top

  • f the stack to your current working directory.

git stash drop — Drop the stash on top of the stack. git stash pop — Equivalent to apply then drop.

18

slide-70
SLIDE 70

Git commands — An introduction

stash — Saves and restores local changes by storing them in the stash stack. git stash — Record local changes by creating a new stash on top of all previous ones. git stash apply — Apply the changes from the stash on top

  • f the stack to your current working directory.

git stash drop — Drop the stash on top of the stack. git stash pop — Equivalent to apply then drop.

18

slide-71
SLIDE 71

Resolving confmicts

Confmicts occurs when a fjle has two versions that must be merged, e.g., after a merge, a rebase, a cherry-pick or a stash.

<<<<<<< HEAD Version 2 ======= Version 3 >>>>>>> Other branch

19

slide-72
SLIDE 72

Resolving confmicts

  • 1. Abort the current process, e.g., with the --abort option that

most commands have.

  • 2. Retrieve one version of the fjle:

git checkout --theirs|--ours <files...>

The --theirs and --ours do not have the same meaning for merge or rebase.

  • 3. Modify the fjle manually to resolve the confmict.

Do it! Do it! Do it!

  • 4. Use a dedicated tool, e.g., git mergetool, Magit.

20

slide-73
SLIDE 73

Resolving confmicts

  • 1. Abort the current process, e.g., with the --abort option that

most commands have.

  • 2. Retrieve one version of the fjle:

git checkout --theirs|--ours <files...>

The --theirs and --ours do not have the same meaning for merge or rebase.

  • 3. Modify the fjle manually to resolve the confmict.

Do it! Do it! Do it!

  • 4. Use a dedicated tool, e.g., git mergetool, Magit.

20

slide-74
SLIDE 74

Resolving confmicts

  • 1. Abort the current process, e.g., with the --abort option that

most commands have.

  • 2. Retrieve one version of the fjle:

git checkout --theirs|--ours <files...>

The --theirs and --ours do not have the same meaning for merge or rebase.

  • 3. Modify the fjle manually to resolve the confmict.

Do it! Do it! Do it!

  • 4. Use a dedicated tool, e.g., git mergetool, Magit.

20

slide-75
SLIDE 75

Resolving confmicts

  • 1. Abort the current process, e.g., with the --abort option that

most commands have.

  • 2. Retrieve one version of the fjle:

git checkout --theirs|--ours <files...>

The --theirs and --ours do not have the same meaning for merge or rebase.

  • 3. Modify the fjle manually to resolve the confmict. → Do it! Do it!

Do it!

  • 4. Use a dedicated tool, e.g., git mergetool, Magit.

20

slide-76
SLIDE 76

Resolving confmicts

  • 1. Abort the current process, e.g., with the --abort option that

most commands have.

  • 2. Retrieve one version of the fjle:

git checkout --theirs|--ours <files...>

The --theirs and --ours do not have the same meaning for merge or rebase.

  • 3. Modify the fjle manually to resolve the confmict. → Do it! Do it!

Do it!

  • 4. Use a dedicated tool, e.g., git mergetool, Magit.

20

slide-77
SLIDE 77

Git objects

git stores objects within the .git/objects directory (local):

  • blob objects;
  • tree objects;
  • commit objects;
  • (annotated) tag objects.

Each object represented by its SHA-1 checksum (20 bytes, 40 hexadecimal characters), e.g:

.git/objects/98/7c3be764396c5a315e2c5ea536d8956aba82bc

Once created, objects never change.

21

slide-78
SLIDE 78

Git objects — blob

blob objects —

  • a blob contains the content of a “fjle” (a binary array of data);
  • identical contents means identical objects due to SHA-1 naming:
  • two identical fjles are represented by a single blob object;
  • a blob has no metadata associated directly with it:
  • names of fjles are stored within tree objects and within the index;
  • blob objects are usually created when (revision of) fjles are

added to the repository (git add) or fjles are compared (git diff). git does not store delta between fjle revisions.

22

slide-79
SLIDE 79

Git objects — tree

tree objects —

  • a tree is similar to a directory, it contains:
  • references to blob objects (fjles);
  • references to other tree objects (sub-directories);
  • a tree associates names and modes to blob and tree objects it

references;

  • a tree object has no “name” by itself.

23

slide-80
SLIDE 80

Git objects — tree

tree objects — possible modes:

  • 040000: directory
  • 100644: regular non-executable fjle
  • 100755: regular executable fjle
  • 120000: symbolic link
  • 160000: gitlink (submodule)

tree blob commit

24

slide-81
SLIDE 81

Git objects — commit

commit objects —

  • commit objects are the building blocks of git;
  • a commit object contains a snapshot of the working tree (a tree
  • bject) with associated metadata: author, committer, date, …;
  • commit objects are linked together by a parent-child

relationship, creating a revision tree;

  • references (branches, HEAD, tags) target commit objects using

their SHA-1 checksums (names).

25

slide-82
SLIDE 82

Git objects — Relation between objects

commit

<tree-id> <parent-id> <parent-id> <author> <date> <committer> <date> <message> 0..* <parent-id> 0..2

tree

<mode> <name> <blob-id> <mode> <name> <tree-id> <mode> <name> <blob-id> <...> 0..* <commit-id> 0..* 0..* <tree-id> 1 0..* <tree-id> 0..*

blob

<file-content> 0..* <blob-id> 0..*

tag (annotated)

<object-id> <object-type> <tag-name> <tagger> <date> <message> 0..* 1 <object-id> 1 1 26

slide-83
SLIDE 83

Git objects — Inspecting objects

# List files in the index. $ git ls-files --stage 100644 fa49b077972391ad58037050f2a75f74e3671e92 0 foo.txt 100644 96ac8f82e27c18f4a736ebb277fb0aa9648b711f 0 test.txt # Display the content of the given blob. $ git cat-file -p 96ac8f82e27c18f4a736ebb277fb0aa9648b711f version 4 $ git cat-file -p HEAD

tree 0f318b9fb1845be79439afc88c7b76dfa2ff8d91 parent eacd8426cd48c7e14f80b1650110439dbb13a7df author Mikaël Capelle <mikael.capelle@irt-saintexupery.com> 1541587661 +0100 committer Mikaël Capelle <mikael.capelle@irt-saintexupery.com> 1541587661 +0100 third commit

$ git cat-file -p HEAD^{tree} 100644 blob fa49b077972391ad58037050f2a75f74e3671e92 new.txt 100644 blob 7170a5278f42ea12d4b6de8ed1305af8c393e756 test.txt

27

slide-84
SLIDE 84

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version "

test.txt

"new file" "some file"

bar.txt

git init .git

28

slide-85
SLIDE 85

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 1"

test.txt

"new file" "some file"

bar.txt

echo "version 1" > test.txtgit

28

slide-86
SLIDE 86

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 1"

test.txt

"new file" "some file"

bar.txt

git add test.txtgit

28

slide-87
SLIDE 87

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 1"

test.txt

"new file" "some file"

bar.txt

git commit -m "first commit"git

28

slide-88
SLIDE 88

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 2"

test.txt

"new file" "some file"

bar.txt

echo "version 2" > test.txtgit

28

slide-89
SLIDE 89

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 2"

test.txt

"new file" "some file"

bar.txt

echo "some file" > bar.txtgit

28

slide-90
SLIDE 90

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 2"

test.txt

"new file"

new.txt

"some file"

bar.txt

echo "new file" > new.txtgit

28

slide-91
SLIDE 91

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 2"

test.txt

"new file"

new.txt

"some file"

bar.txt

git add test.txtgit

28

slide-92
SLIDE 92

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 2"

test.txt

"new file"

new.txt

"some file"

bar.txt

git add new.txtgit

28

slide-93
SLIDE 93

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 2"

test.txt

"new file"

new.txt

"some file"

bar.txt

git commit -m "second commit"git

28

slide-94
SLIDE 94

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 3"

test.txt

"new file"

new.txt

"some file"

bar.txt

echo "version 3" > test.txtgit

28

slide-95
SLIDE 95

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 3"

test.txt

"new file"

new.txt

"some file"

bar.txt

git commit -am "third commit"git

28

slide-96
SLIDE 96

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 4"

test.txt

"new file"

new.txt

"some file"

bar.txt

echo "version 4" > test.txtgit

28

slide-97
SLIDE 97

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 4"

test.txt

"new file"

new.txt

"some file"

bar.txt

git add -ugit

28

slide-98
SLIDE 98

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 4"

test.txt

"new file"

foo.txt

"some file"

bar.txt

mv new.txt foo.txtgit

28

slide-99
SLIDE 99

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 4"

test.txt

"new file"

foo.txt

"some file"

bar.txt

git rm new.txtgit

28

slide-100
SLIDE 100

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 4"

test.txt

"new file"

foo.txt

"some file"

bar.txt

git add foo.txtgit

28

slide-101
SLIDE 101

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

HEAD HEAD HEAD index

test.txt test.txt new.txt test.txt test.txt foo.txt

Working directory "version 5"

test.txt

"new file"

foo.txt

"some file"

bar.txt

echo "version 5" > test.txtgit

28

slide-102
SLIDE 102

$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) renamed: new.txt -> foo.txt modified: test.txt Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: test.txt Untracked files: (use "git add <file>..." to include in what will be committed) bar.txt

29

slide-103
SLIDE 103

Branch & References

reference = human-readable name for a SHA-1 hash —

  • references are stored under .git/refs;
  • there a three main types of references:
  • heads — head of local branches;
  • remotes — head of remote branches;
  • tags.

30

slide-104
SLIDE 104

References

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt refs/heads/master refs/tags/v1.0.0 commit on branch-1

eaa1d1 commit on branch-2 fab430

refs/heads/branch-1 refs/heads/branch-2

HEAD HEAD HEAD HEAD tree

e46540

"version 6"

b1dc10

test.txt new.txt

tree

2fb3f8

"version 7"

b4370c

test.txt new.txt

git

31

slide-105
SLIDE 105

References

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt refs/heads/master refs/tags/v1.0.0 commit on branch-1

eaa1d1 commit on branch-2 fab430

refs/heads/branch-1 refs/heads/branch-2

HEAD HEAD HEAD HEAD tree

e46540

"version 6"

b1dc10

test.txt new.txt

tree

2fb3f8

"version 7"

b4370c

test.txt new.txt

git

31

slide-106
SLIDE 106

References

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt refs/heads/master refs/tags/v1.0.0 commit on branch-1

eaa1d1 commit on branch-2 fab430

refs/heads/branch-1 refs/heads/branch-2

HEAD HEAD HEAD HEAD tree

e46540

"version 6"

b1dc10

test.txt new.txt

tree

2fb3f8

"version 7"

b4370c

test.txt new.txt

git tag v1.0.0git

31

slide-107
SLIDE 107

References

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt refs/heads/master refs/tags/v1.0.0 commit on branch-1

eaa1d1 commit on branch-2 fab430

refs/heads/branch-1 refs/heads/branch-2

HEAD HEAD HEAD HEAD tree

e46540

"version 6"

b1dc10

test.txt new.txt

tree

2fb3f8

"version 7"

b4370c

test.txt new.txt

git checkout -b branch-1git

31

slide-108
SLIDE 108

References

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt refs/heads/master refs/tags/v1.0.0 commit on branch-1

eaa1d1 commit on branch-2 fab430

refs/heads/branch-1 refs/heads/branch-2

HEAD HEAD HEAD HEAD tree

e46540

"version 6"

b1dc10

test.txt new.txt

tree

2fb3f8

"version 7"

b4370c

test.txt new.txt

echo "version 6" > test.txt && git commit -am "commit on branch- 1"git

31

slide-109
SLIDE 109

References

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt refs/heads/master refs/tags/v1.0.0 commit on branch-1

eaa1d1 commit on branch-2 fab430

refs/heads/branch-1 refs/heads/branch-2

HEAD HEAD HEAD HEAD tree

e46540

"version 6"

b1dc10

test.txt new.txt

tree

2fb3f8

"version 7"

b4370c

test.txt new.txt

git checkout mastergit

31

slide-110
SLIDE 110

References

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt refs/heads/master refs/tags/v1.0.0 commit on branch-1

eaa1d1 commit on branch-2 fab430

refs/heads/branch-1 refs/heads/branch-2

HEAD HEAD HEAD HEAD tree

e46540

"version 6"

b1dc10

test.txt new.txt

tree

2fb3f8

"version 7"

b4370c

test.txt new.txt

git checkout -b branch-2git

31

slide-111
SLIDE 111

References

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt refs/heads/master refs/tags/v1.0.0 commit on branch-1

eaa1d1 commit on branch-2 fab430

refs/heads/branch-1 refs/heads/branch-2

HEAD HEAD HEAD HEAD tree

e46540

"version 6"

b1dc10

test.txt new.txt

tree

2fb3f8

"version 7"

b4370c

test.txt new.txt

echo "version 7" > test.txt && git commit -am "commit on branch- 2"git

31

slide-112
SLIDE 112

$ git show-ref --head eaa1d1794759413c31d26fe0b66c6a9d73142d7f HEAD eaa1d1794759413c31d26fe0b66c6a9d73142d7f refs/heads/branch-1 fab4302c8ab48a509b3f55bb22c8ad790cffcdde refs/heads/branch-2 ed64911b6d93a10de9beb6c6ea03c58afbf75e03 refs/heads/master eaa1d1794759413c31d26fe0b66c6a9d73142d7f refs/remotes/origin/branch-1 ed64911b6d93a10de9beb6c6ea03c58afbf75e03 refs/remotes/origin/master fab4302c8ab48a509b3f55bb22c8ad790cffcdde refs/remotes/public/branch-2 eaa1d1794759413c31d26fe0b66c6a9d73142d7f refs/remotes/public/master ed64911b6d93a10de9beb6c6ea03c58afbf75e03 refs/tags/v1.0.0

32

slide-113
SLIDE 113

Remotes

remote = “hosted” version of the repository —

  • a remote is simply a git repository somewhere else:
  • a remote is often a bare repository (see --bare for the init and

clone commands), i.e., a repository without a working directory;

  • git handles four protocols to communicate with remotes:
  • local protocol — file:// — for remotes that are on an accessible

fjlesystem;

  • http(s) protocol — http(s):// — authenticated and

unauthenticated access;;

  • ssh protocol — ssh:// — easy to set-up, but does not allow

unauthenticated access;

  • git protocol — git://.

33

slide-114
SLIDE 114

Remotes

remote = “hosted” version of the repository —

  • a remote is identifjed by its name:
  • the default remote after clone is origin;
  • remotes are often confjgured to prevent hazardous behaviours:

$ git config --system receive.fsckObjects true $ git config --system receive.denyNonFastForwards true $ git config --system receive.denyDeletes true

  • in order to enable branch-specifjc control, hooks must be used.

34

slide-115
SLIDE 115

Remotes

remote = “hosted” version of the repository —

$ git init --bare Initialized empty Git repository in /data/git/mikael/tutogit.git $ git status fatal: This operation must be run in a work tree $ ls config description HEAD hooks info

  • bjects

refs

35

slide-116
SLIDE 116

git commands

  • Most commands are non-destructive:
  • most objects can be retrieved from the repository, even though it

may be hard to fjnd their names;

  • objects may have been added to the repository without a git

add;

  • only a few commands erase fjles in the working directory.
  • Some commands have very different behaviors when a path is

specifjed at the end, e.g., reset or checkout.

  • Some commands have a -p|--patch option to apply the

command hunk by hunk, e.g., you can add a fjle partially to the index using git add -p.

  • Most “hazardous”/destructive commands have a
  • n|--dry-run fmag to perform a dry run of the command, i.e.,

printing what the command would do without actually doing anything.

36

slide-117
SLIDE 117

git reset — V1

git reset [-q] [<tree-ish>] [--] [<paths> … ]

  • reset the index entry for <paths> so that it points to the
  • bjects for <paths> in the <tree-ish> revision;
  • does not update any fjles in the working directory;
  • if a fjle did not exists in the <tree-ish> revision, remove the

fjle from the index.

37

slide-118
SLIDE 118

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

refs/heads/master

HEAD index

test.txt test.txt test.txt foo.txt

Working directory "version 5"

test.txt

"new file"

foo.txt

"some file"

bar.txt

38

slide-119
SLIDE 119

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

refs/heads/master

HEAD index

test.txt test.txt test.txt foo.txt

Working directory "version 5"

test.txt

"new file"

foo.txt

"some file"

bar.txt

git reset HEAD -- test.txtgit

38

slide-120
SLIDE 120

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

refs/heads/master

HEAD index

test.txt test.txt test.txt foo.txt

Working directory "version 5"

test.txt

"new file"

foo.txt

"some file"

bar.txt

git reset 3e397a -- test.txtgit

38

slide-121
SLIDE 121

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

refs/heads/master

HEAD index

test.txt test.txt test.txt foo.txt

Working directory "version 5"

test.txt

"new file"

foo.txt

"some file"

bar.txt

git reset 3e397a -- foo.txtgit

38

slide-122
SLIDE 122

git reset — V2

git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]

  • reset the current branch head to the specifjed <commit>, reset

the index and reset fjles in the working tree:

  • --soft — reset the head but does not reset the index or fjles in

the working tree;

  • --mixed (default) — reset the head and the index but does not

reset fjles in the working tree;

  • --hard — reset the head, the index and all tracked fjles in the

working tree (i.e., discard local changes for tracked fjles);

  • --merge, --keep — reset the head, the index, and some fjles in

the working tree, depending on their states.

39

slide-123
SLIDE 123

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

refs/heads/master

HEAD index

test.txt test.txt foo.txt

Working directory "version 5"

test.txt

"new file"

foo.txt

"some file"

bar.txt

40

slide-124
SLIDE 124

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

refs/heads/master

HEAD index

test.txt test.txt foo.txt

Working directory "version 5"

test.txt

"new file"

foo.txt

"some file"

bar.txt

git reset --soft 3e397agit

40

slide-125
SLIDE 125

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

refs/heads/master

HEAD index

test.txt test.txt foo.txt

Working directory "version 5"

test.txt

"new file"

foo.txt

"some file"

bar.txt

git reset [--mixed] 3e397agit

40

slide-126
SLIDE 126

Git — Example

third commit

ed6491

second commit

eacd84

first commit

3e397a

tree

0f318b

tree

0155eb

tree

d8329f

"version 3"

7170a5

"version 2"

1f7a7a

"new file"

fa49b0

"version 1"

83baae

test.txt test.txt new.txt new.txt test.txt

"version 4"

96ac8f

refs/heads/master

HEAD index

test.txt test.txt foo.txt

Working directory "version 1"

test.txt

"new file"

foo.txt

"some file"

bar.txt

git reset --hard 3e397agit

40

slide-127
SLIDE 127

reset vs. checkout

HEAD1 Index Workdir “Safe”?2

Commit Level reset --soft [commit] REF reset [commit] REF reset --hard [commit] REF checkout [commit] HEAD File Level reset [commit] <paths> — checkout [commit] <paths> —

1Indicates if the command moves the reference (branch), REF, or only the HEAD. 2Indicates if the command is safe for the working directory.

41