SlideShare a Scribd company logo
Avilay Parekh (@avilay)
CTO, Co-Founder of Informion, Inc.
January 2014
Learn how to use git-checkout, git-reset,
git-revert, and git-clean
Walk through typical undo scenarios using
these commands
Kevin Skoglund’s excellent git tutorial on
Lynda.com
Pro Git Book
(http://www.amazon.com/Pro-Experts-Voice-Software-
Development/dp/1430218339/)
You know the 3-tree architecture used in git.
You are familiar with the terms repo, staged
index, working directory, and HEAD.
You are familiar with basic git commands like
git add, git status, git log, git commit.
git checkout [changeset] -- <file>
git reset [option] [changeset]
git revert <changeset>
git clean [-n] [-f]
git checkout [changeset] -- <file>
git reset [option] [changeset]
git revert <changeset>
git clean [-n] [-f]
Can be used in a
number of
different
scenarios
A bit difficult to
understand at a
conceptual level
git checkout [changeset] -- <file>
git reset [option] [changeset]
git revert <changeset>
git clean [-n] [-f]
Does a single task
really well
Easy to
conceptually
understand what
is going on
A way to undo any uncommitted changes in the
staging index or the working directory
repo is left untouched
Undo un-staged changes to a particular file in my
working directory.
1
repo
Staging
index
Working
directory
git checkout --
repo
Staging
index
Working
directory
Initial State Final State
Initial State
The repo has 3 commits.
Staging index has some
uncommitted changes.
hello.py in the working
directory has some changes
that have not been staged
yet.
1
a1b2c3 fff999 5d6ef1
HEAD
repo
staging index working
directory
git checkout --
hello.py has
un-added
changes
hello.py has
some
uncommitted
changes
Git Checkout --
The two dashes -- are telling git not to
switch branches; something git
checkout command will do otherwise.
We are telling git to undo all current
changes to hello.py and go back to the
version in the staging index.
To undo changes to all files in the
working directory say –
git checkout -- .
1
git checkout -- hello.py
git checkout --
Final State
Staging index remains
unchanged.
hello.py in the working
directory is overwritten by
the version in the staging
index.
1
a1b2c3 fff999 5d6ef1
HEAD
repo
staging index working
directory
git checkout --
hello.py is
same as
staging
index
No changes
in the
staging
index
With a bunch of files in staged or unstaged
states, undo changes to a particular file and
revert it to a version 2 commits ago.
2
repo
Staging
index
Working
directory
git checkout --
repo
Staging
index
Working
directory
Initial State Final State
Initial State
The repo has 3 commits.
There are a bunch of
staged, but uncommitted
files shown in green.
There are a bunch of
unstaged changes to files in
the working directory
shown in red.
2 git checkout --
a1b2c3 fff999 5d6ef1
HEAD
repo
Added (but
uncommitted
changes)
New changes
not added to
stage
staging index working
directory
Git Checkout --
Note, the changeset fff999 is
parent of HEAD.
We are telling git to undo all
current changes to a single file
“hello.py” and go back to the
version in the changeset fff999.
Unlike Scenario 1, the staging
index will also change
2 git checkout --
git checkout fff999 -- hello.py
Final State
First hello.py in the staging
index is overwritten by the
version in commit fff999.
Then hello.py in the working
directory is overwritten by the
version in the staging index.
All other staged and unstaged
files are left alone.
2 git checkout --
a1b2c3 fff999 5d6ef1
HEAD
repo
staging index working
directory
hello.py is
changed to
the version
2 commits
ago
hello.py is
changed to
the staging
version
A way to move the HEAD pointer in the repo.
Staging index and working directory can also be
changed by using the right options
Undo the last commit in the repo, but keep all the
uncommitted and unstaged changes intact
3
repo
Staging
index
Working
directory
git reset --soft
repo
Staging
index
Working
directory
Initial State Final State
Initial State
The repo has 3 commits.
Staging index has some
uncommitted changes.
hello.py in the working
directory has some
unstaged changes.
3
a1b2c3 fff999 5d6ef1
HEAD
repo
staging index working
directory
git reset --soft
hello.py has
un-added
changes
hello.py has
some
uncommitted
changes
git reset --soft
We are telling git to move the HEAD
pointer to the specified commit ID
which is the parent of the current HEAD
The soft switch is telling git not to touch
the working directory or the staging
index
3
git reset --soft ff999
git reset --soft
Final State
HEAD pointer moves one
commit up. Any new
commits will be appended
to fff999 effectively losing
5d6ef1.
Staging index and working
directory remain untouched.
3
a1b2c3 fff999
repo
staging index working
directory
git reset --soft
No changes
to the
working
directory
No changes
in the
staging
index
HEAD
Undo the last commit in the repo, discard all
staged changes, but keep the working directory
intact
4
repo
Staging
index
Working
directory
git reset --mixed
repo
Staging
index
Working
directory
Initial State Final State
Initial State
The repo has 3 commits.
Staging index has some
uncommitted changes.
hello.py in the working
directory has some
unstaged changes.
4
a1b2c3 fff999 5d6ef1
HEAD
repo
staging index working
directory
git reset --mixed
hello.py has
un-added
changes
hello.py has
some
uncommitted
changes
git reset --mixed
We are telling git to move the HEAD
pointer to the specified commit ID
which is the parent of the current HEAD
The mixed switch is telling git to make
the staging index look like HEAD after
it has been moved
Mixed is the default switch if none is
provided
4
git reset --mixed ff999
git reset --mixed
Final State
HEAD pointer moves one
commit up. Any new
commits will be appended
to fff999 effectively losing
5d6ef1.
Staging index looks like
fff999
Working directory is left
unchanged
4
a1b2c3 fff999
repo
staging index working
directory
git reset --mixed
No changes
to the
working
directory
HEAD
Undo the last commit in the repo, discard all
staged and unstaged changes
5
repo
Staging
index
Working
directory
git reset --hard
repo
Staging
index
Working
directory
Initial State Final State
Initial State
The repo has 3 commits.
Staging index has some
uncommitted changes.
Working directory has
some unstaged changes.
5
a1b2c3 fff999 5d6ef1
HEAD
repo
staging index working
directory
git reset --hard
hello.py has
un-added
changes
hello.py has
some
uncommitted
changes
git reset --hard
We are telling git to move the HEAD
pointer to the specified commit ID
which is the parent of the current HEAD
The hard switch is telling git to make
the staging index look like HEAD after
it has been moved, and make the
working directory look like staging
after it has been changed
Effectively losing all work after fff999!
5
git reset --hard ff999
git reset --hard
Final State
HEAD pointer moves one
commit up. Any new
commits will be appended
to fff999 effectively losing
5d6ef1.
All changes to the staging
index and the working
directory after fff999 are
lost.
5
a1b2c3 fff999
repo
staging index working
directory
git reset --hard
HEAD
How can you undo all uncommitted changes (i.e.,
staged and unstaged changes) and go back to what
was last committed?
 git checkout HEAD -- .
 git reset --hard HEAD
