SlideShare a Scribd company logo
1 of 42
Introduction to
Git
@parallelit
(part 2)
Agenda
• Referring to a commit
• Undoing changes
• git reset
• git checkout
• git revert
• Reverting Vs resetting
• git rebase
• gitignore
• Git in action
• HEAD or head?
• Fast-forward Merge
• Tracked branches
• Tagging
• git commit --amend
Referring to a commit
The most direct way to reference a commit is via
its SHA-1 hash. This acts as the unique ID for
each commit. You can find the hash of all your
commits in the git log output.
Ref (1)
A ref is an indirect way of referring to a commit.
You can think of it as a user-friendly alias for a
commit hash. This is Git’s internal mechanism of
representing branches and tags.
Refs are stored as normal text files in the .git/refs
directory.
This is part of the reason why Git branches are so
lightweight compared to SVN.
Ref (2)
.git/refs/
heads/
master
develop
remotes/
origin/
master
tags/
v0.1
Special Refs
In addition to the refs directory, there are a few special refs that
reside in the top-level .git directory. They are listed below:
• HEAD := The currently checked-out commit/branch.
• FETCH_HEAD := The most recently fetched branch from a
remote repo.
• ORIG_HEAD := A backup reference to HEAD before drastic
changes to it.
• MERGE_HEAD := The commit(s) that you’re merging into the
current branch with git merge.
These refs are all created and updated by Git when necessary.
Undoing changes
The git reset, git checkout, and git revert commands are all
similar in that they undo some type of change in your repository.
Think about each command in terms of their effect on the three
main components of a Git repository: the working directory, the
staging area (or staged snapshot), and the repository (or commit
history).
git reset (1)
On the commit-level, resetting is a way to move
the tip of a branch to a different commit.
This usage of git reset is a simple way to undo
changes that haven’t been shared with anyone
else.
git reset (2)
In addition to moving the current branch, you can also get
git reset to alter the staged snapshot and/or the working
directory by passing it one of the following flags:
• --soft := The staged snapshot and working directory are
not altered in any way.
• --mixed := The staged snapshot is updated to match the
specified commit, but the working directory is not
affected. This is the default option.
• --hard := The staged snapshot and the working directory
are both updated to match the specified commit.
The scope of a git reset
operation
soft reset
repository
hash1
v1
hash2
v2
hash3
v3
staging
index
working
directory
HEAD
git reset —soft hash2
repository
hash1
v1
hash2
v2
staging
index
v3
working
directory
v3
HEAD
mixed reset
repository
hash1
v1
hash2
v2
hash3
v3
staging
index
working
directory
HEAD
git reset —mixed hash2
or
git reset hash2
repository
hash1
v1
hash2
v2
staging
index
v2
working
directory
v3
HEAD
hard reset
repository
hash1
v1
hash2
v2
hash3
v3
staging
index
working
directory
HEAD
git reset —hard hash2
repository
hash1
v1
hash2
v2
staging
index
v2
working
directory
v2
HEAD
git reset
• git checkout HEAD
• edit file1, file2, file3 / create file4
• git add file4
• git commit -m “This is my commit”
git reset
• git checkout HEAD
HARD RESET
• edit file1, file2, file3 / create file4
• git add file4
• git commit -m “This is my commit”
git reset
• git checkout HEAD
HARD RESET
• edit file1, file2, file3 / create file4
MIXED RESET
• git add file4
• git commit -m “This is my commit”
git reset
• git checkout HEAD
HARD RESET
• edit file1, file2, file3 / create file4
MIXED RESET
• git add file4
SOFT RESET
• git commit -m “This is my commit”
Git in action
git checkout
git checkout allows to:
• switch branches
When passed a branch name, it lets you switch between
branches.
• view an old commit
It moves HEAD to a different branch and update the working
directory to match. Since this has the potential to overwrite
local changes, Git forces you to commit any changes in the
working directory that will be lost during the checkout
operation.
Detached HEAD
Once you’ve built up a project history, git checkout is an easy
way to “load” any of these saved snapshots onto your
development machine.
Checking out an old commit is a read-only operation. It’s
impossible to harm your repository while viewing an old
revision. The “current” state of your project remains untouched
in the master branch.
During the normal course of development, the HEAD usually
points to master or some other local branch, but when you
check out a previous commit, HEAD no longer points to a
branch, it points directly to a commit. This is called a “detached
HEAD” state.
git revert (1)
Reverting undoes a commit by creating a new
commit. This is a safe way to undo changes, as it
has no chance of re-writing the commit history.
It's important to understand that git revert undoes
a single commit, it does not “revert” back to the
previous state of a project by removing all
subsequent commits.
git revert (2)
git revert (3)
Reverting undoes a commit by creating a new
commit. This is a safe way to undo changes, as it
has no chance of re-writing the commit history.
Contrast this with git reset, which does alter the
existing commit history. For this reason, git revert
should be used to undo changes on a public
branch, and git reset should be reserved for
undoing changes on a private branch.
git revert (4)
You can also think of git revert as a tool for
undoing committed changes, while git reset HEAD
is for undoing uncommitted changes.
Like git checkout, git revert has the potential to
overwrite files in the working directory, so it will
ask you to commit changes that would be lost
during the revert operation.
File-level operations
The git reset and git checkout commands also accept an
optional file path as a parameter. This dramatically alters their
behavior. Instead of operating on entire snapshots, this forces
them to limit their operations to a single file.
Git in action
Reverting Vs resetting (1)
Whereas reverting is designed to safely undo a public commit,
git reset is designed to undo local changes.
Reverting Vs resetting (2)
Revert Reset
Undo public commit local changes
Affect single commit all subsequent commits
Project history doesn’t change change
Safe yes no, permanent undo
Rewriting history using git
reset in a safe way
• git checkout HEAD
• git reset —hard hash1
• git reset —soft HEAD
git rebase (1)
Rebasing is the process of moving a branch to a new
base commit.
Git accomplishes this by creating new commits and
applying them to the specified base.
It’s literally rewriting your project history. It’s very
important to understand that, even though the branch
looks the same, it’s composed of entirely new commits.
The primary reason for rebasing is to maintain a linear
project history.
git rebase (2)
Initial history After rebase
The golden rule of rebasing:
Don’t rebase public history
As we’ve discussed with git commit --amend and git
reset, you should never rebase commits that have been
pushed to a public repository.
The rebase would replace the old commits with new ones,
and it would look like that part of your project history
abruptly vanished.
Before you run git rebase, always ask yourself, “Is
anyone else looking at this branch?”. If the answer is yes,
take your hands off the keyboard and start thinking about
a non-destructive way to make your changes. Otherwise,
you’re safe to re-write history as much as you like.
git rebase -i
Running git rebase with the -i flag begins an
interactive rebasing session. Instead of blindly
moving all of the commits to the new base,
interactive rebasing gives you the opportunity to
alter individual commits in the process.
This lets you clean up history by removing,
splitting, and altering an existing series of
commits.
Initial history
The Merge option
Merge the master branch
into the feature branch.
Merging is nice because
it’s a non-destructive
operation. The existing
branches are not
changed in any way.
On the other hand, this
also means that the
feature branch will have
an extraneous merge
commit every time you
need to incorporate
upstream changes.
*merge commit
Initial history
The Rebase option
Rebase the feature
branch onto master
branch.
This moves the entire
feature branch to
begin on the tip of the
master branch,
effectively
incorporating all of
the new commits in
master. But, instead of
using a merge
commit, rebasing re-
writes the project
history by creating
brand new commits
for each commit in the
original branch.
Rebase
*new commit
Initial history
The Rebase option
The major benefit of
rebasing is that you
get a much cleaner
project history.
First, it eliminates the
unnecessary merge
commits required by
git merge.
Second, as you can
see in the above
diagram, rebasing also
results in a perfectly
linear project history.
You can follow the tip
of feature all the way
to the beginning of the
project without any
forks.
Rebase
*new commit
Git in action
Coming next
• Branching
• Merging
• Gitflow Workflow
• GitHub Flow
• Pull request
http://sal.va.it/1OKfxiR
Download these slides on

