SlideShare a Scribd company logo
Git – Rewriting Git History
Bryan Lin
20131230
Agenda
 Overview
 git commit --amend
 git rebase
 git rebase -i

 git reflog
Overview
 Git provides its history-rewriting commands under the disclaimer that using
them may result in lost content.
 Discusses some of the most common reasons for overwriting committed
snapshots and shows you how to avoid the pitfalls of doing so
git commit --amend
 The git commit --amend command is a convenient way to fix up the most
recent commit
git commit --amend
 Usage
 git commit –amend
 Combine the staged changes with the previous commit and replace the
previous commit with the resulting snapshot
git commit --amend
 Discussion
 Don’t Amend Public Commits
 Amended commits are actually entirely new commits, and the previous commit
is removed from the project history. This has the same consequences as resetting
a public snapshot.
git rebase
 Rebasing is the process of moving a branch to a new base commit. The
general process can be visualized as the following:
git rebase
 From a content perspective, rebasing really is just moving a branch from
one commit to another
 But internally, Git accomplishes this by creating new commits and applying
them to the specified base—it’s literally rewriting your project history
git rebase
 Usage
 git rebase <base>
 Rebase the current branch onto <base>, which can be any kind of commit
reference (an ID, a branch name, a tag, or a relative reference to HEAD)
git rebase
 Discussion
 The primary reason for rebasing is to maintain a linear project history
git rebase
 Discussion
 Two options for integrating your feature into the master branch:
 merging directly
 rebasing and then merging
git rebase
 Discussion
 Don’t Rebase Public History
 The rebase would replace the old commits with new ones, and it would look like
that part of your project history abruptly vanished
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
git rebase -i
 Usage
 git rebase -i <base>
 Rebase the current branch onto <base>, but use an interactive rebasing session.
 This opens an editor where you can enter commands (described below) for
each commit to be rebased.

 These commands determine how individual commits will be transferred to the
new base. You can also reorder the commit listing to change the order of the
commits themselves
git reflog
 Git keeps track of updates to the tip of branches using a mechanism called
reflog
 This allows you to go back to changesets even though they are not
referenced by any branch or tag
 After rewriting history, the reflog contains information about the old state of
branches and allows you to go back to that state if necessary
git reflog
 Usage
 git reflog
 Show the reflog for the local repository.

 git reflog --relative-date
 Show the reflog with relative date information (e.g. 2 weeks ago).
git reflog
 Discussion
 Every time the current HEAD gets updated (by switching branches, pulling in new
changes, rewriting history or simply by adding new commits) a new entry will
be added to the reflog
git reflog
 Example
 To understand git reflog, let's run through an example

 The reflog above shows a checkout from master to the 2.2 branch and back
 The latest activity is represented at the top labeled HEAD@{0}
git reflog
 Example
 If it turns out that you accidentially moved back, the reflog will contain
the commit master pointed to (0254ea7) before you accidentially dropped 2
commits.

 Using git reset it is then possible to change master back to the commit it
was before
FAQ

More Related Content

What's hot (15)

PPTX
Demystifying Git
Pablo Quiroga
 
PDF
Introduction to Git (part 2)
Salvatore Cordiano
 
PDF
test
zwned
 
PPTX
Git locally git rm/revert/reset
ahmadezzeir
 
PPTX
Git locally - part 1
ahmadezzeir
 
PDF
Git and GitHub workflows
Arthur Shvetsov
 
PDF
Git cheat-sheet-education
Avitesh Kesharwani
 
PDF
Git-r-Done
Cesar Martinez
 
PPTX
Git-Basics
Bhawna Tuteja
 
PDF
Git ops: Git based application deployment patterns for Kubernetes
Shahidh K Muhammed
 
PPTX
Version control git day02
Gourav Varma
 
PPTX
Git Branch
Wei-Tsung Su
 
PDF
Gn unify git
Priyanka Nag
 
Demystifying Git
Pablo Quiroga
 
Introduction to Git (part 2)
Salvatore Cordiano
 
test
zwned
 
Git locally git rm/revert/reset
ahmadezzeir
 
Git locally - part 1
ahmadezzeir
 
Git and GitHub workflows
Arthur Shvetsov
 
Git cheat-sheet-education
Avitesh Kesharwani
 
Git-r-Done
Cesar Martinez
 
Git-Basics
Bhawna Tuteja
 
Git ops: Git based application deployment patterns for Kubernetes
Shahidh K Muhammed
 
Version control git day02
Gourav Varma
 
Git Branch
Wei-Tsung Su
 
Gn unify git
Priyanka Nag
 

Viewers also liked (14)

PPTX
20131011 sql2012 file-table_anney
LearningTech
 
