SlideShare uma empresa Scribd logo
1 de 30
Baixar para ler offline
- My name Shawn Sorichetti
- going to talk about handling
coding mistakes with git
FIXUP
AND
AUTOSQUASH
Shawn Sorichetti
shawn@sorichetti.org
https://ssoriche.com
- I like to start git repositories with an
empty commit, as it creates a rebase
point at the beginning of the repository
- because yes, you can make a mistake
in the initial commit
- creating a develop branch to follow
process
- and now a feature branch
A LITTLE ENVIRONMENT SETUP
git init .
git commit -m "Initial commit" --allow-empty
git checkout -b develop
git checkout -b getting_started
Fixup and Autosquash // Shawn Sorichetti
- some super simple code just
to get the commits going
- this is far from real world, but
needed something to show
- Is that a good commit
message? No.
CREATE SOME SIMPLE CODE
#!/usr/bin/env perl
use strict;
use warnings;
print "Enter your name: ";
my $name = <STDIN>;
print "nHi namen";
git add my_name.pl
git commit -m "Initial code commit"
Fixup and Autosquash // Shawn Sorichetti
- some super simple code just
to get the commits going
- this is far from real world, but
needed something to show
- Is that a good commit
message? No.
CREATE SOME SIMPLE CODE
#!/usr/bin/env perl
use strict;
use warnings;
print "Enter your name: ";
my $name = <STDIN>;
print "nHi namen";
git add my_name.pl
git commit -m "Initial code commit"
Fixup and Autosquash // Shawn Sorichetti
- Going to introduce a change
to the code
CREATE A CHANGE
#!/usr/bin/env perl
use strict;
use warnings;
print "Enter your name: ";
my $name = <STDIN>;
chomp($name);
print "nHi namen";
git add -u
git commit -m "Add newline removal"
Fixup and Autosquash // Shawn Sorichetti
- this changes the way the
code works, and deserves a
separate change
CREATE A CHANGE
#!/usr/bin/env perl
use strict;
use warnings;
print "Enter your name: ";
my $name = <STDIN>;
chomp($name);
print "nHi namen";
git add -u
git commit -m "Add newline removal"
Fixup and Autosquash // Shawn Sorichetti
- when I created the initial code
I made a mistake, did you catch
it?
- failed to identify name as a
variable so name is printed
rather than the $name contents
INITIAL MISTAKE
#!/usr/bin/env perl
use strict;
use warnings;
print "Enter your name: ";
my $name = <STDIN>;
chomp($name);
print "nHi namen";
Fixup and Autosquash // Shawn Sorichetti
INITIAL MISTAKE
#!/usr/bin/env perl
use strict;
use warnings;
print "Enter your name: ";
my $name = <STDIN>;
chomp($name);
print "nHi $namen";
Fixup and Autosquash // Shawn Sorichetti
INITIAL MISTAKE
#!/usr/bin/env perl
use strict;
use warnings;
print "Enter your name: ";
my $name = <STDIN>;
chomp($name);
print "nHi $namen";
git add -u
Fixup and Autosquash // Shawn Sorichetti
- As this was a mistake and
doesn't change the story, it
should not be a separate commit
- just fix the existing commit
- the change has been staged
- but how do we deal with this
mistake
THEN WHAT DO YOU DO?
Fixup and Autosquash // Shawn Sorichetti
- create a new commit with a
distinctive subject reminding
me of what I need to do
- yeah... I forgot.
WHAT I USED TO DO
git commit -m "XXX Rebase and fix up into Initial commit"
Fixup and Autosquash // Shawn Sorichetti
AND THEN THIS HAPPENS
git checkout develop
git merge getting_started
git push origin develop
git log origin/develop --oneline
02cde46 (HEAD -> develop) XXX Rebase and fix up into Initial commit
46c49cf Add newline removal
9a0cb79 Initial code commit
cf186bb (master, develop) Initial commit
Fixup and Autosquash // Shawn Sorichetti
AND THEN THIS HAPPENS
git checkout develop
git merge getting_started
git push origin develop
git log origin/develop --oneline
02cde46 (HEAD -> develop) XXX Rebase and fix up into Initial commit
46c49cf Add newline removal
9a0cb79 Initial code commit
cf186bb (master, develop) Initial commit
Fixup and Autosquash // Shawn Sorichetti
FACEPALM
@mattmight
Fixup and Autosquash // Shawn Sorichetti
- creates a special kind of commit
that includes the subject of the
commit to be fixed
- now this isn't really what I
normally do, I use git log to
find the commit and capture the
SHA and just use that
WHAT I SHOULD HAVE DONE
git commit --fixup :/Initial
Fixup and Autosquash // Shawn Sorichetti
- which is a regex
- this for instance results in the latest commit with the
message matching Initial
- This power by the way is brought to you by rev-parse
- the --fixup argument accepts anything that git rev-
parse will allow
- highly recommend having a read through there
- it's amazing what all can be done to specify a
commit
- one of which is the latest commit of the file, but
that's another talk...
WHAT I SHOULD HAVE DONE
git commit --fixup :/Initial
git help rev-parse
Fixup and Autosquash // Shawn Sorichetti
NOW MY COMMITS LOOK LIKE THIS
git log --oneline
009b808 (HEAD -> getting_started) fixup! Initial code commit
46c49cf Add newline removal
9a0cb79 Initial code commit
cf186bb (master, develop) Initial commit
Fixup and Autosquash // Shawn Sorichetti
- wait a minute, before you had
XXX now you have fixup!
- this doesn't look better
HOW IS THAT BETTER?
Fixup and Autosquash // Shawn Sorichetti
AUTOSQUASH
Fixup and Autosquash // Shawn Sorichetti
- notice that git rebase moved the fixup
commit into
location and applies the fixup option
automatically
- now this is a simple example where there's
only 3 commits
- but imagine 20 - 40 commits, and trying to
move them around
- by hand
AUTOSQUASH
git rebase -i develop --autosquash
pick 9a0cb79 Initial code commit
fixup 2e72bb0 fixup! Initial code commit
pick 46c49cf Add newline removal
# Rebase cf186bb..2e72bb0 onto cf186bb (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
Fixup and Autosquash // Shawn Sorichetti
- Because this code is so
small, it does generate a
merge conflict
- which is pretty easy to fix
- just mentioning it for
completeness
MERGE CONFLICT
#!/usr/bin/env perl
use strict;
use warnings;
print "Enter your name: ";
my $name = <STDIN>;
<<<<<<< HEAD
print "nHi namen";
=======
chomp($name);
print "nHi $namen";
>>>>>>> 2e72bb0... fixup! Initial code commit
Fixup and Autosquash // Shawn Sorichetti
GREAT FOR CODE REVIEWS
Fixup and Autosquash // Shawn Sorichetti
- this is a valid concern
FEEDBACK PROVIDED
Fixup and Autosquash // Shawn Sorichetti
- This is a simple fix
- if condition not to print if
there is no value
- yes, this doesn't handle if a
persons name is 0 or false
FIX IT IN THE CODE
#!/usr/bin/env perl
use strict;
use warnings;
print "Enter your name: ";
my $name = <STDIN>;
chomp($name);
print "nHi $namen" if $name;
git add -u
git commit --fixup :/Initial
git push origin getting_started
Fixup and Autosquash // Shawn Sorichetti
- stage the change for commit
- commit the change again
back to the initial commit
- the history of the request is
kept in the merge request, a
separate commit isn't required
FIX IT IN THE CODE
#!/usr/bin/env perl
use strict;
use warnings;
print "Enter your name: ";
my $name = <STDIN>;
chomp($name);
print "nHi $namen" if $name;
git add -u
git commit --fixup :/Initial
git push origin getting_started
Fixup and Autosquash // Shawn Sorichetti
- this was the merge request
state before the change was
push
THE MERGE REQUEST
Fixup and Autosquash // Shawn Sorichetti
- GitLab has automatically
marked the merge request as
Work in Progress
- it will not allow this merge
request to be completed until
this state is resolved.
THE MERGE REQUEST NOW
Fixup and Autosquash // Shawn Sorichetti
- GitLab has added the fact
that this code has changed
directly to the discussion
- this allows the original
reviewer to mark the
discussion as resolved
AND WHAT DOES THE FEEDBACK LOOK LIKE?
Fixup and Autosquash // Shawn Sorichetti
- once the approval is obtained, we
rebase the branch again, to squash the
fixup
- and we force push the branch to get
the clean history
- at this point the Merge Request Work
in Progress status needs to be
resolved
APPROVED
git rebase -i develop --autosquash
git push --force-with-lease origin getting_started
Fixup and Autosquash // Shawn Sorichetti
HTTPS://SSORICHE.COM/TALKS
Fixup and Autosquash // Shawn Sorichetti