More Related Content

What's hot

Gitのよく使うコマンド
Gitのよく使うコマンドGitのよく使うコマンド
Gitのよく使うコマンドYUKI Kaoru
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitLukas Fittl
 
15分でわかるGit入門
15分でわかるGit入門15分でわかるGit入門
15分でわかるGit入門to_ueda
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to gitEmanuele Olivetti
 
一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理Takafumi Yoshida
 
バージョン管理のワークフロー
バージョン管理のワークフローバージョン管理のワークフロー
バージョン管理のワークフローadd20
 
ノンプログラマでも今日から使える「Git」でバージョン管理
ノンプログラマでも今日から使える「Git」でバージョン管理ノンプログラマでも今日から使える「Git」でバージョン管理
ノンプログラマでも今日から使える「Git」でバージョン管理H2O Space. Co., Ltd.
 
なるべく噛み砕いたGit基礎講習
なるべく噛み砕いたGit基礎講習なるべく噛み砕いたGit基礎講習
なるべく噛み砕いたGit基礎講習石橋 啓太
 
Workshop on Git and GitHub
Workshop on Git and GitHubWorkshop on Git and GitHub
Workshop on Git and GitHubDSCVSSUT
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With GitNick Quaranto
 
Git and GitHub for Documentation
Git and GitHub for DocumentationGit and GitHub for Documentation
Git and GitHub for DocumentationAnne Gentle
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Git and github fundamentals
Git and github fundamentalsGit and github fundamentals
Git and github fundamentalsRajKharvar
 
