SlideShare a Scribd company logo
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!
Ad

More Related Content

Similar to Fancy Git (20)

Keep your GIT history clean
Keep your GIT history cleanKeep your GIT history clean
Keep your GIT history clean
tomasbro
 
Git for beginner
Git for beginnerGit for beginner
Git for beginner
Trung Huynh
 
Git For Beginer
Git For BeginerGit For Beginer
Git For Beginer
Trung Huynh
 
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
Katie Sylor-Miller
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
Nick Quaranto
 
M.Mozūras - git
M.Mozūras - gitM.Mozūras - git
M.Mozūras - git
Agile Lietuva
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By Swawibe
Md Swawibe Ul Alam
 
Undoing Things in Git
Undoing Things in GitUndoing Things in Git
Undoing Things in Git
gittower
 
How to use git without rage
How to use git without rageHow to use git without rage
How to use git without rage
Javier Lafora Rey
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
Fran García
 
Git introduction
Git introductionGit introduction
Git introduction
Dimitar Danailov
 
Git: Overview, Pitfalls, Best Practices
Git: Overview, Pitfalls, Best PracticesGit: Overview, Pitfalls, Best Practices
Git: Overview, Pitfalls, Best Practices
Jeremy Leisy
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
Tagged Social
 
YET ANOTHER INTRODCTION AND AN EXAMPLE HOW NOT TO USE BAD PRESENTATION STYLES
YET ANOTHER INTRODCTION AND AN EXAMPLE HOW NOT TO USE BAD PRESENTATION STYLESYET ANOTHER INTRODCTION AND AN EXAMPLE HOW NOT TO USE BAD PRESENTATION STYLES
YET ANOTHER INTRODCTION AND AN EXAMPLE HOW NOT TO USE BAD PRESENTATION STYLES
removed_7e30d0915f14b559919f338a71e486d1
 
Working with Git
Working with GitWorking with Git
Working with Git
Pete Nicholls
 
Introducción a git y GitHub
Introducción a git y GitHubIntroducción a git y GitHub
Introducción a git y GitHub
Lucas Videla
 
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a BossGit Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
tmacwilliam
 
Sacándole jugo a git
Sacándole jugo a gitSacándole jugo a git
Sacándole jugo a git
Berny Cantos
 
Git rebase
Git rebaseGit rebase
Git rebase
SitaPrajapati
 
Git
GitGit
Git
Kang-min Liu
 
Keep your GIT history clean
Keep your GIT history cleanKeep your GIT history clean
Keep your GIT history clean
tomasbro
 
Git for beginner
Git for beginnerGit for beginner
Git for beginner
Trung Huynh
 
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
Katie Sylor-Miller
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
Nick Quaranto
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By Swawibe
Md Swawibe Ul Alam
 
Undoing Things in Git
Undoing Things in GitUndoing Things in Git
Undoing Things in Git
gittower
 
Git: Overview, Pitfalls, Best Practices
Git: Overview, Pitfalls, Best PracticesGit: Overview, Pitfalls, Best Practices
Git: Overview, Pitfalls, Best Practices
Jeremy Leisy
 
YET ANOTHER INTRODCTION AND AN EXAMPLE HOW NOT TO USE BAD PRESENTATION STYLES
YET ANOTHER INTRODCTION AND AN EXAMPLE HOW NOT TO USE BAD PRESENTATION STYLESYET ANOTHER INTRODCTION AND AN EXAMPLE HOW NOT TO USE BAD PRESENTATION STYLES
YET ANOTHER INTRODCTION AND AN EXAMPLE HOW NOT TO USE BAD PRESENTATION STYLES
removed_7e30d0915f14b559919f338a71e486d1
 
Introducción a git y GitHub
Introducción a git y GitHubIntroducción a git y GitHub
Introducción a git y GitHub
Lucas Videla
 
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a BossGit Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
tmacwilliam
 
Sacándole jugo a git
Sacándole jugo a gitSacándole jugo a git
Sacándole jugo a git
Berny Cantos
 

Recently uploaded (20)

π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Ad

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