SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
New Views on your History
with git replace
Christian Couder, Murex
chriscool@tuxfamily.org
OSDC.fr 2013
October 5, 2013
About Git
A Distributed Version Control System
(DVCS):
● created by Linus Torvalds
● maintained by Junio Hamano
● since 2005
● prefered VCS among open source
developers
Git Design
Git is made of these things:
● “Objects”
● “Refs”
● config, indexes, logs, hooks,
grafts, packs, ...
Only “Objects” and “Refs” are
transferred from one repository to
another.
Git Objects

● Blob: content of a file
● Tree: content of a directory
● Commit: state of the whole source code
● Tag: stamp on an object
Git Objects Storage

● Git Objects are stored in a
content addressable database.
● The key to retrieve each Object is the
SHA-1 of the Object’s content.
● A SHA-1 is a 160-bit / 40-hex / 20-byte
hash value which is considered
unique.
Blob
SHA1: e8455...

blob = content of a file
blob

size

/* content of this blob, it can be
anything like an image, a video,
... but most of the time it is
source code like:*/
#include <stdio.h>
int main(void)
{
printf("Hello world!n");
return 0;
}
Example of storing and
retrieving a blob
# echo “Whatever…” | git hash-object -w --stdin
aa02989467eea6d8e0bc68f3663de51767a9f5b1
# git cat-file -p aa02989467
Whatever...
Tree
SHA1: 0de24...
size

tree
blob
tree

hello.c
lib

tree = content of a
directory

e8455...
10af9...

It can point to blobs and
other trees.
Example of storing and
retrieving a tree
# BLOB=aa02989467eea6d8e0bc68f3663de51767a9f5b1
# (printf "100644 whatever.txt0"; echo $BLOB | xxd -r -p)
| git hash-object -t tree -w --stdin
0625da548ef0a7038c44b480f10d5550b2f2f962
# git cat-file -p 0625da548e
100644 blob aa02989467... whatever.txt
Commit
SHA1: 98ca9...
size

commit
tree

0de24...

parents

commit = information
about some changes

()

author

Christian <timestamp>

committer

Christian <timestamp>

My commit message

It points to one tree and 0
or more parents.
Example of storing and
retrieving a commit (1)
# TREE=0625da548ef0a7038c44b480f10d5550b2f2f962
# ME=”Christian Couder <chriscool@tuxfamily.org>”
# DATE=$(date "+%s %z")
# (echo -e "tree $TREEnauthor $ME $DATE";
echo -e "committer $ME $DATEnnfirst commit")
| git hash-object -t commit -w --stdin
37449e955443883a0a888ee100cfd0a7ba7927b3
Example of storing and
retrieving a commit (2)
# git cat-file -p 37449e9554
tree 0625da548ef0a7038c44b480f10d5550b2f2f962
author Christian Couder <chriscool@tuxfamily.org> 1380447450 +0200
committer Christian Couder <chriscool@tuxfamily.org> 1380447450 +0200
first commit
Git Objects Relations
SHA1: e84c7...
Commit

SHA1: 0de24...

size

tree

29c43...

parents

()

author

Christian

committer

Christian

Blob

size

SHA1: 29c43...
int main() { ... }
Tree

Initial commit

blob
tree

size
hello.c 0de24...
doc

98ca9...

SHA1: 98ca9...
Tree

size

blob readme 677f4...
blob

SHA1: 98ca9...
Commit
tree

install

23ae9...

size
5c11f...

parents

(e84c7...)

author

Arnaud

committer

Arnaud

Change hello.c

SHA1: 5c11f...
SHA1: bc789...
Tree
blob
tree

size
hello.c bc789...
doc

98ca9...

Blob

size

int main(void) { ... }
Git Refs
● Head: branch,
.git/refs/heads/
● Tag: lightweight tag,
.git/refs/tags/
● Remote: distant repository,
.git/refs/remotes/
● Note: note attached to an object,
.git/refs/notes/
● Replace: replacement of an object,
.git/refs/replace/
Example of storing and
retrieving a branch
# git update-ref refs/heads/master 37449e9554
# git rev-parse master
37449e955443883a0a888ee100cfd0a7ba7927b3
# git reset --hard master
HEAD is now at 37449e9 first commit
# cat whatever.txt
Whatever...
Result from previous examples
master

commit 37449e9554