デザイナのためのGit入門
デザイナのためのGit入門デザイナのためのGit入門
デザイナのためのGit入門dsuke Takaoka
 

What's hot (20)

git flow
git flowgit flow
git flow
 
Gitのよく使うコマンド
Gitのよく使うコマンドGitのよく使うコマンド
Gitのよく使うコマンド
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
 
15分でわかるGit入門
15分でわかるGit入門15分でわかるGit入門
15分でわかるGit入門
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to git
 
一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理
 
バージョン管理のワークフロー
バージョン管理のワークフローバージョン管理のワークフロー
バージョン管理のワークフロー
 
ノンプログラマでも今日から使える「Git」でバージョン管理
ノンプログラマでも今日から使える「Git」でバージョン管理ノンプログラマでも今日から使える「Git」でバージョン管理
ノンプログラマでも今日から使える「Git」でバージョン管理
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Git best practices workshop
Git best practices workshopGit best practices workshop
Git best practices workshop
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
 
なるべく噛み砕いたGit基礎講習
なるべく噛み砕いたGit基礎講習なるべく噛み砕いたGit基礎講習
なるべく噛み砕いたGit基礎講習
 
Workshop on Git and GitHub
Workshop on Git and GitHubWorkshop on Git and GitHub
Workshop on Git and GitHub
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Git and GitHub for Documentation
Git and GitHub for DocumentationGit and GitHub for Documentation
Git and GitHub for Documentation
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Git and github fundamentals
Git and github fundamentalsGit and github fundamentals
Git and github fundamentals
 
デザイナのためのGit入門
デザイナのためのGit入門デザイナのためのGit入門
デザイナのためのGit入門
 

Viewers also liked

"CONDICIÓN FÍSICA"
"CONDICIÓN FÍSICA""CONDICIÓN FÍSICA"
"CONDICIÓN FÍSICA"Lauraplaza18
 
Presentació pol
Presentació polPresentació pol
Presentació polpolijordi
 
Nanaimo Chamber of Commerce - Practical Tips for Building Productive Business...
Nanaimo Chamber of Commerce - Practical Tips for Building Productive Business...Nanaimo Chamber of Commerce - Practical Tips for Building Productive Business...
Nanaimo Chamber of Commerce - Practical Tips for Building Productive Business...Donna Mercier
 
Que es la economia nuevo
Que es la economia nuevoQue es la economia nuevo
Que es la economia nuevoAgustin Cogorno
 
Prostrate Enlargement-Must read for men above 40
Prostrate Enlargement-Must read for men above 40Prostrate Enlargement-Must read for men above 40
Prostrate Enlargement-Must read for men above 40Col Mukteshwar Prasad
 
Meu primeiro beijo !
Meu primeiro beijo !Meu primeiro beijo !
Meu primeiro beijo !Edna Meda
 
Cloud Computing with AWS
Cloud Computing with AWSCloud Computing with AWS
Cloud Computing with AWSEdureka!
 
Presentación empresa KESP SERVICIOS
Presentación empresa KESP SERVICIOSPresentación empresa KESP SERVICIOS
Presentación empresa KESP SERVICIOSKESP SERVICIOS
 
Human settlement transport and communication
Human settlement transport and communicationHuman settlement transport and communication
Human settlement transport and communicationkrati143
 

Viewers also liked (16)

Reccomendation letters
Reccomendation lettersReccomendation letters
Reccomendation letters
 
Automoviles
AutomovilesAutomoviles
Automoviles
 
Adairs Portfolio
Adairs PortfolioAdairs Portfolio
Adairs Portfolio
 