How can you undo all uncommitted changes (i.e.,
staged and unstaged changes) and go back to what
was last committed?
 git checkout HEAD -- .
 git reset --hard HEAD
A way to discard changes made in a specific
commit
Always affects all 3 trees
Working directory has to be clean before a revert
Undo the last commit
6
repo
Staging
index
Working
directory
git revert
repo
Staging
index
Working
directory
Initial State Final State
Initial State
The repo has 3 commits.
Working directory is clean.
6
a1b2c3 fff999 5d6ef1
HEAD
repo
staging index working
directory
git revert
git revert
We are telling git to discard changes in
the specified commit, in this case
HEAD, which is the last commit
6
git revert HEAD
git reset --hard
Final State
What really happens is that
a new commit is made which
has the inverse of all
changes that were in 5d6ef1,
effectively making the
project look like fff999
In theory, reverting 333aaa
will “redo” the previous
“undo”
6
staging index working
directory
git reset --hard
a1b2c3 fff999 5d6ef1
HEADrepo
333aaa
The “only” way to discard untracked changes, i.e,
new files that have not been added yet
These files can always just be rm’ed

More Related Content

What's hot

Git training v10
Git training v10Git training v10
Git training v10
Skander Hamza
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
Safique Ahmed Faruque
 
Introduction git
Introduction gitIntroduction git
Introduction git
Dian Sigit Prastowo
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
Thomas Rausch
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
James Gray
 
