git tutorial - official site of andreas hadiyono - gunadarma

22
1 GIT TUTORIAL GIT TUTORIAL Andreas Hadiyono, ST, MMSI Koordinator Kerjasama Luar Negeri Gunadarma University http://www.gunadarma.ac.id

Upload: others

Post on 11-Feb-2022

16 views

Category:

Documents


0 download

TRANSCRIPT

1

GIT TUTORIALGIT TUTORIAL

Andreas Hadiyono, ST, MMSI

Koordinator Kerjasama Luar NegeriGunadarma University

http://www.gunadarma.ac.id

2

Version Control● A system that records changes to a file or set of files

over time so that you can recall specific versions later

● though in reality you can do this with nearly any type of file on a computer.

● If you are a graphic or web designer and want to keep every version of an image or layout(which you would most certainly want to), a Version Control System (VCS) is a very wise thing to use.

3

Version Control -cont'd● It allows you to revert files back to a previous state,

revert the entire project back to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.

● Using a VCS also generally means that if you screw things up or lose files, you can easily recover. In addition, you get all this for very little overhead.

4

Local Version Control Systems

5

Central Version Control Language

Example: CVS, Subversion, and Perforce

6

Distributed Version Control Systems

7

GIT vs Other Version System

Differences GIT Other Version System

Focus About Data About File-Based

Thinking of GIT Snapshot Store Data

8

GIT vs Other Version System-cont'd

Other Version System GIT

9

The Main States Of GIT

● Committed● Data is safely stored in your local database.

● Modified● Changed the file but have not committed it to

your database yet. ● Staged

● Means we have marked a modified file in its current version to go into your next commit snapshot.

10

The Main States Of GIT-cont'd

11

The Main States Of GIT-cont'd

● The directory is where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone a repositoryfrom another computer.

● The working directory is a single checkout of one version of the project. These files are pulled out of the compressed database in the directory and placed on disk for you to use or modify.

● The staging area is a simple file, generally contained in your directory, that stores information about what will go into your next commit. It’s sometimes referred to as the index, but it’s becoming standard to refer to it as the staging area.

12

Git Advantages

● Resilience● No one repository has more data than any other

● Speed● Very fast operations compared to other VCS (I’m looking

at you CVS and Subversion)● Space

● Compression can be done across repository not just per file

● Minimizes local size as well as push/pull data transfers● Simplicity

● Object model is very simple● Large userbase with robust tools

13

Git Architecture

● Index● Stores information about current working directory and

changes made to it● Object Database

● Blobs (files)– Stored in .git/objects– Indexed by unique hash– All files are stored as blobs

● Trees (directories)● Commits

– One object for every commit– Contains hash of parent, name of author, time of commit, and

hash of the current tree● Tags

14

Some Commands

● Getting a Repository

● git init● git clone

● Commits● git add● git commit

● Getting information

● git help● git status● git diff● git log● git show

15

Our First Git Repository

● mkdir first-git-repo && cd first-git-repo

● git init● Creates the basic artifacts in the .git directory

● echo “Hello World” > hello.txt● git add .

● Adds content to the index● Index reflects the working version● Must be run prior to a commit

● git commit -a -m ‘Check in number one’

16

Key Git Files/Directories

● ~/.gitconfig● .git

● In top level of repository● Contains all objects, commits, configuration,

for project● .git/config has project specific configurations

● .gitignore● Stored in directory for ignoring

17

Working With Git

● echo “I love Git” >> hello.txt● git diff

● Shows changes we have made● git status

● Shows list of modified files● git add hello.txt● git diff

● No changes shown as diff compares to the index● git diff HEAD

● Now can see the changes in working version● git status● git commit -m ‘Second commit’

18

Viewing What Has Changed

● git log● Note the hash code for each commit.

● git show <OBJECT>● Can use full or shortened hash

● git reflog to see all changes that have occurred

19

Git and Patch files

● git diff HEAD^^● Show what has changed in last two commits

● git diff HEAD~10..HEAD~2● Show what changed between 10 commits ago and two

commits ago● git format-patch HEAD^^..HEAD

● Will create individual patch files per commit● git apply to apply patches

● git am to apply patches from an mbox● Can also compare

● Between specific objects● To branches/tags

20

Undoing What is Done

● git checkout● Used to checkout a specific version/branch of the tree

● git reset● Moves the tree back to a certain specified version● Use the --force to ignore working changes

● git revert● Reverts a commit● Does not delete the commit object, just applies a patch● Reverts can themselves be reverted!

● Git never deletes a commit object● It is very hard to shoot yourself in the foot!

21

Git and Tagging

● Tags are just human readable shortcuts for hashes

● Branches can be made from any commit

● git tag <tag-name>

Terima kasihTerima kasih