ACTIVE SOCK TREND
ACTIVE SOCK TRENDACTIVE SOCK TREND
ACTIVE SOCK TREND
 
"CONDICIÓN FÍSICA"
"CONDICIÓN FÍSICA""CONDICIÓN FÍSICA"
"CONDICIÓN FÍSICA"
 
Presentació pol
Presentació polPresentació pol
Presentació pol
 
8059
80598059
8059
 
Nanaimo Chamber of Commerce - Practical Tips for Building Productive Business...
Nanaimo Chamber of Commerce - Practical Tips for Building Productive Business...Nanaimo Chamber of Commerce - Practical Tips for Building Productive Business...
Nanaimo Chamber of Commerce - Practical Tips for Building Productive Business...
 
Que es la economia nuevo
Que es la economia nuevoQue es la economia nuevo
Que es la economia nuevo
 
Prostrate Enlargement-Must read for men above 40
Prostrate Enlargement-Must read for men above 40Prostrate Enlargement-Must read for men above 40
Prostrate Enlargement-Must read for men above 40
 
Meu primeiro beijo !
Meu primeiro beijo !Meu primeiro beijo !
Meu primeiro beijo !
 
Cloud Computing with AWS
Cloud Computing with AWSCloud Computing with AWS
Cloud Computing with AWS
 
Aula 4
Aula 4Aula 4
Aula 4
 
Presentación empresa KESP SERVICIOS
Presentación empresa KESP SERVICIOSPresentación empresa KESP SERVICIOS
Presentación empresa KESP SERVICIOS
 
Map Tools in AutoCAD Civil 3D
Map Tools in AutoCAD Civil 3DMap Tools in AutoCAD Civil 3D
Map Tools in AutoCAD Civil 3D
 
Human settlement transport and communication
Human settlement transport and communicationHuman settlement transport and communication
Human settlement transport and communication
 

Similar to Introduction to Git (part 2)

Git tutorial
Git tutorialGit tutorial
Git tutorialmobaires
 
Git slides
Git slidesGit slides
Git slidesNanyak S
 
Git rewriting git history
Git   rewriting git  historyGit   rewriting git  history
Git rewriting git historyLearningTech
 
Git tutorial git branches 20131206-Bryan
Git tutorial   git branches 20131206-BryanGit tutorial   git branches 20131206-Bryan
Git tutorial git branches 20131206-BryanLearningTech
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdfTilton2
 
Git and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideGit and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideRaghavendraVattikuti1
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | WorkshopAnuchit Chalothorn
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubDSC GVP
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?9 series
 
Git hub abduallah abu nada
Git hub   abduallah abu nadaGit hub   abduallah abu nada
Git hub abduallah abu nadaLama K Banna
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthroughBimal Jain
 

Similar to Introduction to Git (part 2) (20)

Git tips
Git tipsGit tips
Git tips
 
Mastering GIT
Mastering GITMastering GIT
Mastering GIT
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git slides
Git slidesGit slides
Git slides
 
Introduction to Git (part 1)
Introduction to Git (part 1)Introduction to Git (part 1)
Introduction to Git (part 1)
 
Git rewriting git history
Git   rewriting git  historyGit   rewriting git  history
Git rewriting git history
 
Git tutorial git branches 20131206-Bryan
Git tutorial   git branches 20131206-BryanGit tutorial   git branches 20131206-Bryan
Git tutorial git branches 20131206-Bryan
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
 
Git and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideGit and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slide
 
Git 101
Git 101Git 101
Git 101
 
GIT Rebasing and Merging
GIT Rebasing and MergingGIT Rebasing and Merging
GIT Rebasing and Merging
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
 
Git github
Git githubGit github
Git github
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
Git training v10
Git training v10Git training v10
Git training v10
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Git hub abduallah abu nada
Git hub   abduallah abu nadaGit hub   abduallah abu nada
Git hub abduallah abu nada
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 

More from Salvatore Cordiano

Transformed: Moving to the Product Operating Model
Transformed: Moving to the Product Operating ModelTransformed: Moving to the Product Operating Model
Transformed: Moving to the Product Operating ModelSalvatore Cordiano
 
Executive Master in Business Administration
Executive Master in Business AdministrationExecutive Master in Business Administration
Executive Master in Business AdministrationSalvatore Cordiano
 
