SlideShare a Scribd company logo
1 of 22
Download to read offline
Git: Basic to Advanced
Yodalee <lc85301@gmail.com>
Before start
某:小弟我想知道merge, cherry什麼的, rebase還有reflog
某:可以的話 stash 順便
某:log --graph介紹一下
某:我只會commit嗚嗚
某:remote的概念可以介紹一下呀
某:我不會交女朋友呀(炸
(╯-_-)╯ ~╩╩ , man git-XXX (無誤)
Git: Basic
git init
git add
git commit
Extend Reading Material:
http://johnjohnlys.blogspot.tw/2012/08/git-part-1.html
Git Basic
Git: Reference
➔ git branch
➔ git tag
➔ HEAD, ORIG_HEAD, FETCH_HEAD
Notice:
1. Each reference points to a commit (Hash)
2. Low cost to move a reference (FF)
Git: Reference
Git: Remote
● Remote and Local
are independent.
● Use fetch/push to
get/set remote data.
Git rebase
Cut down a branch, connect to other
Steps:
1. Checkout the new-base
2. Re-apply commits
3. Stop if conflict
Git rebase -i
Interactive Rebase, you can:
● Change content(edit)
● Change message(reword)
● Change order
● Combine/Split commit(squash, reset)
● Run command(exec)
Extend Reading Material:
http://blog.yorkxin.org/posts/2011/07/29/git-rebase/
Git rebase
!rebase 有機會竄改歷史!
在已經merge 的branch 上rebase 會怎麼樣?
➔ = = 建議千萬別這樣做..上次有人這樣 結果把分枝弄得一團亂..
➔ 樓上..然後呢@@
➔ 就把分枝弄得一團亂 很不方便..
git stash
● Temporary store the changes you made.
● Useful with rebase
Basic usage: stash <push, pop, list>
Extend Reading Material:
http://yodalee.blogspot.tw/2013/12/git-stash.html
git format-patch, am
● git format-patch <Ref>
○ generate patches
● git am <path-to-patch>
○ Apply patches
git bisect
Find the commit that changes somthing, steps:
1. bisect start
2. Set “bisect bad”, “bisect good”
3. Keep testing; set bad or good
4. Find the commit
Extend Reading Material:
http://yodalee.blogspot.tw/2014/08/git-bisect.html
git cherry-pick
Pick out the change in some commit.
● -n, --no-commit: allow you edit, commit
manually
Not very useful, actually.
Git inside
ls * in .git:
● Object/: Data
● Refs/: Reference
● Logs/: Change to Reference
● other files
Extend Reading Material:
http://git-scm.com/docs/gitrepository-layout
Git reflog
● View the list of HEAD movement. record the
Hash and action
● Log when you move reference by
<commit, rebase, reset, checkout>
If you get the Hash, you can recover it.
Git fsck
● Fsck check repository integrity, find dangling
commits.
● Even reflog is deleted or not record, ex:
git branch -D some-branch
rm -Rf .git/logs/
Git gc
● Git do 'git gc --auto' automatically, it will
○ Pack the loose files (refs->packed-refs)
○ Delete the Non-reference files.
Git filter-branch
Filter out some commits, and do some change.
ex. git filter-branch --msg-filter “echo XD” branch
--Change all commit message into “XD”
ex. git filter-branch --index-filter “rm xxx” branch
--Delete file from git repository
Extend Reading Material:
http://yodalee.blogspot.tw/2014/06/git-gc.html
Git filter-branch
!filter-branch 就是要更動歷史!
在已經merge 的branch 上filter-branch會怎麼
樣?
➔ = = 建議千萬別這樣做..上次有人這樣 結果把分枝弄得一團亂..
➔ 樓上..然後呢@@
➔ 就把分枝弄得一團亂 很不方便..
Git useful tool
Linux: gitk, gitg
https://wiki.gnome.org/Apps/Gitg/
MacOS:
http://gitx.frim.nl/
Windows: X! I don’t know
The End
● Git is POWERFUL. With basic skills, it can
fulfill daily requirement.
● Hope everyone can become Git Master

More Related Content

What's hot

Git tutorial
Git tutorialGit tutorial
Git tutorialmobaires
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use ItDaniel Kummer
 
Version Control Systems with git (and github) as an example
Version Control Systems with git (and github) as an exampleVersion Control Systems with git (and github) as an example
Version Control Systems with git (and github) as an exampleGaurav Kumar Garg
 
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
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
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
 
Git - The Incomplete Introduction
Git - The Incomplete IntroductionGit - The Incomplete Introduction
Git - The Incomplete Introductionrschwietzke
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial IJim Yeh
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeMd Swawibe Ul Alam
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHubNicolás Tourné
 

What's hot (20)

Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git basics
Git basicsGit basics
Git basics
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use It
 
Version Control Systems with git (and github) as an example
Version Control Systems with git (and github) as an exampleVersion Control Systems with git (and github) as an example
Version Control Systems with git (and github) as an example
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
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 tutorial
Git tutorialGit tutorial
Git tutorial
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Git commands
Git commandsGit commands
Git commands
 
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
 
Git - The Incomplete Introduction
Git - The Incomplete IntroductionGit - The Incomplete Introduction
Git - The Incomplete Introduction
 
Git in 5 Minutes
Git in 5 MinutesGit in 5 Minutes
Git in 5 Minutes
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By Swawibe
 
Git & GitHub for Beginners
Git & GitHub for BeginnersGit & GitHub for Beginners
Git & GitHub for Beginners
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
 

Similar to Git: basic to advanced

Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptuallyseungzzang Kim
 
Git tech talk
Git tech talkGit tech talk
Git tech talkrazasayed
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221Shinho Kang
 
Getting some Git
Getting some GitGetting some Git
Getting some GitBADR
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practiceMajid Hosseini
 
Git cheat-sheets
Git cheat-sheetsGit cheat-sheets
Git cheat-sheetsozone777
 
Git slides
Git slidesGit slides
Git slidesNanyak S
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?9 series
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commandsZakaria Bouazza
 
Git Basics 1 Carenza
Git Basics 1 CarenzaGit Basics 1 Carenza
Git Basics 1 CarenzaPeter Carenza
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubDSC GVP
 

Similar to Git: basic to advanced (20)

Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
 
Introduction to GIT
Introduction to GITIntroduction to GIT
Introduction to GIT
 
Git tech talk
Git tech talkGit tech talk
Git tech talk
 
Git basics 2
Git basics 2Git basics 2
Git basics 2
 
Git
GitGit
Git
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
 
Getting some Git
Getting some GitGetting some Git
Getting some Git
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 
Git cheat-sheets
Git cheat-sheetsGit cheat-sheets
Git cheat-sheets
 
Git slides
Git slidesGit slides
Git slides
 
Intro to Git
Intro to GitIntro to Git
Intro to Git
 
Git: Git'ing the Basic
Git: Git'ing the BasicGit: Git'ing the Basic
Git: Git'ing the Basic
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commands
 
Git Basics 1 Carenza
Git Basics 1 CarenzaGit Basics 1 Carenza
Git Basics 1 Carenza
 
Git of every day
Git of every dayGit of every day
Git of every day
 
Git and Github workshop
Git and Github workshopGit and Github workshop
Git and Github workshop
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 

More from Yodalee

COSCUP2023 RSA256 Verilator.pdf
COSCUP2023 RSA256 Verilator.pdfCOSCUP2023 RSA256 Verilator.pdf
COSCUP2023 RSA256 Verilator.pdfYodalee
 
rrxv6 Build a Riscv xv6 Kernel in Rust.pdf
rrxv6 Build a Riscv xv6 Kernel in Rust.pdfrrxv6 Build a Riscv xv6 Kernel in Rust.pdf
rrxv6 Build a Riscv xv6 Kernel in Rust.pdfYodalee
 
Gameboy emulator in rust and web assembly
Gameboy emulator in rust and web assemblyGameboy emulator in rust and web assembly
Gameboy emulator in rust and web assemblyYodalee
 
Make A Shoot ‘Em Up Game with Amethyst Framework
Make A Shoot ‘Em Up Game with Amethyst FrameworkMake A Shoot ‘Em Up Game with Amethyst Framework
Make A Shoot ‘Em Up Game with Amethyst FrameworkYodalee
 
Build Yourself a Nixie Tube Clock
Build Yourself a Nixie Tube ClockBuild Yourself a Nixie Tube Clock
Build Yourself a Nixie Tube ClockYodalee
 
Use PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language ParserUse PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language ParserYodalee
 
Introduction to nand2 tetris
Introduction to nand2 tetrisIntroduction to nand2 tetris
Introduction to nand2 tetrisYodalee
 
Office word skills
Office word skillsOffice word skills
Office word skillsYodalee
 

More from Yodalee (8)

COSCUP2023 RSA256 Verilator.pdf
COSCUP2023 RSA256 Verilator.pdfCOSCUP2023 RSA256 Verilator.pdf
COSCUP2023 RSA256 Verilator.pdf
 
rrxv6 Build a Riscv xv6 Kernel in Rust.pdf
rrxv6 Build a Riscv xv6 Kernel in Rust.pdfrrxv6 Build a Riscv xv6 Kernel in Rust.pdf
rrxv6 Build a Riscv xv6 Kernel in Rust.pdf
 
Gameboy emulator in rust and web assembly
Gameboy emulator in rust and web assemblyGameboy emulator in rust and web assembly
Gameboy emulator in rust and web assembly
 
Make A Shoot ‘Em Up Game with Amethyst Framework
Make A Shoot ‘Em Up Game with Amethyst FrameworkMake A Shoot ‘Em Up Game with Amethyst Framework
Make A Shoot ‘Em Up Game with Amethyst Framework
 
Build Yourself a Nixie Tube Clock
Build Yourself a Nixie Tube ClockBuild Yourself a Nixie Tube Clock
Build Yourself a Nixie Tube Clock
 
Use PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language ParserUse PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language Parser
 
Introduction to nand2 tetris
Introduction to nand2 tetrisIntroduction to nand2 tetris
Introduction to nand2 tetris
 
Office word skills
Office word skillsOffice word skills
Office word skills
 

Recently uploaded

What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 

Recently uploaded (20)

What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 

Git: basic to advanced

  • 1. Git: Basic to Advanced Yodalee <lc85301@gmail.com>
  • 2. Before start 某:小弟我想知道merge, cherry什麼的, rebase還有reflog 某:可以的話 stash 順便 某:log --graph介紹一下 某:我只會commit嗚嗚 某:remote的概念可以介紹一下呀 某:我不會交女朋友呀(炸 (╯-_-)╯ ~╩╩ , man git-XXX (無誤)
  • 3. Git: Basic git init git add git commit Extend Reading Material: http://johnjohnlys.blogspot.tw/2012/08/git-part-1.html
  • 5. Git: Reference ➔ git branch ➔ git tag ➔ HEAD, ORIG_HEAD, FETCH_HEAD Notice: 1. Each reference points to a commit (Hash) 2. Low cost to move a reference (FF)
  • 7. Git: Remote ● Remote and Local are independent. ● Use fetch/push to get/set remote data.
  • 8. Git rebase Cut down a branch, connect to other Steps: 1. Checkout the new-base 2. Re-apply commits 3. Stop if conflict
  • 9. Git rebase -i Interactive Rebase, you can: ● Change content(edit) ● Change message(reword) ● Change order ● Combine/Split commit(squash, reset) ● Run command(exec) Extend Reading Material: http://blog.yorkxin.org/posts/2011/07/29/git-rebase/
  • 10. Git rebase !rebase 有機會竄改歷史! 在已經merge 的branch 上rebase 會怎麼樣? ➔ = = 建議千萬別這樣做..上次有人這樣 結果把分枝弄得一團亂.. ➔ 樓上..然後呢@@ ➔ 就把分枝弄得一團亂 很不方便..
  • 11. git stash ● Temporary store the changes you made. ● Useful with rebase Basic usage: stash <push, pop, list> Extend Reading Material: http://yodalee.blogspot.tw/2013/12/git-stash.html
  • 12. git format-patch, am ● git format-patch <Ref> ○ generate patches ● git am <path-to-patch> ○ Apply patches
  • 13. git bisect Find the commit that changes somthing, steps: 1. bisect start 2. Set “bisect bad”, “bisect good” 3. Keep testing; set bad or good 4. Find the commit Extend Reading Material: http://yodalee.blogspot.tw/2014/08/git-bisect.html
  • 14. git cherry-pick Pick out the change in some commit. ● -n, --no-commit: allow you edit, commit manually Not very useful, actually.
  • 15. Git inside ls * in .git: ● Object/: Data ● Refs/: Reference ● Logs/: Change to Reference ● other files Extend Reading Material: http://git-scm.com/docs/gitrepository-layout
  • 16. Git reflog ● View the list of HEAD movement. record the Hash and action ● Log when you move reference by <commit, rebase, reset, checkout> If you get the Hash, you can recover it.
  • 17. Git fsck ● Fsck check repository integrity, find dangling commits. ● Even reflog is deleted or not record, ex: git branch -D some-branch rm -Rf .git/logs/
  • 18. Git gc ● Git do 'git gc --auto' automatically, it will ○ Pack the loose files (refs->packed-refs) ○ Delete the Non-reference files.
  • 19. Git filter-branch Filter out some commits, and do some change. ex. git filter-branch --msg-filter “echo XD” branch --Change all commit message into “XD” ex. git filter-branch --index-filter “rm xxx” branch --Delete file from git repository Extend Reading Material: http://yodalee.blogspot.tw/2014/06/git-gc.html
  • 20. Git filter-branch !filter-branch 就是要更動歷史! 在已經merge 的branch 上filter-branch會怎麼 樣? ➔ = = 建議千萬別這樣做..上次有人這樣 結果把分枝弄得一團亂.. ➔ 樓上..然後呢@@ ➔ 就把分枝弄得一團亂 很不方便..
  • 21. Git useful tool Linux: gitk, gitg https://wiki.gnome.org/Apps/Gitg/ MacOS: http://gitx.frim.nl/ Windows: X! I don’t know
  • 22. The End ● Git is POWERFUL. With basic skills, it can fulfill daily requirement. ● Hope everyone can become Git Master