Mais conteúdo relacionado

Mais procurados

The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
Edorian
 
The state of PHPUnit
The state of PHPUnitThe state of PHPUnit
The state of PHPUnit
Edorian
 

Mais procurados (17)

entwickler.de Go Day: Go Web Development 101
entwickler.de Go Day: Go Web Development 101entwickler.de Go Day: Go Web Development 101
entwickler.de Go Day: Go Web Development 101
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
 
The State of PHPUnit
The State of PHPUnitThe State of PHPUnit
The State of PHPUnit
 
betterCode() Go: Einstieg in Go, Standard-Library und Ökosystem
betterCode() Go: Einstieg in Go, Standard-Library und ÖkosystembetterCode() Go: Einstieg in Go, Standard-Library und Ökosystem
betterCode() Go: Einstieg in Go, Standard-Library und Ökosystem
 
Gem That (2009)
Gem That (2009)Gem That (2009)
Gem That (2009)
 
JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
JavaForum Nord 2021: Java to Go - Google Go für Java-EntwicklerJavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
 
The state of PHPUnit
The state of PHPUnitThe state of PHPUnit
The state of PHPUnit
 
Ohh shit git
Ohh shit gitOhh shit git
Ohh shit git
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25
 
ATS language overview
ATS language overviewATS language overview
ATS language overview
 