Facile.it Partner 🚀 Hackathon 2023 - What we learned
Facile.it Partner 🚀 Hackathon 2023 - What we learnedFacile.it Partner 🚀 Hackathon 2023 - What we learned
Facile.it Partner 🚀 Hackathon 2023 - What we learnedSalvatore Cordiano
 
Accrescere la motivazione per raggiungere gli obiettivi
Accrescere la motivazione per raggiungere gli obiettiviAccrescere la motivazione per raggiungere gli obiettivi
Accrescere la motivazione per raggiungere gli obiettiviSalvatore Cordiano
 
Migliora le prestazioni dei tuoi collaboratori
Migliora le prestazioni dei tuoi collaboratoriMigliora le prestazioni dei tuoi collaboratori
Migliora le prestazioni dei tuoi collaboratoriSalvatore Cordiano
 
Delivering Effective Feedback - FP Talks
Delivering Effective Feedback - FP TalksDelivering Effective Feedback - FP Talks
Delivering Effective Feedback - FP TalksSalvatore Cordiano
 
No Silver Bullet - Essence and Accident in Software Engineering
No Silver Bullet - Essence and Accident in Software EngineeringNo Silver Bullet - Essence and Accident in Software Engineering
No Silver Bullet - Essence and Accident in Software EngineeringSalvatore Cordiano
 
Facile.it Partner Hackathon - What we learned
Facile.it Partner Hackathon - What we learnedFacile.it Partner Hackathon - What we learned
Facile.it Partner Hackathon - What we learnedSalvatore Cordiano
 
FP Hackathon - Closing, remarks and awards ceremony
FP Hackathon - Closing, remarks and awards ceremonyFP Hackathon - Closing, remarks and awards ceremony
FP Hackathon - Closing, remarks and awards ceremonySalvatore Cordiano
 
Facile.it Partner Hackathon 2022
Facile.it Partner Hackathon 2022Facile.it Partner Hackathon 2022
Facile.it Partner Hackathon 2022Salvatore Cordiano
 
The Blake Mouton Managerial Grid
The Blake Mouton Managerial GridThe Blake Mouton Managerial Grid
The Blake Mouton Managerial GridSalvatore Cordiano
 
Facile.it Partner Hackathon (kick-off)
Facile.it Partner Hackathon (kick-off)Facile.it Partner Hackathon (kick-off)
Facile.it Partner Hackathon (kick-off)Salvatore Cordiano
 

More from Salvatore Cordiano (20)

Transformed: Moving to the Product Operating Model
Transformed: Moving to the Product Operating ModelTransformed: Moving to the Product Operating Model
Transformed: Moving to the Product Operating Model
 
Executive Master in Business Administration
Executive Master in Business AdministrationExecutive Master in Business Administration
Executive Master in Business Administration
 
Facile.it Partner 🚀 Hackathon 2023 - What we learned
Facile.it Partner 🚀 Hackathon 2023 - What we learnedFacile.it Partner 🚀 Hackathon 2023 - What we learned
Facile.it Partner 🚀 Hackathon 2023 - What we learned
 
Accrescere la motivazione per raggiungere gli obiettivi
Accrescere la motivazione per raggiungere gli obiettiviAccrescere la motivazione per raggiungere gli obiettivi
Accrescere la motivazione per raggiungere gli obiettivi
 
Il potere delle domande
Il potere delle domandeIl potere delle domande
Il potere delle domande
 
Impara a delegare
Impara a delegareImpara a delegare
Impara a delegare
 
Migliora il tuo ascolto
Migliora il tuo ascoltoMigliora il tuo ascolto
Migliora il tuo ascolto
 
Negoziazione organizzativa
Negoziazione organizzativaNegoziazione organizzativa
Negoziazione organizzativa
 
Migliora le prestazioni dei tuoi collaboratori
Migliora le prestazioni dei tuoi collaboratoriMigliora le prestazioni dei tuoi collaboratori
Migliora le prestazioni dei tuoi collaboratori
 
Charles Péguy - Il denaro
Charles Péguy - Il denaroCharles Péguy - Il denaro
Charles Péguy - Il denaro
 
Delivering Effective Feedback - FP Talks
Delivering Effective Feedback - FP TalksDelivering Effective Feedback - FP Talks
Delivering Effective Feedback - FP Talks
 
No Silver Bullet - Essence and Accident in Software Engineering
No Silver Bullet - Essence and Accident in Software EngineeringNo Silver Bullet - Essence and Accident in Software Engineering
No Silver Bullet - Essence and Accident in Software Engineering
 
