SlideShare a Scribd company logo
“GIT-ING”
OUT OF
TROUBLE
H O W TO G O B A C K I N T I M E W I T H O U T E R A S I N G
Y O U R S E L F F R O M T H E F U T U R E
OUTLINE
• Basic Foundations of Git
• Fixes for Common Issues
• Other Useful Commands
• Recovering from
Catastrophic Failures
BASIC GIT
FOUNDATIONS
D O E S A N Y O N E R E A L LY G I T G E T ?
WHAT IS GIT ANYWAY?
Key-value data store
• Value: object being stored
• Key: SHA-1 hash of object
COMMIT
5 basic pieces of data
• Reference to top-level tree (folder) of snapshot
– Files/folders at the time of the commit
• Reference to parent commit
• Author with timestamp
• Committer with timestamp
• Commit message
FILE LOCATIONS IN GIT
• Working Directory
• Index (Staging Area)
• Repository
Working
Directory
Index
Repository
git add
git commit
FIXES FOR
COMMON
ISSUES
FIXING TYPOS/SMALL MISTAKES
• Typo in branch name
– git branch –m [new_name]
• Typo in your commit message
• Forgot to include a file
• Found a small bug after committing
– git commit --amend (--no-edit)
• Accidentally included changes
– git reset HEAD~1 (--soft)
ADDED TO WRONG BRANCH
• Need change from another branch
– git checkout [branch_to_add_to]
– git cherry-pick [commit_hash]
• Accidentally committed to `develop`
– git branch [new_name]
– git reset origin –hard
– git checkout [new_name]
CLEANING UP HISTORY BEFORE
PUSHING
CLEANING UP HISTORY BEFORE
PUSHING
• Use cases:
– Condense history
– Split commit
– Pretend things never happened
• Commands:
– git rebase –i origin
GOLDEN RULE OF REBASING
“Never rebase a shared branch.”
• Practical Golden Rule:
1. Determine the base commit
2. Do not rebase if anything past base commit is shared
B
A
D
C Pushed to
Origin
INTERACTIVE REBASE
Basic Syntax:
git rebase –i [<commit>]
Shows each commit ahead of the root commit and lets you decide what to do with them.
• Reorder commits
• Execute command against commit.
– pick: keep commit as-is
– drop: remove commit from history
– reword: keep contents of commit, but change message
– squash/fixup: amend previous commit with this one
– edit: pause rebase after commit to allow for amending
• git rebase –continue
– …
RECOVERING
FROM
CATASTROPHIC
FAILURE
Remember the Git
fundamentals
• When in doubt, just delete
everything and re-clone
• Noone can see your mistakes
if they no longer exist…
SO SOMETHING WENT
WRONG…
Remember the Git
fundamentals
• When in doubt, just delete
everything and re-clone
• Noone can see your mistakes
if they no longer exist…
SO SOMETHING WENT
WRONG…
Remember the Git
fundamentals
• Every commit is just an
object in the repository with
a hash
• Commits are read-only. You
cannot change a commit, you
can only create new ones.
SO SOMETHING WENT
WRONG…
GIT REFLOG
Basic Syntax:
git reflog [-n <number>]
• See entries in the “Reference Log”, along with their hashes
• You can reset a branch back to a “pre-catastrophic-
failure” hash
SUMMARY
H O W D O I R E M E M B E R A L L T H A T ?
CHEAT SHEET (FIXING COMMITS)
• Rename Branch
– git branch –m [new_name]
• Adjust previous commit
– git commit --amend --no-edit
• Copy commit from another branch
– git cherry-pick [commit]
• Accidental commits on `develop`
– git branch [new_branch]
– git reset origin --hard
– git checkout [new_branch]
• Clean up history
– git rebase –i origin
– move, fixup, squash, drop
• Split commit
– git rebase –I origin
– “edit”
– git reset HEAD~1
– Make new commits
– git rebase --continue
• Catastrophic failure
– git reflog
– get reset [some_commit_in_past]
CHEAT SHEET (USEFUL COMMANDS)
• Create new local branch
– git checkout –b [new_branch]
• Push locally created branch to BitBucket
– git push –u origin HEAD
• Update with latest from develop (add to end)
– git pull origin develop
• Update with latest from develop (add to beginning)
– git pull origin develop --rebase

More Related Content

What's hot

A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to git
Emanuele Olivetti
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
Jim Yeh
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails Underground
Ariejan de Vroom
 
