SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
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 ?

Contenu connexe

Tendances

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
 

Tendances (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
 

Similaire à 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
 

Similaire à 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
 

Dernier

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Dernier (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

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.