SlideShare a Scribd company logo
1 of 30
Fancy Git
Liu Lin
How to modify
what you have committed?
1.Chang the Last Commit
❖ git commit --amend
C1 C2 C3 C4 C5
master
HEAD
C5’
master
HEAD
2.Chang Multiple Commit Message
C1 C2 C3 C4 C5 C6
❖ Change Message
pick C4 add a.file
pick C5 add first line
pick C6 add second line
Rebase C3..C6 onto C3
edit C4 add a.file
pick C5 add first line
pick C6 add second line
Rebase C3..C6 onto C3
master
HEAD
git rebase -i C3
C1 C2 C3 C4 C5 C6
❖ Change Message
add a.file
git commit --amend
change c4 message
C4’ C5’ C6’git rebase --continue
HEAD master
HEAD
master
HEAD
3.Reorder Commits
C1 C2 C3 C4 C5 C6
pick C4 add a.file
pick C5 add first line
pick C6 add second line
Rebase C3..C6 onto C3
pick C5 add first line
pick C4 add a.file
Rebase C3..C6 onto C3
❖ Reorder Commits
C5’ C4’
git rebase -i HEAD~3
master
HEAD
4.Squash Commits
C1 C2 C3 C4 C5 C6
pick C5 add first line
pick C6 add second line
Rebase C4..C6 onto C4
pick C5 add first line
squash C6 add second line
Rebase C4..C6 onto C4
❖ Squash Commits
master
HEAD
git rebase -i HEAD~2
C1 C2 C3 C4 C5 C6
# This s a combination of 2 commits.
# The first commit's message is:
add first line
# This is the 2nd commit message:
add second line
❖ Squash Commits
C5C6’
master
HEAD
master
HEAD
tree c9cb48
parent C4
add first line
add second line
git cat-file -p C5’
5.Split a Commit
C1 C2 C3 C4 C5 C6
❖ Split a Commit
pick C5 add first line and b.file
pick C6 add second line
Rebase C4..C6 onto C4
edit C5 add first line and b.file
pick C6 add second line
Rebase C4..C6 onto C4
master
HEAD
git rebase -i C4
C1 C2 C3 C4 C5 C6
❖ Split a Commit
HEAD master
git reset HEAD~1
a.file
b.file
C5-1
git commit -m ‘add a.file’
git commit -m ‘add b.file’
HEAD
C5-2
C1 C2 C3 C4 C5 C6
❖ Split a Commit
master
C5-1
HEAD
C5-2 C6’
git rebase --continue
master
HEAD
How to modify
what you have pushed?
C1 C2 C3 C4 C5 -C5
❖ git revert C5
master
HEAD
origin/master
- This is the one line
- This is the two line
Diff
❖ git push --force
C1 C2 C3
C1 C2 C3
R4
origin/master
master
L4
L4
origin/master
Local Repo
Remote Repo
❖ git reflog show remotes/origin/master
L4 remotes/origin/master@{0} : update by push
R4 remotes/origin/master@{1} : update by push
C3 remotes/origin/master@{2} : update by push
C2 remotes/origin/master@{3} : update by push
C1 remotes/origin/master@{4} : update by push
C1 C2 C3 R4
L4
origin/master
Remote Repo
❖ git checkout -b temp R4
C1 C2 C3
origin/master
master
L4
Local Repo
R4
HEAD
temp
❖ git push --force origin temp:master
C1 C2 C3
C1 C2 C3
R4
origin/master
master
L4
L4
origin/master
Local Repo
Remote Repo
R4tempHEAD
How to deal with
a detached HEAD?
C1 C2 C3 C4 C5 C6
❖ git checkout -b new
master
HEAD
B1
HEAD
new
How to find
the commit you lose?
❖ git reflog
Git Repo
logs
HEAD
refs
heads
master
remotes
origin
master
HEAD
branch1
git reflog show HEAD
git reflog show master
git reflog show remotes/origin/master
❖ git cherry-pick B2
C1 C2 C3 C4 C5
master
HEAD
B2’
B1 B2 B3
fix
The Premiums
❖ git rebase --onto master fix1 fix2
C1 C2 C3 A1’ A2’
master
HEAD
B1 B2 B3
fix1
A1 A2
fix2
Thanks!

More Related Content

Similar to Fancy Git