Git - The Incomplete Introduction
Git - The Incomplete IntroductionGit - The Incomplete Introduction
Git - The Incomplete Introduction
rschwietzke
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
Arnaud Seilles
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
Colin Su
 
git and github
git and githubgit and github
git and github
Darren Oakley
 
Git basic
Git basicGit basic
Git basic
Emran Ul Hadi
 
Git commands
Git commandsGit commands
Git commands
Viyaan Jhiingade
 
Git introduction workshop for scientists
Git introduction workshop for scientists Git introduction workshop for scientists
Git introduction workshop for scientists
Steven Hamblin
 
Git tutorial
Git tutorial Git tutorial
Git tutorial
TingYen Lee
 
Git learning
Git learningGit learning
Git learning
Amit Gupta
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advanced
Yodalee
 
Introduction to Git (part 1)
Introduction to Git (part 1)Introduction to Git (part 1)
Introduction to Git (part 1)
Salvatore Cordiano
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
Anurag Upadhaya
 
Git tutorial II
Git tutorial IIGit tutorial II
Git tutorial II
Jim Yeh
 
Git 101
Git 101Git 101
Git 101
jayrparro
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
DivineOmega
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
mobaires
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
Mohammad Imam Hossain
 

What's hot (20)

A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to git
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails Underground
 
Git - The Incomplete Introduction
Git - The Incomplete IntroductionGit - The Incomplete Introduction
Git - The Incomplete Introduction
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
git and github
git and githubgit and github
git and github
 
Git basic
Git basicGit basic
Git basic
 
Git commands
Git commandsGit commands
Git commands
 
Git introduction workshop for scientists
Git introduction workshop for scientists Git introduction workshop for scientists
Git introduction workshop for scientists
 
Git tutorial
Git tutorial Git tutorial
Git tutorial
 
Git learning
Git learningGit learning
Git learning
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advanced
 
Introduction to Git (part 1)
Introduction to Git (part 1)Introduction to Git (part 1)
Introduction to Git (part 1)
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
Git tutorial II
Git tutorial IIGit tutorial II
Git tutorial II
 
Git 101
Git 101Git 101
Git 101
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
 

Similar to Gitting out of trouble

Git training v10
Git training v10Git training v10
Git training v10
Skander Hamza
 
Gitlikeapro 2019
Gitlikeapro 2019Gitlikeapro 2019
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
Bimal Jain
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
dropsolid
 
Talk to git
Talk to gitTalk to git
Talk to git
YenTing Chen
 
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Git Is A State Of Mind - The path to becoming a Master of the mystic art of GitGit Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Nicola Costantino
 
Git first steps
Git first stepsGit first steps
Git first steps
IgorSteinmacher
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
srinathcox
 
Git tips
Git tipsGit tips
Git tips
Arthur Shvetsov
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
glen_a_smith
 
Source control management
Source control managementSource control management
Source control management
Owen Winkler
 
Git basic commands
Git basic commandsGit basic commands
Git basic commands
Adarsh Konchady
 
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
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
Katie Sylor-Miller
 
Git
Git Git
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
Sage Sharp
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
Chris Johnson
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
Pranesh Vittal
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
UshaSuray
 
Introduction into Git
Introduction into GitIntroduction into Git
Introduction into Git
Serhii Kartashov
 

Similar to Gitting out of trouble (20)

Git training v10
Git training v10Git training v10
Git training v10
 
Gitlikeapro 2019
Gitlikeapro 2019Gitlikeapro 2019
Gitlikeapro 2019
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
 
Talk to git
Talk to gitTalk to git
Talk to git
 
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Git Is A State Of Mind - The path to becoming a Master of the mystic art of GitGit Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git
 
Git first steps
Git first stepsGit first steps
Git first steps
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 
Git tips
Git tipsGit tips
Git tips
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Source control management
Source control managementSource control management
Source control management
 
Git basic commands
Git basic commandsGit basic commands
Git basic commands
 
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
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
Git
Git Git
Git
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
Introduction into Git
Introduction into GitIntroduction into Git
Introduction into Git
 

Recently uploaded

Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 

Recently uploaded (20)

Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 