tree 0625da548e

blob aa02989467
Commits in Git form a DAG
(Directed Acyclic Graph)

● history direction is from left to right
● new commits point to their parents
git bisect

B

● B introduces a bad behavior called "bug" or
"regression"
● red commits are called "bad"
● blue commits are called "good"
Problem when bisecting
Sometimes the commit that introduced a bug
will be in an untestable area of the graph.
For example:
W

X

X1

X2

X3

Y

Z

Commit X introduced a breakage, later fixed
by commit Y.
Possible solutions
Possible solutions to bisect anyway:
● apply a patch before testing and remove it
afterwards (can be done using "git cherrypick"), or
● create a fixed up branch (can be done with
"git rebase -i"), for example:
X+Y

W

X

X1'

X1

X2'

X2

X3'

X3

Z'

Y

Z

Z1
A good solution
The idea is that we will replace Z with Z' so that
we bisect from the beginning using the fixed up
branch.
X+Y

W

X

X1'

X1

$ git replace Z Z'

X2'

X2

X3'

X3

Z'

Y

Z1

Z
Grafts
Created mostly for projects like linux
kernel with old repositories.
● “.git/info/grafts” file
● each line describe parents of a
commit
● <commit> <parent> [<parent>]*
● this overrides the content in the
commit
Problem with Grafts

They are neither objects nor refs, so
they cannot be easily transferred.
We need something that is either:
● an object, or
● a ref
Solution, part 1: replace ref

● It is a ref in .git/refs/replace/
● Its name is the SHA-1 of the
object that should be replaced.
● It contains, so it points to, the
SHA-1 of the replacement object.
Solution, part 2: git replace