Git advanced
Git advancedGit advanced
Git advanced
Peter Vandenabeele
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
glen_a_smith
 
Overview of github
Overview of githubOverview of github
Overview of github
Sangeetha Subramani
 
Git workflows presentation
Git workflows presentationGit workflows presentation
Git workflows presentation
Mack Hardy
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
Md. Ahsan Habib Nayan
 
A successful Git branching model
A successful Git branching model A successful Git branching model
A successful Git branching model
abodeltae
 
Version control system
Version control systemVersion control system
Version control system
Andrew Liu
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
Lukas Fittl
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
Anurag Upadhaya
 
Introduction to Gitlab | Gitlab 101 | Training Session
Introduction to Gitlab | Gitlab 101 | Training SessionIntroduction to Gitlab | Gitlab 101 | Training Session
Introduction to Gitlab | Gitlab 101 | Training Session
Anwarul Islam
 
Gitlab ci-cd
Gitlab ci-cdGitlab ci-cd
Gitlab ci-cd
Dan MAGIER
 
Continuous Integration/Deployment with Gitlab CI
Continuous Integration/Deployment with Gitlab CIContinuous Integration/Deployment with Gitlab CI
Continuous Integration/Deployment with Gitlab CI
David Hahn
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Lee Hanxue
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Simplilearn
 
Git
GitGit

What's hot (20)

Git training v10
Git training v10Git training v10
Git training v10
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git advanced
Git advancedGit advanced
Git advanced
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Overview of github
Overview of githubOverview of github
Overview of github
 
Git workflows presentation
Git workflows presentationGit workflows presentation
Git workflows presentation
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
A successful Git branching model
A successful Git branching model A successful Git branching model
A successful Git branching model
 
Version control system
Version control systemVersion control system
Version control system
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
Introduction to Gitlab | Gitlab 101 | Training Session
Introduction to Gitlab | Gitlab 101 | Training SessionIntroduction to Gitlab | Gitlab 101 | Training Session
Introduction to Gitlab | Gitlab 101 | Training Session
 
Gitlab ci-cd
Gitlab ci-cdGitlab ci-cd
Gitlab ci-cd
 
Continuous Integration/Deployment with Gitlab CI
Continuous Integration/Deployment with Gitlab CIContinuous Integration/Deployment with Gitlab CI
Continuous Integration/Deployment with Gitlab CI
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
 
Git
GitGit
Git
 

Similar to Git undo

Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
Jason Byrne
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
Katie Sylor-Miller
 
Git Cards - Powerpoint Format
Git Cards - Powerpoint FormatGit Cards - Powerpoint Format
Git Cards - Powerpoint Format
Adam Lowe
 
Git Cards - Keynote Format
Git Cards - Keynote FormatGit Cards - Keynote Format
Git Cards - Keynote Format
Adam Lowe
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
Jesús Miguel Benito Calzada
 
Git-ing out of your git messes - Fluent Conf 2017
Git-ing out of  your git messes - Fluent Conf 2017Git-ing out of  your git messes - Fluent Conf 2017
Git-ing out of your git messes - Fluent Conf 2017
Katie Sylor-Miller
 
Git commands
Git commandsGit commands
Git commands
Viyaan Jhiingade
 
Git workshop
Git workshopGit workshop
Git workshop
Mateusz Galazyn
 
GIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control SystemGIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control System
Tommaso Visconti
 
Git like a pro EDD18 - Full edition
Git like a pro EDD18 - Full editionGit like a pro EDD18 - Full edition
Git like a pro EDD18 - Full edition
Jesús Miguel Benito Calzada
 
Git presentation
Git presentationGit presentation
Git presentation
Lorenzo Baracchi
 
GIT Training
GIT TrainingGIT Training
GIT Training
Muhammad Ibrar
 
Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheet
Abdul Basit
 
Gittalk
GittalkGittalk
Gittalk
prtinsley
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
Ananth Kumar
 
Introducción a git y GitHub
Introducción a git y GitHubIntroducción a git y GitHub
Introducción a git y GitHub
Lucas Videla
 
Git basics for beginners
Git basics for beginnersGit basics for beginners
Git basics for beginners
PravallikaTammisetty
 
Git real slides
Git real slidesGit real slides
Git real slides
Lucas Couto
 
Git_real_slides
Git_real_slidesGit_real_slides
Git_real_slides
Khanh NL-bantoilatoi
 
Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changes
LearningTech
 

Similar to Git undo (20)

Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
Git Cards - Powerpoint Format
Git Cards - Powerpoint FormatGit Cards - Powerpoint Format
Git Cards - Powerpoint Format
 
Git Cards - Keynote Format
Git Cards - Keynote FormatGit Cards - Keynote Format
Git Cards - Keynote Format
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
 
Git-ing out of your git messes - Fluent Conf 2017
Git-ing out of  your git messes - Fluent Conf 2017Git-ing out of  your git messes - Fluent Conf 2017
Git-ing out of your git messes - Fluent Conf 2017
 
Git commands
Git commandsGit commands
Git commands
 
Git workshop
Git workshopGit workshop
Git workshop
 
GIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control SystemGIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control System
 
Git like a pro EDD18 - Full edition
Git like a pro EDD18 - Full editionGit like a pro EDD18 - Full edition
Git like a pro EDD18 - Full edition
 
Git presentation
Git presentationGit presentation
Git presentation
 
GIT Training
GIT TrainingGIT Training
GIT Training
 
Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheet
 
Gittalk
GittalkGittalk
Gittalk
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Introducción a git y GitHub
Introducción a git y GitHubIntroducción a git y GitHub
Introducción a git y GitHub
 
Git basics for beginners
Git basics for beginnersGit basics for beginners
Git basics for beginners
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Git_real_slides
Git_real_slidesGit_real_slides
Git_real_slides
 
Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changes
 

More from Avilay Parekh

Backprop
BackpropBackprop
Backprop
Avilay Parekh
 
Ai &amp; ml
Ai &amp; mlAi &amp; ml
Ai &amp; ml
Avilay Parekh
 
Pupymeetup
PupymeetupPupymeetup
Pupymeetup
Avilay Parekh
 
Day4
Day4Day4
Day3
Day3Day3
Day2
Day2Day2
Day1
Day1Day1
Git primer
Git primerGit primer
Git primer
Avilay Parekh
 
Ruby object graph
Ruby object graphRuby object graph
Ruby object graph
Avilay Parekh
 
What is cloud computing
What is cloud computingWhat is cloud computing
What is cloud computing
Avilay Parekh
 

More from Avilay Parekh (10)

Backprop
BackpropBackprop
Backprop
 
Ai &amp; ml
Ai &amp; mlAi &amp; ml
Ai &amp; ml
 
Pupymeetup
PupymeetupPupymeetup
Pupymeetup
 
Day4
Day4Day4
Day4
 
Day3
Day3Day3
Day3
 
Day2
Day2Day2
Day2
 
Day1
Day1Day1
Day1
 
Git primer
Git primerGit primer
Git primer
 
Ruby object graph
Ruby object graphRuby object graph
Ruby object graph
 
What is cloud computing
What is cloud computingWhat is cloud computing
What is cloud computing
 