Facile.it Partner Hackathon - What we learned
Facile.it Partner Hackathon - What we learnedFacile.it Partner Hackathon - What we learned
Facile.it Partner Hackathon - What we learned
 
FP Hackathon - Closing, remarks and awards ceremony
FP Hackathon - Closing, remarks and awards ceremonyFP Hackathon - Closing, remarks and awards ceremony
FP Hackathon - Closing, remarks and awards ceremony
 
Facile.it Partner Hackathon 2022
Facile.it Partner Hackathon 2022Facile.it Partner Hackathon 2022
Facile.it Partner Hackathon 2022
 
Remarks about Ownership
Remarks about OwnershipRemarks about Ownership
Remarks about Ownership
 
Introducing Kaizen
Introducing KaizenIntroducing Kaizen
Introducing Kaizen
 
Introducing Eisenhower Matrix
Introducing Eisenhower MatrixIntroducing Eisenhower Matrix
Introducing Eisenhower Matrix
 
The Blake Mouton Managerial Grid
The Blake Mouton Managerial GridThe Blake Mouton Managerial Grid
The Blake Mouton Managerial Grid
 
Facile.it Partner Hackathon (kick-off)
Facile.it Partner Hackathon (kick-off)Facile.it Partner Hackathon (kick-off)
Facile.it Partner Hackathon (kick-off)
 

Recently uploaded

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 

