SlideShare une entreprise Scribd logo
1  sur  20
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

Contenu connexe

Tendances

Checkitmobile - using Git for development
Checkitmobile - using Git for developmentCheckitmobile - using Git for development
Checkitmobile - using Git for development
Gerrit Wanderer
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced git
Gerrit Wanderer
 

Tendances (18)

Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
 
Git
GitGit
Git
 
Introduction to Git (part 2)
Introduction to Git (part 2)Introduction to Git (part 2)
Introduction to Git (part 2)
 
test
testtest
test
 
Git locally git rm/revert/reset
Git locally git rm/revert/resetGit locally git rm/revert/reset
Git locally git rm/revert/reset
 
Git
GitGit
Git
 
Git locally - part 1
Git locally - part 1Git locally - part 1
Git locally - part 1
 
Git and GitHub workflows
Git and GitHub workflowsGit and GitHub workflows
Git and GitHub workflows
 
Git cheat-sheet-education
Git cheat-sheet-educationGit cheat-sheet-education
Git cheat-sheet-education
 
Git-r-Done
Git-r-DoneGit-r-Done
Git-r-Done
 
Git-Basics
Git-BasicsGit-Basics
Git-Basics
 
Checkitmobile Git Workshop
Checkitmobile Git WorkshopCheckitmobile Git Workshop
Checkitmobile Git Workshop
 
Checkitmobile - using Git for development
Checkitmobile - using Git for developmentCheckitmobile - using Git for development
Checkitmobile - using Git for development
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced git
 
Git ops: Git based application deployment patterns for Kubernetes
Git ops: Git based application deployment patterns for KubernetesGit ops: Git based application deployment patterns for Kubernetes
Git ops: Git based application deployment patterns for Kubernetes
 
Version control git day02
Version control   git day02Version control   git day02
Version control git day02
 
Git Branch
Git BranchGit Branch
Git Branch
 
Gn unify git
Gn unify gitGn unify git
Gn unify git
 

En vedette

20131011 sql2012 file-table_anney
20131011 sql2012 file-table_anney20131011 sql2012 file-table_anney
20131011 sql2012 file-table_anney
LearningTech
 

En vedette (14)

20131011 sql2012 file-table_anney
20131011 sql2012 file-table_anney20131011 sql2012 file-table_anney
20131011 sql2012 file-table_anney
 
Git rebase howto
Git rebase howtoGit rebase howto
Git rebase howto
 
git command
git commandgit command
git command
 
Learning Git with Workflows
Learning Git with WorkflowsLearning Git with Workflows
Learning Git with Workflows
 
#3 - Git - Branching e Merging
#3 - Git - Branching e Merging#3 - Git - Branching e Merging
#3 - Git - Branching e Merging
 
Build & Release Engineering
Build & Release Engineering Build & Release Engineering
Build & Release Engineering
 
vim
vimvim
vim
 
Git tutorial git branches 20131206-Bryan
Git tutorial   git branches 20131206-BryanGit tutorial   git branches 20131206-Bryan
Git tutorial git branches 20131206-Bryan
 
Git rebase explained
Git rebase explainedGit rebase explained
Git rebase explained
 
Git Branching Model
Git Branching ModelGit Branching Model
Git Branching Model
 
Git and Git Workflow Models as Catalysts of Software Development
Git and Git Workflow Models as Catalysts of Software DevelopmentGit and Git Workflow Models as Catalysts of Software Development
Git and Git Workflow Models as Catalysts of Software Development
 
Principles and Practices in Continuous Deployment at Etsy
Principles and Practices in Continuous Deployment at EtsyPrinciples and Practices in Continuous Deployment at Etsy
Principles and Practices in Continuous Deployment at Etsy
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Similaire à Git rewriting git history

Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changes
LearningTech
 
Git Developer Cheatsheet
Git Developer CheatsheetGit Developer Cheatsheet
Git Developer Cheatsheet
Abdul Basit
 

Similaire à Git rewriting git history (20)

Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
Git slides
Git slidesGit slides
Git slides
 
Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheet
 
GIT Rebasing and Merging
GIT Rebasing and MergingGIT Rebasing and Merging
GIT Rebasing and Merging
 
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 tutorial
Git tutorialGit tutorial
Git tutorial
 
Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changes
 
Git hub abduallah abu nada
Git hub   abduallah abu nadaGit hub   abduallah abu nada
Git hub abduallah abu nada
 
GITHappens, powerpoint about git and github
GITHappens, powerpoint about git and githubGITHappens, powerpoint about git and github
GITHappens, powerpoint about git and github
 
Git Developer Cheatsheet
Git Developer CheatsheetGit Developer Cheatsheet
Git Developer Cheatsheet
 
Advanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with GitAdvanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with Git
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
 
Git commands
Git commandsGit commands
Git commands
 
Git cheat sheet
Git cheat sheetGit cheat sheet
Git cheat sheet
 
Mastering GIT
Mastering GITMastering GIT
Mastering GIT
 
Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git
 
Git github
Git githubGit github
Git github
 
SVN 2 Git
SVN 2 GitSVN 2 Git
SVN 2 Git
 
Git tips
Git tipsGit tips
Git tips
 

Plus de LearningTech (20)

PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection &amp; activator
Reflection &amp; activatorReflection &amp; activator
Reflection &amp; activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
Asp.net MVC DI
Asp.net MVC DIAsp.net MVC DI
Asp.net MVC DI
 
Vic weekly learning_20151127
Vic weekly learning_20151127Vic weekly learning_20151127
Vic weekly learning_20151127
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 

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