Gitting out of trouble

  • 1. “GIT-ING” OUT OF TROUBLE H O W TO G O B A C K I N T I M E W I T H O U T E R A S I N G Y O U R S E L F F R O M T H E F U T U R E
  • 2. OUTLINE • Basic Foundations of Git • Fixes for Common Issues • Other Useful Commands • Recovering from Catastrophic Failures
  • 3. BASIC GIT FOUNDATIONS D O E S A N Y O N E R E A L LY G I T G E T ?
  • 4. WHAT IS GIT ANYWAY? Key-value data store • Value: object being stored • Key: SHA-1 hash of object
  • 5. COMMIT 5 basic pieces of data • Reference to top-level tree (folder) of snapshot – Files/folders at the time of the commit • Reference to parent commit • Author with timestamp • Committer with timestamp • Commit message
  • 6. FILE LOCATIONS IN GIT • Working Directory • Index (Staging Area) • Repository Working Directory Index Repository git add git commit
  • 8. FIXING TYPOS/SMALL MISTAKES • Typo in branch name – git branch –m [new_name] • Typo in your commit message • Forgot to include a file • Found a small bug after committing – git commit --amend (--no-edit) • Accidentally included changes – git reset HEAD~1 (--soft)
  • 9. ADDED TO WRONG BRANCH • Need change from another branch – git checkout [branch_to_add_to] – git cherry-pick [commit_hash] • Accidentally committed to `develop` – git branch [new_name] – git reset origin –hard – git checkout [new_name]
  • 10. CLEANING UP HISTORY BEFORE PUSHING
  • 11. CLEANING UP HISTORY BEFORE PUSHING • Use cases: – Condense history – Split commit – Pretend things never happened • Commands: – git rebase –i origin
  • 12. GOLDEN RULE OF REBASING “Never rebase a shared branch.” • Practical Golden Rule: 1. Determine the base commit 2. Do not rebase if anything past base commit is shared B A D C Pushed to Origin
  • 13. INTERACTIVE REBASE Basic Syntax: git rebase –i [<commit>] Shows each commit ahead of the root commit and lets you decide what to do with them. • Reorder commits • Execute command against commit. – pick: keep commit as-is – drop: remove commit from history – reword: keep contents of commit, but change message – squash/fixup: amend previous commit with this one – edit: pause rebase after commit to allow for amending • git rebase –continue – …
  • 15. Remember the Git fundamentals • When in doubt, just delete everything and re-clone • Noone can see your mistakes if they no longer exist… SO SOMETHING WENT WRONG…
  • 16. Remember the Git fundamentals • When in doubt, just delete everything and re-clone • Noone can see your mistakes if they no longer exist… SO SOMETHING WENT WRONG…
  • 17. Remember the Git fundamentals • Every commit is just an object in the repository with a hash • Commits are read-only. You cannot change a commit, you can only create new ones. SO SOMETHING WENT WRONG…
  • 18. GIT REFLOG Basic Syntax: git reflog [-n <number>] • See entries in the “Reference Log”, along with their hashes • You can reset a branch back to a “pre-catastrophic- failure” hash
  • 19. SUMMARY H O W D O I R E M E M B E R A L L T H A T ?
  • 20. CHEAT SHEET (FIXING COMMITS) • Rename Branch – git branch –m [new_name] • Adjust previous commit – git commit --amend --no-edit • Copy commit from another branch – git cherry-pick [commit] • Accidental commits on `develop` – git branch [new_branch] – git reset origin --hard – git checkout [new_branch] • Clean up history – git rebase –i origin – move, fixup, squash, drop • Split commit – git rebase –I origin – “edit” – git reset HEAD~1 – Make new commits – git rebase --continue • Catastrophic failure – git reflog – get reset [some_commit_in_past]
  • 21. CHEAT SHEET (USEFUL COMMANDS) • Create new local branch – git checkout –b [new_branch] • Push locally created branch to BitBucket – git push –u origin HEAD • Update with latest from develop (add to end) – git pull origin develop • Update with latest from develop (add to beginning) – git pull origin develop --rebase

Editor's Notes

  1. Ken is here to evaluate
  2. XKCD image “content-addressable filesystem” – key-value data store Insert an object and it gives you back a hash to retrieve it with.
  3. Author is the one who originally wrote the commit Committer is the one who most recently applied it (e.g. rewriting others’ history) Note: hash is based on all of these – if a commit has the same values, it has the same hash. If any value is different, it is a different commit.
  4. Working Directory – Files currently on your local FS Git shows differences between WD and Index Index – build a set of changes you want to commit Git shows differences between Index and Repsotory You can add “hunks” (partial changes to a file) to the index Repository – where all of your history is tracked