Git-ing out of your git messes - Fluent Conf 2017
Git-ing out of  your git messes - Fluent Conf 2017Git-ing out of  your git messes - Fluent Conf 2017
Git-ing out of your git messes - Fluent Conf 2017Katie Sylor-Miller
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With GitNick Quaranto
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeMd Swawibe Ul Alam
 
Undoing Things in Git
Undoing Things in GitUndoing Things in Git
Undoing Things in Gitgittower
 
Effective Git with Eclipse
Effective Git with EclipseEffective Git with Eclipse
Effective Git with EclipseChris Aniszczyk
 
Git: Overview, Pitfalls, Best Practices
Git: Overview, Pitfalls, Best PracticesGit: Overview, Pitfalls, Best Practices
Git: Overview, Pitfalls, Best PracticesJeremy Leisy
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
Introduction to git, an efficient distributed version control system
Introduction to git, an efficient distributed version control systemIntroduction to git, an efficient distributed version control system
Introduction to git, an efficient distributed version control systemAlbanLevy
 
Sacándole jugo a git
Sacándole jugo a gitSacándole jugo a git
Sacándole jugo a gitBerny Cantos
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthroughBimal Jain
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messesKatie Sylor-Miller
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshellalignan
 
Essential Git and Github commands
Essential Git and Github commandsEssential Git and Github commands
Essential Git and Github commandsIsham Rashik
 

Similar to Fancy Git (20)

Git-ing out of your git messes - Fluent Conf 2017
Git-ing out of  your git messes - Fluent Conf 2017Git-ing out of  your git messes - Fluent Conf 2017
Git-ing out of your git messes - Fluent Conf 2017
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
M.Mozūras - git
M.Mozūras - gitM.Mozūras - git
M.Mozūras - git
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By Swawibe
 
Undoing Things in Git
Undoing Things in GitUndoing Things in Git
Undoing Things in Git
 
How to use git without rage
How to use git without rageHow to use git without rage
How to use git without rage
 
Effective Git with Eclipse
Effective Git with EclipseEffective Git with Eclipse
Effective Git with Eclipse
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
 
Git introduction
Git introductionGit introduction
Git introduction
 
Git: Overview, Pitfalls, Best Practices
Git: Overview, Pitfalls, Best PracticesGit: Overview, Pitfalls, Best Practices
Git: Overview, Pitfalls, Best Practices
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Introduction to git, an efficient distributed version control system
Introduction to git, an efficient distributed version control systemIntroduction to git, an efficient distributed version control system
Introduction to git, an efficient distributed version control system
 
Sacándole jugo a git
Sacándole jugo a gitSacándole jugo a git
Sacándole jugo a git
 
Git rebase
Git rebaseGit rebase
Git rebase
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
Git
GitGit
Git
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
 
Essential Git and Github commands
Essential Git and Github commandsEssential Git and Github commands
Essential Git and Github commands
 
Working with Git
Working with GitWorking with Git
Working with Git
 

Recently uploaded

Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxMustafa Ahmed
 
Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Studentskannan348865
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...archanaece3
 
Databricks Generative AI Fundamentals .pdf
Databricks Generative AI Fundamentals  .pdfDatabricks Generative AI Fundamentals  .pdf
Databricks Generative AI Fundamentals .pdfVinayVadlagattu
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailingAshishSingh1301
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxMustafa Ahmed
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...IJECEIAES
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxCHAIRMAN M
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfKira Dess
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfEr.Sonali Nasikkar
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdfAlexander Litvinenko
 
Presentation on Slab, Beam, Column, and Foundation/Footing
Presentation on Slab,  Beam, Column, and Foundation/FootingPresentation on Slab,  Beam, Column, and Foundation/Footing
Presentation on Slab, Beam, Column, and Foundation/FootingEr. Suman Jyoti
 
Independent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging StationIndependent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging Stationsiddharthteach18
 
Artificial Intelligence in due diligence
Artificial Intelligence in due diligenceArtificial Intelligence in due diligence
Artificial Intelligence in due diligencemahaffeycheryld
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfJNTUA
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docxrahulmanepalli02
 
Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...IJECEIAES
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxMustafa Ahmed
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfSkNahidulIslamShrabo
 

Recently uploaded (20)

Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Students
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...
 
Databricks Generative AI Fundamentals .pdf
Databricks Generative AI Fundamentals  .pdfDatabricks Generative AI Fundamentals  .pdf
Databricks Generative AI Fundamentals .pdf
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
Presentation on Slab, Beam, Column, and Foundation/Footing
Presentation on Slab,  Beam, Column, and Foundation/FootingPresentation on Slab,  Beam, Column, and Foundation/Footing
Presentation on Slab, Beam, Column, and Foundation/Footing
 