Recently uploaded (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 

Introduction to Git (part 2)

  • 2. Agenda • Referring to a commit • Undoing changes • git reset • git checkout • git revert • Reverting Vs resetting • git rebase • gitignore • Git in action • HEAD or head? • Fast-forward Merge • Tracked branches • Tagging • git commit --amend
  • 3. Referring to a commit The most direct way to reference a commit is via its SHA-1 hash. This acts as the unique ID for each commit. You can find the hash of all your commits in the git log output.
  • 4. Ref (1) A ref is an indirect way of referring to a commit. You can think of it as a user-friendly alias for a commit hash. This is Git’s internal mechanism of representing branches and tags. Refs are stored as normal text files in the .git/refs directory. This is part of the reason why Git branches are so lightweight compared to SVN.
  • 6. Special Refs In addition to the refs directory, there are a few special refs that reside in the top-level .git directory. They are listed below: • HEAD := The currently checked-out commit/branch. • FETCH_HEAD := The most recently fetched branch from a remote repo. • ORIG_HEAD := A backup reference to HEAD before drastic changes to it. • MERGE_HEAD := The commit(s) that you’re merging into the current branch with git merge. These refs are all created and updated by Git when necessary.
  • 7. Undoing changes The git reset, git checkout, and git revert commands are all similar in that they undo some type of change in your repository. Think about each command in terms of their effect on the three main components of a Git repository: the working directory, the staging area (or staged snapshot), and the repository (or commit history).
  • 8. git reset (1) On the commit-level, resetting is a way to move the tip of a branch to a different commit. This usage of git reset is a simple way to undo changes that haven’t been shared with anyone else.
  • 9. git reset (2) In addition to moving the current branch, you can also get git reset to alter the staged snapshot and/or the working directory by passing it one of the following flags: • --soft := The staged snapshot and working directory are not altered in any way. • --mixed := The staged snapshot is updated to match the specified commit, but the working directory is not affected. This is the default option. • --hard := The staged snapshot and the working directory are both updated to match the specified commit.
  • 10. The scope of a git reset operation
  • 12. git reset —soft hash2 repository hash1 v1 hash2 v2 staging index v3 working directory v3 HEAD
  • 14. git reset —mixed hash2 or git reset hash2 repository hash1 v1 hash2 v2 staging index v2 working directory v3 HEAD
  • 16. git reset —hard hash2 repository hash1 v1 hash2 v2 staging index v2 working directory v2 HEAD
  • 17. git reset • git checkout HEAD • edit file1, file2, file3 / create file4 • git add file4 • git commit -m “This is my commit”
  • 18. git reset • git checkout HEAD HARD RESET • edit file1, file2, file3 / create file4 • git add file4 • git commit -m “This is my commit”
  • 19. git reset • git checkout HEAD HARD RESET • edit file1, file2, file3 / create file4 MIXED RESET • git add file4 • git commit -m “This is my commit”
  • 20. git reset • git checkout HEAD HARD RESET • edit file1, file2, file3 / create file4 MIXED RESET • git add file4 SOFT RESET • git commit -m “This is my commit”
  • 22. git checkout git checkout allows to: • switch branches When passed a branch name, it lets you switch between branches. • view an old commit It moves HEAD to a different branch and update the working directory to match. Since this has the potential to overwrite local changes, Git forces you to commit any changes in the working directory that will be lost during the checkout operation.
  • 23. Detached HEAD Once you’ve built up a project history, git checkout is an easy way to “load” any of these saved snapshots onto your development machine. Checking out an old commit is a read-only operation. It’s impossible to harm your repository while viewing an old revision. The “current” state of your project remains untouched in the master branch. During the normal course of development, the HEAD usually points to master or some other local branch, but when you check out a previous commit, HEAD no longer points to a branch, it points directly to a commit. This is called a “detached HEAD” state.
  • 24. git revert (1) Reverting undoes a commit by creating a new commit. This is a safe way to undo changes, as it has no chance of re-writing the commit history. It's important to understand that git revert undoes a single commit, it does not “revert” back to the previous state of a project by removing all subsequent commits.
  • 26. git revert (3) Reverting undoes a commit by creating a new commit. This is a safe way to undo changes, as it has no chance of re-writing the commit history. Contrast this with git reset, which does alter the existing commit history. For this reason, git revert should be used to undo changes on a public branch, and git reset should be reserved for undoing changes on a private branch.
  • 27. git revert (4) You can also think of git revert as a tool for undoing committed changes, while git reset HEAD is for undoing uncommitted changes. Like git checkout, git revert has the potential to overwrite files in the working directory, so it will ask you to commit changes that would be lost during the revert operation.
  • 28. File-level operations The git reset and git checkout commands also accept an optional file path as a parameter. This dramatically alters their behavior. Instead of operating on entire snapshots, this forces them to limit their operations to a single file.
  • 30. Reverting Vs resetting (1) Whereas reverting is designed to safely undo a public commit, git reset is designed to undo local changes.
  • 31. Reverting Vs resetting (2) Revert Reset Undo public commit local changes Affect single commit all subsequent commits Project history doesn’t change change Safe yes no, permanent undo
  • 32. Rewriting history using git reset in a safe way • git checkout HEAD • git reset —hard hash1 • git reset —soft HEAD
  • 33. git rebase (1) Rebasing is the process of moving a branch to a new base commit. Git accomplishes this by creating new commits and applying them to the specified base. It’s literally rewriting your project history. It’s very important to understand that, even though the branch looks the same, it’s composed of entirely new commits. The primary reason for rebasing is to maintain a linear project history.
  • 34. git rebase (2) Initial history After rebase
  • 35. The golden rule of rebasing: Don’t rebase public history As we’ve discussed with git commit --amend and git reset, you should never rebase commits that have been pushed to a public repository. The rebase would replace the old commits with new ones, and it would look like that part of your project history abruptly vanished. Before you run git rebase, always ask yourself, “Is anyone else looking at this branch?”. If the answer is yes, take your hands off the keyboard and start thinking about a non-destructive way to make your changes. Otherwise, you’re safe to re-write history as much as you like.
  • 36. git rebase -i Running git rebase with the -i flag begins an interactive rebasing session. Instead of blindly moving all of the commits to the new base, interactive rebasing gives you the opportunity to alter individual commits in the process. This lets you clean up history by removing, splitting, and altering an existing series of commits.
  • 37. Initial history The Merge option Merge the master branch into the feature branch. Merging is nice because it’s a non-destructive operation. The existing branches are not changed in any way. On the other hand, this also means that the feature branch will have an extraneous merge commit every time you need to incorporate upstream changes. *merge commit
  • 38. Initial history The Rebase option Rebase the feature branch onto master branch. This moves the entire feature branch to begin on the tip of the master branch, effectively incorporating all of the new commits in master. But, instead of using a merge commit, rebasing re- writes the project history by creating brand new commits for each commit in the original branch. Rebase *new commit
  • 39. Initial history The Rebase option The major benefit of rebasing is that you get a much cleaner project history. First, it eliminates the unnecessary merge commits required by git merge. Second, as you can see in the above diagram, rebasing also results in a perfectly linear project history. You can follow the tip of feature all the way to the beginning of the project without any forks. Rebase *new commit
  • 41. Coming next • Branching • Merging • Gitflow Workflow • GitHub Flow • Pull request