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

PPTX
Git 101
PPTX
Git - Basic Crash Course
PPT
Git and fundamentals
PPTX
Git tutorial
PDF
Git basics
PDF
Git for beginners
PDF
Git tutorial
PPTX
Git in 10 minutes
Git 101
Git - Basic Crash Course
Git and fundamentals
Git tutorial
Git basics
Git for beginners
Git tutorial
Git in 10 minutes

What's hot (20)

PDF
A Practical Introduction to git
PDF
Git Tutorial I
KEY
Git Basics at Rails Underground
PDF
Git - The Incomplete Introduction
KEY
Introduction To Git
PDF
Introduction to Git
PDF
git and github
PPT
Git basic
PPTX
Git commands
PDF
Git introduction workshop for scientists
PPTX
Git tutorial
PPTX
Git learning
PDF
Git: basic to advanced
PDF
Introduction to Git (part 1)
PPTX
Git 101 for Beginners
PDF
Git tutorial II
PPTX
Git 101
ODP
The Fundamentals of Git
PDF
Git tutorial
PDF
GIT | Distributed Version Control System
A Practical Introduction to git
Git Tutorial I
Git Basics at Rails Underground
Git - The Incomplete Introduction
Introduction To Git
Introduction to Git
git and github
Git basic
Git commands
Git introduction workshop for scientists
Git tutorial
Git learning
Git: basic to advanced
Introduction to Git (part 1)
Git 101 for Beginners
Git tutorial II
Git 101
The Fundamentals of Git
Git tutorial
GIT | Distributed Version Control System
Ad

Similar to Gitting out of trouble (20)

PDF
Git training v10
PPTX
PPTX
Git walkthrough
PPTX
Git session Dropsolid.com
PPT
Talk to git
PDF
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git
PPTX
Git first steps
PPTX
Learning Basic GIT Cmd
PPTX
Git tips
PPTX
Git One Day Training Notes
PPTX
Source control management
PPTX
Git basic commands
PPTX
Use Git like a pro - condensed
PPTX
Git-ing out of your git messes
PDF
Advanced Git Tutorial
KEY
Git Tech Talk
PDF
Git in a nutshell
PPTX
sample.pptx
PPTX
Introduction into Git
PPT
Fundamentals and basics of Git and commands
Git training v10
Git walkthrough
Git session Dropsolid.com
Talk to git
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Git first steps
Learning Basic GIT Cmd
Git tips
Git One Day Training Notes
Source control management
Git basic commands
Use Git like a pro - condensed
Git-ing out of your git messes
Advanced Git Tutorial
Git Tech Talk
Git in a nutshell
sample.pptx
Introduction into Git
Fundamentals and basics of Git and commands
Ad

Recently uploaded (20)

PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
history of c programming in notes for students .pptx
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Nekopoi APK 2025 free lastest update
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
System and Network Administraation Chapter 3
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Design an Analysis of Algorithms II-SECS-1021-03
Which alternative to Crystal Reports is best for small or large businesses.pdf
ai tools demonstartion for schools and inter college
2025 Textile ERP Trends: SAP, Odoo & Oracle
Odoo POS Development Services by CandidRoot Solutions
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Upgrade and Innovation Strategies for SAP ERP Customers
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
history of c programming in notes for students .pptx
Understanding Forklifts - TECH EHS Solution
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Nekopoi APK 2025 free lastest update
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
How Creative Agencies Leverage Project Management Software.pdf
CHAPTER 2 - PM Management and IT Context
Operating system designcfffgfgggggggvggggggggg
System and Network Administraation Chapter 3
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Lecture 3: Operating Systems Introduction to Computer Hardware Systems

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

  • #2: Ken is here to evaluate
  • #5: XKCD image “content-addressable filesystem” – key-value data store Insert an object and it gives you back a hash to retrieve it with.
  • #6: 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.
  • #7: 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