Independent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging StationIndependent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging Station
 
Artificial Intelligence in due diligence
Artificial Intelligence in due diligenceArtificial Intelligence in due diligence
Artificial Intelligence in due diligence
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdf
 

Fancy Git

  • 2. How to modify what you have committed?
  • 4. ❖ git commit --amend C1 C2 C3 C4 C5 master HEAD C5’ master HEAD
  • 6. C1 C2 C3 C4 C5 C6 ❖ Change Message pick C4 add a.file pick C5 add first line pick C6 add second line Rebase C3..C6 onto C3 edit C4 add a.file pick C5 add first line pick C6 add second line Rebase C3..C6 onto C3 master HEAD git rebase -i C3
  • 7. C1 C2 C3 C4 C5 C6 ❖ Change Message add a.file git commit --amend change c4 message C4’ C5’ C6’git rebase --continue HEAD master HEAD master HEAD
  • 9. C1 C2 C3 C4 C5 C6 pick C4 add a.file pick C5 add first line pick C6 add second line Rebase C3..C6 onto C3 pick C5 add first line pick C4 add a.file Rebase C3..C6 onto C3 ❖ Reorder Commits C5’ C4’ git rebase -i HEAD~3 master HEAD
  • 11. C1 C2 C3 C4 C5 C6 pick C5 add first line pick C6 add second line Rebase C4..C6 onto C4 pick C5 add first line squash C6 add second line Rebase C4..C6 onto C4 ❖ Squash Commits master HEAD git rebase -i HEAD~2
  • 12. C1 C2 C3 C4 C5 C6 # This s a combination of 2 commits. # The first commit's message is: add first line # This is the 2nd commit message: add second line ❖ Squash Commits C5C6’ master HEAD master HEAD tree c9cb48 parent C4 add first line add second line git cat-file -p C5’
  • 14. C1 C2 C3 C4 C5 C6 ❖ Split a Commit pick C5 add first line and b.file pick C6 add second line Rebase C4..C6 onto C4 edit C5 add first line and b.file pick C6 add second line Rebase C4..C6 onto C4 master HEAD git rebase -i C4
  • 15. C1 C2 C3 C4 C5 C6 ❖ Split a Commit HEAD master git reset HEAD~1 a.file b.file C5-1 git commit -m ‘add a.file’ git commit -m ‘add b.file’ HEAD C5-2
  • 16. C1 C2 C3 C4 C5 C6 ❖ Split a Commit master C5-1 HEAD C5-2 C6’ git rebase --continue master HEAD
  • 17. How to modify what you have pushed?
  • 18. C1 C2 C3 C4 C5 -C5 ❖ git revert C5 master HEAD origin/master - This is the one line - This is the two line Diff
  • 19. ❖ git push --force C1 C2 C3 C1 C2 C3 R4 origin/master master L4 L4 origin/master Local Repo Remote Repo
  • 20. ❖ git reflog show remotes/origin/master L4 remotes/origin/master@{0} : update by push R4 remotes/origin/master@{1} : update by push C3 remotes/origin/master@{2} : update by push C2 remotes/origin/master@{3} : update by push C1 remotes/origin/master@{4} : update by push C1 C2 C3 R4 L4 origin/master Remote Repo
  • 21. ❖ git checkout -b temp R4 C1 C2 C3 origin/master master L4 Local Repo R4 HEAD temp
  • 22. ❖ git push --force origin temp:master C1 C2 C3 C1 C2 C3 R4 origin/master master L4 L4 origin/master Local Repo Remote Repo R4tempHEAD
  • 23. How to deal with a detached HEAD?
  • 24. C1 C2 C3 C4 C5 C6 ❖ git checkout -b new master HEAD B1 HEAD new
  • 25. How to find the commit you lose?
  • 26. ❖ git reflog Git Repo logs HEAD refs heads master remotes origin master HEAD branch1 git reflog show HEAD git reflog show master git reflog show remotes/origin/master
  • 27. ❖ git cherry-pick B2 C1 C2 C3 C4 C5 master HEAD B2’ B1 B2 B3 fix
  • 29. ❖ git rebase --onto master fix1 fix2 C1 C2 C3 A1’ A2’ master HEAD B1 B2 B3 fix1 A1 A2 fix2