● git replace [ -f ] <object> <replacement>:
to create a replace ref
● git replace -d <object>:
to delete a replace ref
● git replace [ -l [ pattern ] ]:
to list some replace refs
Replace ref transfer
● as with heads, tags, notes, remotes
● except that there are no shortcuts and
you must be explicit
● refspec: refs/replace/*:refs/replace/*
● refspec can be configured (in .git/config),
or used on the command line (after git
push/fetch <remote>)
Creating replacement objects
When it is needed the following commands
can help:
● git rebase [ -i ]
● git cherry-pick
● git hash-object
● git filter-branch
What can it be used for?
Create new views of your history.
Right now only 2 views are possible:
● the view with all the replace refs enabled
● the view with all the replace refs disabled,
using --no-replace-objects or the
GIT_NO_REPLACE_OBJECTS
environment variable
Why new views?
● split old and new history or merge them
● fix bugs to bisect on a clean history
● fix mistakes in author, committer,
timestamps
● remove big files to have something lighter
to use, when you don’t need them
● prepare a repo cleanup
● mask/unmask some steps
● ...
Limitations
● everything is still in the repo
● so the repo is still big
● there are probably bugs
● confusing?
● ...
Current and future work
● a script to replace grafts
● fix bugs
● allow subdirectories in .git/refs/replace/
● maybe allow “views” as set of active
subdirectories
● ...
Considerations
● best of both world: immutability and
configurability of history
● no true view
● history is important for freedom
Many thanks to:
● Junio Hamano (comments, help, discussions,
reviews, improvements),
● Ingo Molnar,
● Linus Torvalds,
● many other great people in the Git and Linux
communities, especially: Andreas Ericsson,
Johannes Schindelin, H. Peter Anvin, Daniel
Barkalow, Bill Lear, John Hawley, ...
● OSDC/OWF organizers and attendants,
● Murex the company I am working for.
Questions ?

Weitere ähnliche Inhalte

Was ist angesagt?

Essential Git and Github commands
Essential Git and Github commandsEssential Git and Github commands
Essential Git and Github commandsIsham Rashik
 
Workshop on Source control, git merge walkthroughs
Workshop on Source control, git merge walkthroughsWorkshop on Source control, git merge walkthroughs
Workshop on Source control, git merge walkthroughsDavid Lawrence
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitColin Su
 
Contributing to open source using Git
Contributing to open source using GitContributing to open source using Git
Contributing to open source using GitYan Vugenfirer
 
SouthEast LinuxFest 2015 - intro to git
SouthEast LinuxFest 2015 -  intro to gitSouthEast LinuxFest 2015 -  intro to git
SouthEast LinuxFest 2015 - intro to gitedgester
 
Git Introduction
Git IntroductionGit Introduction
Git IntroductionGareth Hall
 
Git tech talk
Git tech talkGit tech talk
Git tech talkrazasayed
 
Git push to build, test and scan your containers
Git push to build, test and scan your containersGit push to build, test and scan your containers
Git push to build, test and scan your containersDharmit Shah
 

Was ist angesagt? (20)

Essential Git and Github commands
Essential Git and Github commandsEssential Git and Github commands
Essential Git and Github commands
 
Workshop on Source control, git merge walkthroughs
Workshop on Source control, git merge walkthroughsWorkshop on Source control, git merge walkthroughs
Workshop on Source control, git merge walkthroughs
 
Git advanced
Git advancedGit advanced
Git advanced
 
Git
GitGit
Git
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Contributing to open source using Git
Contributing to open source using GitContributing to open source using Git
Contributing to open source using Git
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Presentacion git
Presentacion gitPresentacion git
Presentacion git
 
SouthEast LinuxFest 2015 - intro to git
SouthEast LinuxFest 2015 -  intro to gitSouthEast LinuxFest 2015 -  intro to git
SouthEast LinuxFest 2015 - intro to git
 
Git Introduction
Git IntroductionGit Introduction
Git Introduction
 
Git tech talk
Git tech talkGit tech talk
Git tech talk
 
Git Basics
Git BasicsGit Basics
Git Basics
 
Git 101
Git 101Git 101
Git 101
 
Intro to Git
Intro to GitIntro to Git
Intro to Git
 
SCM Boot Camp
SCM Boot CampSCM Boot Camp
SCM Boot Camp
 
Formation git
Formation gitFormation git
Formation git
 
Git push to build, test and scan your containers
Git push to build, test and scan your containersGit push to build, test and scan your containers
Git push to build, test and scan your containers
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Git training with Devaamo
Git training with DevaamoGit training with Devaamo
Git training with Devaamo
 
Git in Eclipse
Git in EclipseGit in Eclipse
Git in Eclipse
 

Ähnlich wie New Views on your History with git replace

Introduction of Git
Introduction of GitIntroduction of Git
Introduction of GitWayne Chen
 
Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Advanced Git Techniques: Subtrees, Grafting, and Other Fun StuffAdvanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Advanced Git Techniques: Subtrees, Grafting, and Other Fun StuffAtlassian
 
Learning git
Learning gitLearning git
Learning gitSid Anand
 
Git, Fast and Distributed Source Code Management
Git, Fast and Distributed Source Code ManagementGit, Fast and Distributed Source Code Management
Git, Fast and Distributed Source Code ManagementSalimane Adjao Moustapha
 
Six3 Getting Git
Six3 Getting GitSix3 Getting Git
Six3 Getting GitDaniel Cox
 
Introduction to Git for developers
Introduction to Git for developersIntroduction to Git for developers
Introduction to Git for developersDmitry Guyvoronsky
 
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)Ahmed El-Arabawy
 
Git: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commandsGit: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commandsth507
 
Practical git for developers
Practical git for developersPractical git for developers
Practical git for developersWim Godden
 
Git in the European Parliament
Git in the European ParliamentGit in the European Parliament
Git in the European ParliamentJean-Pol Landrain
 
Understanding GIT
Understanding GITUnderstanding GIT
Understanding GIThybr1s
 

Ähnlich wie New Views on your History with git replace (20)

Git in action
Git in actionGit in action
Git in action
 
How git works
How git works  How git works
How git works
 
Introduction of Git
Introduction of GitIntroduction of Git
Introduction of Git
 
Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Advanced Git Techniques: Subtrees, Grafting, and Other Fun StuffAdvanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
 
Introduction to Git (Greg Lonnon)
Introduction to Git (Greg Lonnon)Introduction to Git (Greg Lonnon)
Introduction to Git (Greg Lonnon)
 
Learning git
Learning gitLearning git
Learning git
 
Git, Fast and Distributed Source Code Management
Git, Fast and Distributed Source Code ManagementGit, Fast and Distributed Source Code Management
Git, Fast and Distributed Source Code Management
 
Six3 Getting Git
Six3 Getting GitSix3 Getting Git
Six3 Getting Git
 
Command line git
Command line gitCommand line git
Command line git
 
Introduction to Git for developers
Introduction to Git for developersIntroduction to Git for developers
Introduction to Git for developers
 
Git training
Git trainingGit training
Git training
 
Mini git tutorial
Mini git tutorialMini git tutorial
Mini git tutorial
 
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
 
Git: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commandsGit: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commands
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
Practical git for developers
Practical git for developersPractical git for developers
Practical git for developers
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 
Git in the European Parliament
Git in the European ParliamentGit in the European Parliament
Git in the European Parliament
 
Understanding GIT
Understanding GITUnderstanding GIT
Understanding GIT
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 

Kürzlich hochgeladen

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
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 FMESafe Software
 
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, Adobeapidays
 
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 DiscoveryTrustArc
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
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.pdfOrbitshub
 
"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 ...Zilliz
 

Kürzlich hochgeladen (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 
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
 
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
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
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
 
+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...
 
"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 ...
 

New Views on your History with git replace

  • 1. New Views on your History with git replace Christian Couder, Murex chriscool@tuxfamily.org OSDC.fr 2013 October 5, 2013
  • 2. About Git A Distributed Version Control System (DVCS): ● created by Linus Torvalds ● maintained by Junio Hamano ● since 2005 ● prefered VCS among open source developers
  • 3. Git Design Git is made of these things: ● “Objects” ● “Refs” ● config, indexes, logs, hooks, grafts, packs, ... Only “Objects” and “Refs” are transferred from one repository to another.
  • 4. Git Objects ● Blob: content of a file ● Tree: content of a directory ● Commit: state of the whole source code ● Tag: stamp on an object
  • 5. Git Objects Storage ● Git Objects are stored in a content addressable database. ● The key to retrieve each Object is the SHA-1 of the Object’s content. ● A SHA-1 is a 160-bit / 40-hex / 20-byte hash value which is considered unique.
  • 6. Blob SHA1: e8455... blob = content of a file blob size /* content of this blob, it can be anything like an image, a video, ... but most of the time it is source code like:*/ #include <stdio.h> int main(void) { printf("Hello world!n"); return 0; }
  • 7. Example of storing and retrieving a blob # echo “Whatever…” | git hash-object -w --stdin aa02989467eea6d8e0bc68f3663de51767a9f5b1 # git cat-file -p aa02989467 Whatever...
  • 8. Tree SHA1: 0de24... size tree blob tree hello.c lib tree = content of a directory e8455... 10af9... It can point to blobs and other trees.
  • 9. Example of storing and retrieving a tree # BLOB=aa02989467eea6d8e0bc68f3663de51767a9f5b1 # (printf "100644 whatever.txt0"; echo $BLOB | xxd -r -p) | git hash-object -t tree -w --stdin 0625da548ef0a7038c44b480f10d5550b2f2f962 # git cat-file -p 0625da548e 100644 blob aa02989467... whatever.txt
  • 10. Commit SHA1: 98ca9... size commit tree 0de24... parents commit = information about some changes () author Christian <timestamp> committer Christian <timestamp> My commit message It points to one tree and 0 or more parents.
  • 11. Example of storing and retrieving a commit (1) # TREE=0625da548ef0a7038c44b480f10d5550b2f2f962 # ME=”Christian Couder <chriscool@tuxfamily.org>” # DATE=$(date "+%s %z") # (echo -e "tree $TREEnauthor $ME $DATE"; echo -e "committer $ME $DATEnnfirst commit") | git hash-object -t commit -w --stdin 37449e955443883a0a888ee100cfd0a7ba7927b3
  • 12. Example of storing and retrieving a commit (2) # git cat-file -p 37449e9554 tree 0625da548ef0a7038c44b480f10d5550b2f2f962 author Christian Couder <chriscool@tuxfamily.org> 1380447450 +0200 committer Christian Couder <chriscool@tuxfamily.org> 1380447450 +0200 first commit
  • 13. Git Objects Relations SHA1: e84c7... Commit SHA1: 0de24... size tree 29c43... parents () author Christian committer Christian Blob size SHA1: 29c43... int main() { ... } Tree Initial commit blob tree size hello.c 0de24... doc 98ca9... SHA1: 98ca9... Tree size blob readme 677f4... blob SHA1: 98ca9... Commit tree install 23ae9... size 5c11f... parents (e84c7...) author Arnaud committer Arnaud Change hello.c SHA1: 5c11f... SHA1: bc789... Tree blob tree size hello.c bc789... doc 98ca9... Blob size int main(void) { ... }
  • 14. Git Refs ● Head: branch, .git/refs/heads/ ● Tag: lightweight tag, .git/refs/tags/ ● Remote: distant repository, .git/refs/remotes/ ● Note: note attached to an object, .git/refs/notes/ ● Replace: replacement of an object, .git/refs/replace/
  • 15. Example of storing and retrieving a branch # git update-ref refs/heads/master 37449e9554 # git rev-parse master 37449e955443883a0a888ee100cfd0a7ba7927b3 # git reset --hard master HEAD is now at 37449e9 first commit # cat whatever.txt Whatever...
  • 16. Result from previous examples master commit 37449e9554 tree 0625da548e blob aa02989467
  • 17. Commits in Git form a DAG (Directed Acyclic Graph) ● history direction is from left to right ● new commits point to their parents
  • 18. git bisect B ● B introduces a bad behavior called "bug" or "regression" ● red commits are called "bad" ● blue commits are called "good"
  • 19. Problem when bisecting Sometimes the commit that introduced a bug will be in an untestable area of the graph. For example: W X X1 X2 X3 Y Z Commit X introduced a breakage, later fixed by commit Y.
  • 20. Possible solutions Possible solutions to bisect anyway: ● apply a patch before testing and remove it afterwards (can be done using "git cherrypick"), or ● create a fixed up branch (can be done with "git rebase -i"), for example: X+Y W X X1' X1 X2' X2 X3' X3 Z' Y Z Z1
  • 21. A good solution The idea is that we will replace Z with Z' so that we bisect from the beginning using the fixed up branch. X+Y W X X1' X1 $ git replace Z Z' X2' X2 X3' X3 Z' Y Z1 Z
  • 22. Grafts Created mostly for projects like linux kernel with old repositories. ● “.git/info/grafts” file ● each line describe parents of a commit ● <commit> <parent> [<parent>]* ● this overrides the content in the commit
  • 23. Problem with Grafts They are neither objects nor refs, so they cannot be easily transferred. We need something that is either: ● an object, or ● a ref
  • 24. Solution, part 1: replace ref ● It is a ref in .git/refs/replace/ ● Its name is the SHA-1 of the object that should be replaced. ● It contains, so it points to, the SHA-1 of the replacement object.
  • 25. Solution, part 2: git replace ● git replace [ -f ] <object> <replacement>: to create a replace ref ● git replace -d <object>: to delete a replace ref ● git replace [ -l [ pattern ] ]: to list some replace refs
  • 26. Replace ref transfer ● as with heads, tags, notes, remotes ● except that there are no shortcuts and you must be explicit ● refspec: refs/replace/*:refs/replace/* ● refspec can be configured (in .git/config), or used on the command line (after git push/fetch <remote>)
  • 27. Creating replacement objects When it is needed the following commands can help: ● git rebase [ -i ] ● git cherry-pick ● git hash-object ● git filter-branch
  • 28. What can it be used for? Create new views of your history. Right now only 2 views are possible: ● the view with all the replace refs enabled ● the view with all the replace refs disabled, using --no-replace-objects or the GIT_NO_REPLACE_OBJECTS environment variable
  • 29. Why new views? ● split old and new history or merge them ● fix bugs to bisect on a clean history ● fix mistakes in author, committer, timestamps ● remove big files to have something lighter to use, when you don’t need them ● prepare a repo cleanup ● mask/unmask some steps ● ...
  • 30. Limitations ● everything is still in the repo ● so the repo is still big ● there are probably bugs ● confusing? ● ...
  • 31. Current and future work ● a script to replace grafts ● fix bugs ● allow subdirectories in .git/refs/replace/ ● maybe allow “views” as set of active subdirectories ● ...
  • 32. Considerations ● best of both world: immutability and configurability of history ● no true view ● history is important for freedom
  • 33. Many thanks to: ● Junio Hamano (comments, help, discussions, reviews, improvements), ● Ingo Molnar, ● Linus Torvalds, ● many other great people in the Git and Linux communities, especially: Andreas Ericsson, Johannes Schindelin, H. Peter Anvin, Daniel Barkalow, Bill Lear, John Hawley, ... ● OSDC/OWF organizers and attendants, ● Murex the company I am working for.