PDF
Git rebase howto
Mahesh Vaidya
 
PPTX
git command
LearningTech
 
PDF
Learning Git with Workflows
Mosky Liu
 
PDF
#3 - Git - Branching e Merging
Rodrigo Branas
 
PDF
Build & Release Engineering
Pranesh Vittal
 
PPTX
vim
LearningTech
 
PPTX
Git tutorial git branches 20131206-Bryan
LearningTech
 
PDF
Git rebase explained
Mahesh Vaidya
 
PDF
Git Branching Model
Lemi Orhan Ergin
 
PDF
Git and Git Workflow Models as Catalysts of Software Development
Lemi Orhan Ergin
 
PDF
Principles and Practices in Continuous Deployment at Etsy
Mike Brittain
 
PDF
How to Make Awesome SlideShares: Tips & Tricks
SlideShare
 
PDF
Getting Started With SlideShare
SlideShare
 
20131011 sql2012 file-table_anney
LearningTech
 
Git rebase howto
Mahesh Vaidya
 
git command
LearningTech
 
Learning Git with Workflows
Mosky Liu
 
#3 - Git - Branching e Merging
Rodrigo Branas
 
Build & Release Engineering
Pranesh Vittal
 
Git tutorial git branches 20131206-Bryan
LearningTech
 
Git rebase explained
Mahesh Vaidya
 
Git Branching Model
Lemi Orhan Ergin
 
Git and Git Workflow Models as Catalysts of Software Development
Lemi Orhan Ergin
 
Principles and Practices in Continuous Deployment at Etsy
Mike Brittain
 
How to Make Awesome SlideShares: Tips & Tricks
SlideShare
 
Getting Started With SlideShare
SlideShare
 
Ad

Similar to Git rewriting git history (20)

PPTX
Use Git like a pro - condensed
Jesús Miguel Benito Calzada
 
PDF
Advanced Git
Sergiu-Ioan Ungur
 
PPTX
Gitting out of trouble
Jon Senchyna
 
PDF
Don't fear the rebase
Giorgio Cefaro
 
PPTX
Git like a pro EDD18 - Full edition
Jesús Miguel Benito Calzada
 
DOCX
GIT Rebasing and Merging
Ashok Kumar Satuluri
 
PDF
Git Tricks — git utilities that make life git easier
Christoph Matthies
 
PDF
How to Really Get Git
Susan Tan
 
PDF
Git tutorial
mobaires
 
PDF
Advanced Git Tutorial
Sage Sharp
 
PPTX
MakingGitWorkForYou
Kwen Peterson
 
PDF
Git: Overview, Pitfalls, Best Practices
Jeremy Leisy
 
PPTX
Gitlikeapro 2019
Jesús Miguel Benito Calzada
 
PPTX
Git for beginner
Trung Huynh
 
PPTX
Git For Beginer
Trung Huynh
 
PDF
Git Tutorial EclipseCon France 2014 - Git Exercise 06 - interactive rebase
msohn
 
PDF
Git of every day
Alan Descoins
 
PDF
Advanced Git - Functionality and Features
All Things Open
 
PPTX
Git-ing out of your git messes
Katie Sylor-Miller
 
PDF
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
Use Git like a pro - condensed
Jesús Miguel Benito Calzada
 
Advanced Git
Sergiu-Ioan Ungur
 
Gitting out of trouble
Jon Senchyna
 
Don't fear the rebase
Giorgio Cefaro
 
Git like a pro EDD18 - Full edition
Jesús Miguel Benito Calzada
 
GIT Rebasing and Merging
Ashok Kumar Satuluri
 
Git Tricks — git utilities that make life git easier
Christoph Matthies
 
How to Really Get Git
Susan Tan
 
Git tutorial
mobaires
 
Advanced Git Tutorial
Sage Sharp
 
MakingGitWorkForYou
Kwen Peterson
 
Git: Overview, Pitfalls, Best Practices
Jeremy Leisy
 
Git for beginner
Trung Huynh
 
Git For Beginer
Trung Huynh
 
Git Tutorial EclipseCon France 2014 - Git Exercise 06 - interactive rebase
msohn
 
Git of every day
Alan Descoins
 
Advanced Git - Functionality and Features
All Things Open
 
Git-ing out of your git messes
Katie Sylor-Miller
 
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
Ad

More from LearningTech (20)

PPTX
PostCss
LearningTech
 
PPTX
ReactJs
LearningTech
 
PPTX
Docker
LearningTech
 
PPTX
Semantic ui
LearningTech
 
PPTX
node.js errors
LearningTech
 
PPTX
Process control nodejs
LearningTech
 
PPTX
Expression tree
LearningTech
 