Recently uploaded

Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 

Recently uploaded (20)

Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 

Git undo

  • 1. Avilay Parekh (@avilay) CTO, Co-Founder of Informion, Inc. January 2014
  • 2. Learn how to use git-checkout, git-reset, git-revert, and git-clean Walk through typical undo scenarios using these commands
  • 3. Kevin Skoglund’s excellent git tutorial on Lynda.com Pro Git Book (http://www.amazon.com/Pro-Experts-Voice-Software- Development/dp/1430218339/)
  • 4. You know the 3-tree architecture used in git. You are familiar with the terms repo, staged index, working directory, and HEAD. You are familiar with basic git commands like git add, git status, git log, git commit.
  • 5. git checkout [changeset] -- <file> git reset [option] [changeset] git revert <changeset> git clean [-n] [-f]
  • 6. git checkout [changeset] -- <file> git reset [option] [changeset] git revert <changeset> git clean [-n] [-f] Can be used in a number of different scenarios A bit difficult to understand at a conceptual level
  • 7. git checkout [changeset] -- <file> git reset [option] [changeset] git revert <changeset> git clean [-n] [-f] Does a single task really well Easy to conceptually understand what is going on
  • 8. A way to undo any uncommitted changes in the staging index or the working directory repo is left untouched
  • 9. Undo un-staged changes to a particular file in my working directory. 1 repo Staging index Working directory git checkout -- repo Staging index Working directory Initial State Final State
  • 10. Initial State The repo has 3 commits. Staging index has some uncommitted changes. hello.py in the working directory has some changes that have not been staged yet. 1 a1b2c3 fff999 5d6ef1 HEAD repo staging index working directory git checkout -- hello.py has un-added changes hello.py has some uncommitted changes
  • 11. Git Checkout -- The two dashes -- are telling git not to switch branches; something git checkout command will do otherwise. We are telling git to undo all current changes to hello.py and go back to the version in the staging index. To undo changes to all files in the working directory say – git checkout -- . 1 git checkout -- hello.py git checkout --
  • 12. Final State Staging index remains unchanged. hello.py in the working directory is overwritten by the version in the staging index. 1 a1b2c3 fff999 5d6ef1 HEAD repo staging index working directory git checkout -- hello.py is same as staging index No changes in the staging index
  • 13. With a bunch of files in staged or unstaged states, undo changes to a particular file and revert it to a version 2 commits ago. 2 repo Staging index Working directory git checkout -- repo Staging index Working directory Initial State Final State
  • 14. Initial State The repo has 3 commits. There are a bunch of staged, but uncommitted files shown in green. There are a bunch of unstaged changes to files in the working directory shown in red. 2 git checkout -- a1b2c3 fff999 5d6ef1 HEAD repo Added (but uncommitted changes) New changes not added to stage staging index working directory
  • 15. Git Checkout -- Note, the changeset fff999 is parent of HEAD. We are telling git to undo all current changes to a single file “hello.py” and go back to the version in the changeset fff999. Unlike Scenario 1, the staging index will also change 2 git checkout -- git checkout fff999 -- hello.py
  • 16. Final State First hello.py in the staging index is overwritten by the version in commit fff999. Then hello.py in the working directory is overwritten by the version in the staging index. All other staged and unstaged files are left alone. 2 git checkout -- a1b2c3 fff999 5d6ef1 HEAD repo staging index working directory hello.py is changed to the version 2 commits ago hello.py is changed to the staging version
  • 17. A way to move the HEAD pointer in the repo. Staging index and working directory can also be changed by using the right options
  • 18. Undo the last commit in the repo, but keep all the uncommitted and unstaged changes intact 3 repo Staging index Working directory git reset --soft repo Staging index Working directory Initial State Final State
  • 19. Initial State The repo has 3 commits. Staging index has some uncommitted changes. hello.py in the working directory has some unstaged changes. 3 a1b2c3 fff999 5d6ef1 HEAD repo staging index working directory git reset --soft hello.py has un-added changes hello.py has some uncommitted changes
  • 20. git reset --soft We are telling git to move the HEAD pointer to the specified commit ID which is the parent of the current HEAD The soft switch is telling git not to touch the working directory or the staging index 3 git reset --soft ff999 git reset --soft
  • 21. Final State HEAD pointer moves one commit up. Any new commits will be appended to fff999 effectively losing 5d6ef1. Staging index and working directory remain untouched. 3 a1b2c3 fff999 repo staging index working directory git reset --soft No changes to the working directory No changes in the staging index HEAD
  • 22. Undo the last commit in the repo, discard all staged changes, but keep the working directory intact 4 repo Staging index Working directory git reset --mixed repo Staging index Working directory Initial State Final State
  • 23. Initial State The repo has 3 commits. Staging index has some uncommitted changes. hello.py in the working directory has some unstaged changes. 4 a1b2c3 fff999 5d6ef1 HEAD repo staging index working directory git reset --mixed hello.py has un-added changes hello.py has some uncommitted changes
  • 24. git reset --mixed We are telling git to move the HEAD pointer to the specified commit ID which is the parent of the current HEAD The mixed switch is telling git to make the staging index look like HEAD after it has been moved Mixed is the default switch if none is provided 4 git reset --mixed ff999 git reset --mixed
  • 25. Final State HEAD pointer moves one commit up. Any new commits will be appended to fff999 effectively losing 5d6ef1. Staging index looks like fff999 Working directory is left unchanged 4 a1b2c3 fff999 repo staging index working directory git reset --mixed No changes to the working directory HEAD
  • 26. Undo the last commit in the repo, discard all staged and unstaged changes 5 repo Staging index Working directory git reset --hard repo Staging index Working directory Initial State Final State
  • 27. Initial State The repo has 3 commits. Staging index has some uncommitted changes. Working directory has some unstaged changes. 5 a1b2c3 fff999 5d6ef1 HEAD repo staging index working directory git reset --hard hello.py has un-added changes hello.py has some uncommitted changes
  • 28. git reset --hard We are telling git to move the HEAD pointer to the specified commit ID which is the parent of the current HEAD The hard switch is telling git to make the staging index look like HEAD after it has been moved, and make the working directory look like staging after it has been changed Effectively losing all work after fff999! 5 git reset --hard ff999 git reset --hard
  • 29. Final State HEAD pointer moves one commit up. Any new commits will be appended to fff999 effectively losing 5d6ef1. All changes to the staging index and the working directory after fff999 are lost. 5 a1b2c3 fff999 repo staging index working directory git reset --hard HEAD
  • 30. How can you undo all uncommitted changes (i.e., staged and unstaged changes) and go back to what was last committed?  git checkout HEAD -- .  git reset --hard HEAD
  • 31. How can you undo all uncommitted changes (i.e., staged and unstaged changes) and go back to what was last committed?  git checkout HEAD -- .  git reset --hard HEAD
  • 32. A way to discard changes made in a specific commit Always affects all 3 trees Working directory has to be clean before a revert
  • 33. Undo the last commit 6 repo Staging index Working directory git revert repo Staging index Working directory Initial State Final State
  • 34. Initial State The repo has 3 commits. Working directory is clean. 6 a1b2c3 fff999 5d6ef1 HEAD repo staging index working directory git revert
  • 35. git revert We are telling git to discard changes in the specified commit, in this case HEAD, which is the last commit 6 git revert HEAD git reset --hard
  • 36. Final State What really happens is that a new commit is made which has the inverse of all changes that were in 5d6ef1, effectively making the project look like fff999 In theory, reverting 333aaa will “redo” the previous “undo” 6 staging index working directory git reset --hard a1b2c3 fff999 5d6ef1 HEADrepo 333aaa
  • 37. The “only” way to discard untracked changes, i.e, new files that have not been added yet These files can always just be rm’ed