Git 201: A Deeper Look at Git (Nebraska.Code 2016)
Git 201: A Deeper Look at Git (Nebraska.Code 2016)Git 201: A Deeper Look at Git (Nebraska.Code 2016)
Git 201: A Deeper Look at Git (Nebraska.Code 2016)
 
Goの標準的な開発の流れ
Goの標準的な開発の流れGoの標準的な開発の流れ
Goの標準的な開発の流れ
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
KCDC 2018 - Rapid API Development with Sails
KCDC 2018 - Rapid API Development with SailsKCDC 2018 - Rapid API Development with Sails
KCDC 2018 - Rapid API Development with Sails
 
Github flow
Github flowGithub flow
Github flow
 
Battle of the Stacks
Battle of the StacksBattle of the Stacks
Battle of the Stacks
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
 

Semelhante a Fixup and autosquash

PrizeExample.DS_Store__MACOSXPrizeExample._.DS_StoreP.docx
PrizeExample.DS_Store__MACOSXPrizeExample._.DS_StoreP.docxPrizeExample.DS_Store__MACOSXPrizeExample._.DS_StoreP.docx
PrizeExample.DS_Store__MACOSXPrizeExample._.DS_StoreP.docx
ChantellPantoja184
 
Adding Source Control to Your Life
Adding Source Control to Your LifeAdding Source Control to Your Life
Adding Source Control to Your Life
Mark Kelnar
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X Server
Yasuhiro Asaka
 

Semelhante a Fixup and autosquash (20)

Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
Jas bitbucket
Jas bitbucketJas bitbucket
Jas bitbucket
 
Jas bitbucket
Jas bitbucketJas bitbucket
Jas bitbucket
 
Jas bitbucket
Jas bitbucketJas bitbucket
Jas bitbucket
 
Becoming a Git Master - Nicola Paolucci
Becoming a Git Master - Nicola PaolucciBecoming a Git Master - Nicola Paolucci
Becoming a Git Master - Nicola Paolucci
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use It
 
Automate Yo'self -- SeaGL
Automate Yo'self -- SeaGL Automate Yo'self -- SeaGL
Automate Yo'self -- SeaGL
 
PrizeExample.DS_Store__MACOSXPrizeExample._.DS_StoreP.docx
PrizeExample.DS_Store__MACOSXPrizeExample._.DS_StoreP.docxPrizeExample.DS_Store__MACOSXPrizeExample._.DS_StoreP.docx
PrizeExample.DS_Store__MACOSXPrizeExample._.DS_StoreP.docx
 
Adding Source Control to Your Life
Adding Source Control to Your LifeAdding Source Control to Your Life
Adding Source Control to Your Life
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Automate Yo' Self
Automate Yo' SelfAutomate Yo' Self
Automate Yo' Self
 
Becoming a Git Master
Becoming a Git MasterBecoming a Git Master
Becoming a Git Master
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Git avançado
Git avançadoGit avançado
Git avançado
 
Buildout: Fostering Repeatability
Buildout: Fostering RepeatabilityBuildout: Fostering Repeatability
Buildout: Fostering Repeatability
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X Server
 
Loading...git
Loading...gitLoading...git
Loading...git
 
Capistrano
CapistranoCapistrano
Capistrano
 