PPTX
SQL 效能調校
LearningTech
 
PPTX
flexbox report
LearningTech
 
PPTX
Vic weekly learning_20160504
LearningTech
 
PPTX
Reflection &amp; activator
LearningTech
 
PPTX
Peggy markdown
LearningTech
 
PPTX
Node child process
LearningTech
 
PPTX
20160415ken.lee
LearningTech
 
PPTX
Peggy elasticsearch應用
LearningTech
 
PPTX
Expression tree
LearningTech
 
PPTX
Vic weekly learning_20160325
LearningTech
 
PPTX
D3js learning tips
LearningTech
 
PDF
Asp.net MVC DI
LearningTech
 
PPTX
Vic weekly learning_20151127
LearningTech
 
PostCss
LearningTech
 
ReactJs
LearningTech
 
Docker
LearningTech
 
Semantic ui
LearningTech
 
node.js errors
LearningTech
 
Process control nodejs
LearningTech
 
Expression tree
LearningTech
 
SQL 效能調校
LearningTech
 
flexbox report
LearningTech
 
Vic weekly learning_20160504
LearningTech
 
Reflection &amp; activator
LearningTech
 
Peggy markdown
LearningTech
 
Node child process
LearningTech
 
20160415ken.lee
LearningTech
 
Peggy elasticsearch應用
LearningTech
 
Expression tree
LearningTech
 
Vic weekly learning_20160325
LearningTech
 
D3js learning tips
LearningTech
 
Asp.net MVC DI
LearningTech
 
Vic weekly learning_20151127
LearningTech
 

Recently uploaded (20)

PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 

Git rewriting git history

  • 1. Git – Rewriting Git History Bryan Lin 20131230
  • 2. Agenda  Overview  git commit --amend  git rebase  git rebase -i  git reflog
  • 3. Overview  Git provides its history-rewriting commands under the disclaimer that using them may result in lost content.  Discusses some of the most common reasons for overwriting committed snapshots and shows you how to avoid the pitfalls of doing so
  • 4. git commit --amend  The git commit --amend command is a convenient way to fix up the most recent commit
  • 5. git commit --amend  Usage  git commit –amend  Combine the staged changes with the previous commit and replace the previous commit with the resulting snapshot
  • 6. git commit --amend  Discussion  Don’t Amend Public Commits  Amended commits are actually entirely new commits, and the previous commit is removed from the project history. This has the same consequences as resetting a public snapshot.
  • 7. git rebase  Rebasing is the process of moving a branch to a new base commit. The general process can be visualized as the following:
  • 8. git rebase  From a content perspective, rebasing really is just moving a branch from one commit to another  But internally, Git accomplishes this by creating new commits and applying them to the specified base—it’s literally rewriting your project history
  • 9. git rebase  Usage  git rebase <base>  Rebase the current branch onto <base>, which can be any kind of commit reference (an ID, a branch name, a tag, or a relative reference to HEAD)
  • 10. git rebase  Discussion  The primary reason for rebasing is to maintain a linear project history
  • 11. git rebase  Discussion  Two options for integrating your feature into the master branch:  merging directly  rebasing and then merging
  • 12. git rebase  Discussion  Don’t Rebase Public History  The rebase would replace the old commits with new ones, and it would look like that part of your project history abruptly vanished
  • 13. 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
  • 14. git rebase -i  Usage  git rebase -i <base>  Rebase the current branch onto <base>, but use an interactive rebasing session.  This opens an editor where you can enter commands (described below) for each commit to be rebased.  These commands determine how individual commits will be transferred to the new base. You can also reorder the commit listing to change the order of the commits themselves
  • 15. git reflog  Git keeps track of updates to the tip of branches using a mechanism called reflog  This allows you to go back to changesets even though they are not referenced by any branch or tag  After rewriting history, the reflog contains information about the old state of branches and allows you to go back to that state if necessary
  • 16. git reflog  Usage  git reflog  Show the reflog for the local repository.  git reflog --relative-date  Show the reflog with relative date information (e.g. 2 weeks ago).
  • 17. git reflog  Discussion  Every time the current HEAD gets updated (by switching branches, pulling in new changes, rewriting history or simply by adding new commits) a new entry will be added to the reflog
  • 18. git reflog  Example  To understand git reflog, let's run through an example  The reflog above shows a checkout from master to the 2.2 branch and back  The latest activity is represented at the top labeled HEAD@{0}
  • 19. git reflog  Example  If it turns out that you accidentially moved back, the reflog will contain the commit master pointed to (0254ea7) before you accidentially dropped 2 commits.  Using git reset it is then possible to change master back to the commit it was before
  • 20. FAQ