Git Anti-Patterns: How To Mess Up With Git and Love it Again
Git Anti-Patterns: How To Mess Up With Git and Love it AgainGit Anti-Patterns: How To Mess Up With Git and Love it Again
Git Anti-Patterns: How To Mess Up With Git and Love it Again
 

Último

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
panagenda
 

Último (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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
 
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
 
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
 
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
 
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...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 

Fixup and autosquash

  • 1. - My name Shawn Sorichetti - going to talk about handling coding mistakes with git FIXUP AND AUTOSQUASH Shawn Sorichetti shawn@sorichetti.org https://ssoriche.com
  • 2. - I like to start git repositories with an empty commit, as it creates a rebase point at the beginning of the repository - because yes, you can make a mistake in the initial commit - creating a develop branch to follow process - and now a feature branch A LITTLE ENVIRONMENT SETUP git init . git commit -m "Initial commit" --allow-empty git checkout -b develop git checkout -b getting_started Fixup and Autosquash // Shawn Sorichetti
  • 3. - some super simple code just to get the commits going - this is far from real world, but needed something to show - Is that a good commit message? No. CREATE SOME SIMPLE CODE #!/usr/bin/env perl use strict; use warnings; print "Enter your name: "; my $name = <STDIN>; print "nHi namen"; git add my_name.pl git commit -m "Initial code commit" Fixup and Autosquash // Shawn Sorichetti
  • 4. - some super simple code just to get the commits going - this is far from real world, but needed something to show - Is that a good commit message? No. CREATE SOME SIMPLE CODE #!/usr/bin/env perl use strict; use warnings; print "Enter your name: "; my $name = <STDIN>; print "nHi namen"; git add my_name.pl git commit -m "Initial code commit" Fixup and Autosquash // Shawn Sorichetti
  • 5. - Going to introduce a change to the code CREATE A CHANGE #!/usr/bin/env perl use strict; use warnings; print "Enter your name: "; my $name = <STDIN>; chomp($name); print "nHi namen"; git add -u git commit -m "Add newline removal" Fixup and Autosquash // Shawn Sorichetti
  • 6. - this changes the way the code works, and deserves a separate change CREATE A CHANGE #!/usr/bin/env perl use strict; use warnings; print "Enter your name: "; my $name = <STDIN>; chomp($name); print "nHi namen"; git add -u git commit -m "Add newline removal" Fixup and Autosquash // Shawn Sorichetti
  • 7. - when I created the initial code I made a mistake, did you catch it? - failed to identify name as a variable so name is printed rather than the $name contents INITIAL MISTAKE #!/usr/bin/env perl use strict; use warnings; print "Enter your name: "; my $name = <STDIN>; chomp($name); print "nHi namen"; Fixup and Autosquash // Shawn Sorichetti
  • 8. INITIAL MISTAKE #!/usr/bin/env perl use strict; use warnings; print "Enter your name: "; my $name = <STDIN>; chomp($name); print "nHi $namen"; Fixup and Autosquash // Shawn Sorichetti
  • 9. INITIAL MISTAKE #!/usr/bin/env perl use strict; use warnings; print "Enter your name: "; my $name = <STDIN>; chomp($name); print "nHi $namen"; git add -u Fixup and Autosquash // Shawn Sorichetti
  • 10. - As this was a mistake and doesn't change the story, it should not be a separate commit - just fix the existing commit - the change has been staged - but how do we deal with this mistake THEN WHAT DO YOU DO? Fixup and Autosquash // Shawn Sorichetti
  • 11. - create a new commit with a distinctive subject reminding me of what I need to do - yeah... I forgot. WHAT I USED TO DO git commit -m "XXX Rebase and fix up into Initial commit" Fixup and Autosquash // Shawn Sorichetti
  • 12. AND THEN THIS HAPPENS git checkout develop git merge getting_started git push origin develop git log origin/develop --oneline 02cde46 (HEAD -> develop) XXX Rebase and fix up into Initial commit 46c49cf Add newline removal 9a0cb79 Initial code commit cf186bb (master, develop) Initial commit Fixup and Autosquash // Shawn Sorichetti
  • 13. AND THEN THIS HAPPENS git checkout develop git merge getting_started git push origin develop git log origin/develop --oneline 02cde46 (HEAD -> develop) XXX Rebase and fix up into Initial commit 46c49cf Add newline removal 9a0cb79 Initial code commit cf186bb (master, develop) Initial commit Fixup and Autosquash // Shawn Sorichetti
  • 15. - creates a special kind of commit that includes the subject of the commit to be fixed - now this isn't really what I normally do, I use git log to find the commit and capture the SHA and just use that WHAT I SHOULD HAVE DONE git commit --fixup :/Initial Fixup and Autosquash // Shawn Sorichetti
  • 16. - which is a regex - this for instance results in the latest commit with the message matching Initial - This power by the way is brought to you by rev-parse - the --fixup argument accepts anything that git rev- parse will allow - highly recommend having a read through there - it's amazing what all can be done to specify a commit - one of which is the latest commit of the file, but that's another talk... WHAT I SHOULD HAVE DONE git commit --fixup :/Initial git help rev-parse Fixup and Autosquash // Shawn Sorichetti
  • 17. NOW MY COMMITS LOOK LIKE THIS git log --oneline 009b808 (HEAD -> getting_started) fixup! Initial code commit 46c49cf Add newline removal 9a0cb79 Initial code commit cf186bb (master, develop) Initial commit Fixup and Autosquash // Shawn Sorichetti
  • 18. - wait a minute, before you had XXX now you have fixup! - this doesn't look better HOW IS THAT BETTER? Fixup and Autosquash // Shawn Sorichetti
  • 19. AUTOSQUASH Fixup and Autosquash // Shawn Sorichetti
  • 20. - notice that git rebase moved the fixup commit into location and applies the fixup option automatically - now this is a simple example where there's only 3 commits - but imagine 20 - 40 commits, and trying to move them around - by hand AUTOSQUASH git rebase -i develop --autosquash pick 9a0cb79 Initial code commit fixup 2e72bb0 fixup! Initial code commit pick 46c49cf Add newline removal # Rebase cf186bb..2e72bb0 onto cf186bb (3 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message # x, exec <command> = run command (the rest of the line) using shell # b, break = stop here (continue rebase later with 'git rebase --continue') # d, drop <commit> = remove commit # l, label <label> = label current HEAD with a name # t, reset <label> = reset HEAD to a label # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>] # . create a merge commit using the original merge commit's # . message (or the oneline, if no original merge commit was # . specified). Use -c <commit> to reword the commit message. # # These lines can be re-ordered; they are executed from top to bottom. Fixup and Autosquash // Shawn Sorichetti
  • 21. - Because this code is so small, it does generate a merge conflict - which is pretty easy to fix - just mentioning it for completeness MERGE CONFLICT #!/usr/bin/env perl use strict; use warnings; print "Enter your name: "; my $name = <STDIN>; <<<<<<< HEAD print "nHi namen"; ======= chomp($name); print "nHi $namen"; >>>>>>> 2e72bb0... fixup! Initial code commit Fixup and Autosquash // Shawn Sorichetti
  • 22. GREAT FOR CODE REVIEWS Fixup and Autosquash // Shawn Sorichetti
  • 23. - this is a valid concern FEEDBACK PROVIDED Fixup and Autosquash // Shawn Sorichetti
  • 24. - This is a simple fix - if condition not to print if there is no value - yes, this doesn't handle if a persons name is 0 or false FIX IT IN THE CODE #!/usr/bin/env perl use strict; use warnings; print "Enter your name: "; my $name = <STDIN>; chomp($name); print "nHi $namen" if $name; git add -u git commit --fixup :/Initial git push origin getting_started Fixup and Autosquash // Shawn Sorichetti
  • 25. - stage the change for commit - commit the change again back to the initial commit - the history of the request is kept in the merge request, a separate commit isn't required FIX IT IN THE CODE #!/usr/bin/env perl use strict; use warnings; print "Enter your name: "; my $name = <STDIN>; chomp($name); print "nHi $namen" if $name; git add -u git commit --fixup :/Initial git push origin getting_started Fixup and Autosquash // Shawn Sorichetti
  • 26. - this was the merge request state before the change was push THE MERGE REQUEST Fixup and Autosquash // Shawn Sorichetti
  • 27. - GitLab has automatically marked the merge request as Work in Progress - it will not allow this merge request to be completed until this state is resolved. THE MERGE REQUEST NOW Fixup and Autosquash // Shawn Sorichetti
  • 28. - GitLab has added the fact that this code has changed directly to the discussion - this allows the original reviewer to mark the discussion as resolved AND WHAT DOES THE FEEDBACK LOOK LIKE? Fixup and Autosquash // Shawn Sorichetti
  • 29. - once the approval is obtained, we rebase the branch again, to squash the fixup - and we force push the branch to get the clean history - at this point the Merge Request Work in Progress status needs to be resolved APPROVED git rebase -i develop --autosquash git push --force-with-lease origin getting_started Fixup and Autosquash // Shawn Sorichetti