SlideShare a Scribd company logo
Git for absolutely
beginners
Dong-Yi Wu
2016
First of all, VCS
• VCS: Version Control System
• Keep tracking modifications over files
• Centralized Version Control Systems
• CVS, Subversion, Perforce
• Distributed Version Control Systems
• Git, Mercurial, Bazaar, Darcs
Major differences
• Centralized v.s. distributed
• everything is local
• Diff v.s. snapshot
Installation
• Mac - homebrew
• brew install git
• Windows
• Download git installer from git’s website
• Linux - package managers
• apt-get / aptitude / yum / rpm
Start working with git
• You usually start with:
• Make your own: git init
• Contains only master branch
• Work with existing project: git clone <url>
Terminology
• Working tree: the physical
working directory managed
by git
• Index: holds a snapshot of
the content of the working
tree, and it is this snapshot
that is taken as the
contents of the next
commit. Thus after making
any changes to the working
tree, and before running the
commit command, you
must use the add
command to add any new
or modified files to the
index.
• Repository: where git stores
files. All commits are
recorded by repository
https://dotblogs.com.tw/wasichris/2016/04/29/225157
Branches
• stable
• master
• stable master approach (commonly with develop branches)
• unstable master approach (accepts merges from feature/
issue and hotfix, with a stable branch)
• feature/issue
• hotfix
• wip (work in progress)
Setup identification info
• git config —global user.name “Tony Stark”
• git config —global user.email
“shh_not_ironman@stark.com”
• To configure different info for different projects, run the
previous command in the project without option —global
• To check config
• git config —list —global
• git config —list
.gitignore
• It indicates “what” shall not be tracked
• Directories
• build intermediates
• Build/Output
• build/
• Pods/
• Certain type of files
• .DS_Store, Gemfile.lock, Podfile.lock
• Comments start with pound sign(#)
add
• Add file contents to the index
• git add <paths> …
• git add .
• You may add files by regex
• git add *.sh
• -i: interactive
• Unless you have nicely composed .gitignore, using command
git add . might add files that are not suppose to be tracked
add - interactive
rm
• Remove files from the working tree and from the index
• git rm [—cached | -f] <paths>….
• git rm [—cached | -f] -r .
• —cached
• Unstages and keeps file
• -f
• Unstages and removes files
• -r
• recursive, along with .
diff
• Show changes between commits, commit and working tree, etc
• git diff
• git diff <base> <target>
• a base or a target can be a hash of a commit, a branch or a reference to a commit.
• Examples of a reference to a commit
• HEAD, HEAD~1, HEAD@{1}
• stash, stash@{1}
• master~1, master~5
• 044517c6faf3757f1f2ea4844d824bd397d488c9~1
• the commit prior the hash
diff and patch
• You may also generate patch file by:
• git diff <base> <target> > <patch_file>
• If the change involves binary files: git diff —
binary <base> <target>
• To apply the patch git apply <patch_file>, or
git apply —binary <patch_file> if the patch
contains binary diff
status
• Show the working tree status
• git status
reset
• Reset current HEAD to the specified state
• git reset [—soft | — mixed | —hard] <hash / ref>
• —soft
• reset only the repository to the specified state, preserving the content of
working tree and index/cache
• —mixed
• reset the repository and the index/cache, while preserving the content of
working tree
• —hard
• Do not preserve the information of the original commit. It resets working tree,
index/cache and the repository
revert
• Revert some existing commits
• git revert <commit/ref>
• revert a single commit
• git revert —continue
• Resolve conflicts and continue
• git revert —abort
• Abort revert
• git revert -n master~4…master~2
• Reverting from the forth latest commit of master(included) to the second
latest commit of master(included) without committing the revert(flag -n).
Resolving conflicts
• From time to time, you encounter conflicts to be
solved
• Check the blocks surrounded by conflict markers
and revise them properly
Resolving conflicts
cherry-pick
• Apply the changes introduced by some existing commits
• git cherry-pick <ref/commit>
• git cherry-pick brach~2
• git cherry-pick
00492d0a930cfc3e9a891151b62ea0d5629fc5f5
• git cherry-pick —continue
• git cherry-pick—abort
stash
• Stash the changes in a dirty working directory away
• git stash
• stash the changes
• git stash list
• show the stash list
• git stash drop [<stash>]
• Remove a single stashed state from the stash list
• stash ref is in form stash@{<revision>}
• If no <stash> is given, it removes the latest one.
• git stash clear
• Remove all stashed changes. Use with caution.
stash - cont.
• git stash pop [<stash>]
• Remove a single stashed state and apply it to the top of current working
tree state
• git stash apply [<stash>]
• Like pop, but do not remove the stash from the stash list
• git branch <branch name> [<stash>]
• Creates and checks out a new branch named <branchname> starting from
the commit at which the <stash> was originally created, applies the
changes recorded in <stash> to the new working tree and index. Then, the
stage is dropped
• If no <stash> given, the latest is applied.
commit
• Record changes to the repository
• git commit -m <your message>
• git commit —interactive
• git commit -a | —all
• automatically stage files that have been modified and
deleted, but new files you have not told Git about are not
affected.
• git commit —amend
• Amend new changes to previous commit
commit -a, —all
branch
• List, create, or delete branches
• git branch <branch name>
• Create a branch
• git branch [-r]
• list branches, with -r shows remote ones
• git [—set-upstream-to=<upstream> | -u <upstream> | unset-upstream] <branch name>
• set/remove the upstream of the branch
• git branch [-d | -D] <branch name>
• delete a branch. -D is a shortcut for ‘-d -f’
• git -m <old branch name> <new branch name>
• Rename/move a branch
checkout
• Switch branches or restore working tree files
• git checkout <branch>
• Switch to the specified branch
• git checkout — .
• Restore working tree state
• git checkout -b <branch> —track <remote>/<branch>
• Create, checkout and track a remote branch with a local branch
• git checkout [—ours | theirs] — <paths>
• —ours: apply working tree with your change
• —theirs: apply working tree with the change made by others
tag
• Create, list, delete or verify a tag object signed with GPG
• git tag -a <tag name> [-m <message>]
• light-weight tag: no -m option
• annotated tag: with -m option
• git tag -s <tag name> [-m <message>]
• similar with -a, it signs GPG signature to the tag
• git tag -l <pattern>
• list tags that matches the pattern
• e.g, git tag -l ‘v1.*’
• git tag -d <tag name>
• Delete tag with the tag name
• NOTE
• Tags are usually used to tag official release versions or milestone versions
push
• Update remote refs along with associated objects
• git push origin <local branch>
• You may need to setup upstream
pull
• Fetch from and integrate with another repository or
a local branch
• git pull
merge
• Join two or more development histories together
• git merge <branch>
• Merge <branch> into current branch
• git merge —abort
• Abort merging when you did a mess
• Merging ends with commit command
rebase
• Reapply commits on top of another base tip
• git rebase <branch>
• Rebase current branch with <branch>
• git rebase —continue
• Continue rebasing after solving conflicts
• git rebase —skip
• When rebasing encounters no changes, use this option to skip the commit
and continue rebasing
• git rebase —abort
• Abort rebasing when you messed up
Rebase or merge?
• “If you would prefer a clean, linear history free of
unnecessary merge commits, you should reach
for git rebase instead of git merge when
integrating changes from another branch.” —
Atlassian
• https://www.atlassian.com/git/tutorials/merging-vs-
rebasing/conceptual-overview
Rebase or merge?
• Rebasing tremendous amount of changes may be
difficult. Merging would be easier in this case
reflog
• Manage reflog information
• A mechanism to record when the tip of branches are updated
• You may have a chance of getting lost commits back (such as losing DETACHED
branch). It will give you the commit hashes of the mis-placed commit
• Once you got the commit hash or ref:
• git checkout <hash/ref>
• Example:
• git checkout refs/heads/master@{10}
• git checkout HEAD@{3}
• git checkout d7a4926
reflow - cont.
• git reflog
• Show reflogs
• git reflow —all
• Process the reflogs of all references
git blame
• Show what revision and author last modified each line
of a file
• git blame <path>
• Blame a single file
• git blame -L <start>, <end> <path>
• Blame a single file with a range. The simplest is
number, such as -L 1,10 (blame from line 1 to line
10)
log
• Show commit logs
• git log
• Show commit logs of current branch
• git log -S <pattern>
• you may use it to find commits of a deleted line with certain keyword
or pattern
• e.g. git log -S ‘to be deleted’
• git log —graph
• Show a text-based graphical representation of the commit history
git fetch
• Download objects and refs from another repository
• git fetch
• When you have problems of refs with your local git
repo, usually you may fix them by this command
Appendix: Rebasing a
branch pushed to remote
• git checkout <the branch>
• git pull
• get the latest changes
• git rebase <another branch>
• Resolve conflicts if any, until all changes applied
• git rebase —continue
• When you’re done with rebase, you may find you cannot push the branch. DON’T PANIC!
• git pull
• if you didn’t set upstream, set it first
• git commit

More Related Content

What's hot

01 - Git vs SVN
01 - Git vs SVN01 - Git vs SVN
01 - Git vs SVN
Edward Goikhman
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use It
Daniel Kummer
 
Introduction of Git
Introduction of GitIntroduction of Git
Introduction of GitWayne Chen
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advanced
Yodalee
 
A Brief Introduction to Working with Git
A Brief Introduction to Working with GitA Brief Introduction to Working with Git
A Brief Introduction to Working with Git
Philip Langer
 
Basic Git
Basic GitBasic Git
Basic Git
Knut Haugen
 
Git Terminologies
Git TerminologiesGit Terminologies
Git Terminologies
Yash
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails Underground
Ariejan de Vroom
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
Tagged Social
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
Jesús Miguel Benito Calzada
 
Git introduction workshop for scientists
Git introduction workshop for scientists Git introduction workshop for scientists
Git introduction workshop for scientists
Steven Hamblin
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
Gabriele Baldassarre
 
Git SCM
Git SCMGit SCM
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
Shinho Kang
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
Vikram SV
 
Undoing Things in Git
Undoing Things in GitUndoing Things in Git
Undoing Things in Git
gittower
 
Git for beginner
Git for beginnerGit for beginner
Git for beginner
Trung Huynh
 
Git vs svn
Git vs svnGit vs svn
Git vs svn
Suman Mukherjee
 
Git like a pro EDD18 - Full edition
Git like a pro EDD18 - Full editionGit like a pro EDD18 - Full edition
Git like a pro EDD18 - Full edition
Jesús Miguel Benito Calzada
 

What's hot (20)

01 - Git vs SVN
01 - Git vs SVN01 - Git vs SVN
01 - Git vs SVN
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use It
 
Introduction of Git
Introduction of GitIntroduction of Git
Introduction of Git
 
Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advanced
 
A Brief Introduction to Working with Git
A Brief Introduction to Working with GitA Brief Introduction to Working with Git
A Brief Introduction to Working with Git
 
Basic Git
Basic GitBasic Git
Basic Git
 
Git Terminologies
Git TerminologiesGit Terminologies
Git Terminologies
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails Underground
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
 
Git introduction workshop for scientists
Git introduction workshop for scientists Git introduction workshop for scientists
Git introduction workshop for scientists
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
 
Git SCM
Git SCMGit SCM
Git SCM
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Undoing Things in Git
Undoing Things in GitUndoing Things in Git
Undoing Things in Git
 
Git for beginner
Git for beginnerGit for beginner
Git for beginner
 
Git vs svn
Git vs svnGit vs svn
Git vs svn
 
Git like a pro EDD18 - Full edition
Git like a pro EDD18 - Full editionGit like a pro EDD18 - Full edition
Git like a pro EDD18 - Full edition
 
GIT_In_90_Minutes
GIT_In_90_MinutesGIT_In_90_Minutes
GIT_In_90_Minutes
 

Similar to Git

An introduction to Git
An introduction to GitAn introduction to Git
An introduction to Git
Muhil Vannan
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
dropsolid
 
Git 101
Git 101Git 101
Git 101
Sachet Mittal
 
Git basic commands
Git basic commandsGit basic commands
Git basic commands
Adarsh Konchady
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
Pranesh Vittal
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
Bimal Jain
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
Venkat Malladi
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
UshaSuray
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
Nguyen Van Hung
 
Git training v10
Git training v10Git training v10
Git training v10
Skander Hamza
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Ahmed El-Arabawy
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
Roland Emmanuel Salunga
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
Majid Hosseini
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
gdsc13
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
Nguyen Van Hung
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
Chris Johnson
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitRobert Lee-Cann
 
Source Code Management with Git
Source Code Management with GitSource Code Management with Git
Source Code Management with GitThings Lab
 
Git commands
Git commandsGit commands
Git commands
Viyaan Jhiingade
 

Similar to Git (20)

An introduction to Git
An introduction to GitAn introduction to Git
An introduction to Git
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
 
Git 101
Git 101Git 101
Git 101
 
Git basic commands
Git basic commandsGit basic commands
Git basic commands
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Git training v10
Git training v10Git training v10
Git training v10
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 
Source Code Management with Git
Source Code Management with GitSource Code Management with Git
Source Code Management with Git
 
Git commands
Git commandsGit commands
Git commands
 

Recently uploaded

basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
AIR POLLUTION lecture EnE203 updated.pdf
AIR POLLUTION lecture EnE203 updated.pdfAIR POLLUTION lecture EnE203 updated.pdf
AIR POLLUTION lecture EnE203 updated.pdf
RicletoEspinosa1
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
zwunae
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
obonagu
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 

Recently uploaded (20)

basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
AIR POLLUTION lecture EnE203 updated.pdf
AIR POLLUTION lecture EnE203 updated.pdfAIR POLLUTION lecture EnE203 updated.pdf
AIR POLLUTION lecture EnE203 updated.pdf
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 

Git

  • 2. First of all, VCS • VCS: Version Control System • Keep tracking modifications over files • Centralized Version Control Systems • CVS, Subversion, Perforce • Distributed Version Control Systems • Git, Mercurial, Bazaar, Darcs
  • 3. Major differences • Centralized v.s. distributed • everything is local • Diff v.s. snapshot
  • 4. Installation • Mac - homebrew • brew install git • Windows • Download git installer from git’s website • Linux - package managers • apt-get / aptitude / yum / rpm
  • 5. Start working with git • You usually start with: • Make your own: git init • Contains only master branch • Work with existing project: git clone <url>
  • 6. Terminology • Working tree: the physical working directory managed by git • Index: holds a snapshot of the content of the working tree, and it is this snapshot that is taken as the contents of the next commit. Thus after making any changes to the working tree, and before running the commit command, you must use the add command to add any new or modified files to the index. • Repository: where git stores files. All commits are recorded by repository https://dotblogs.com.tw/wasichris/2016/04/29/225157
  • 7. Branches • stable • master • stable master approach (commonly with develop branches) • unstable master approach (accepts merges from feature/ issue and hotfix, with a stable branch) • feature/issue • hotfix • wip (work in progress)
  • 8. Setup identification info • git config —global user.name “Tony Stark” • git config —global user.email “shh_not_ironman@stark.com” • To configure different info for different projects, run the previous command in the project without option —global • To check config • git config —list —global • git config —list
  • 9. .gitignore • It indicates “what” shall not be tracked • Directories • build intermediates • Build/Output • build/ • Pods/ • Certain type of files • .DS_Store, Gemfile.lock, Podfile.lock • Comments start with pound sign(#)
  • 10. add • Add file contents to the index • git add <paths> … • git add . • You may add files by regex • git add *.sh • -i: interactive • Unless you have nicely composed .gitignore, using command git add . might add files that are not suppose to be tracked
  • 12. rm • Remove files from the working tree and from the index • git rm [—cached | -f] <paths>…. • git rm [—cached | -f] -r . • —cached • Unstages and keeps file • -f • Unstages and removes files • -r • recursive, along with .
  • 13. diff • Show changes between commits, commit and working tree, etc • git diff • git diff <base> <target> • a base or a target can be a hash of a commit, a branch or a reference to a commit. • Examples of a reference to a commit • HEAD, HEAD~1, HEAD@{1} • stash, stash@{1} • master~1, master~5 • 044517c6faf3757f1f2ea4844d824bd397d488c9~1 • the commit prior the hash
  • 14. diff and patch • You may also generate patch file by: • git diff <base> <target> > <patch_file> • If the change involves binary files: git diff — binary <base> <target> • To apply the patch git apply <patch_file>, or git apply —binary <patch_file> if the patch contains binary diff
  • 15. status • Show the working tree status • git status
  • 16. reset • Reset current HEAD to the specified state • git reset [—soft | — mixed | —hard] <hash / ref> • —soft • reset only the repository to the specified state, preserving the content of working tree and index/cache • —mixed • reset the repository and the index/cache, while preserving the content of working tree • —hard • Do not preserve the information of the original commit. It resets working tree, index/cache and the repository
  • 17. revert • Revert some existing commits • git revert <commit/ref> • revert a single commit • git revert —continue • Resolve conflicts and continue • git revert —abort • Abort revert • git revert -n master~4…master~2 • Reverting from the forth latest commit of master(included) to the second latest commit of master(included) without committing the revert(flag -n).
  • 18. Resolving conflicts • From time to time, you encounter conflicts to be solved • Check the blocks surrounded by conflict markers and revise them properly
  • 20. cherry-pick • Apply the changes introduced by some existing commits • git cherry-pick <ref/commit> • git cherry-pick brach~2 • git cherry-pick 00492d0a930cfc3e9a891151b62ea0d5629fc5f5 • git cherry-pick —continue • git cherry-pick—abort
  • 21. stash • Stash the changes in a dirty working directory away • git stash • stash the changes • git stash list • show the stash list • git stash drop [<stash>] • Remove a single stashed state from the stash list • stash ref is in form stash@{<revision>} • If no <stash> is given, it removes the latest one. • git stash clear • Remove all stashed changes. Use with caution.
  • 22. stash - cont. • git stash pop [<stash>] • Remove a single stashed state and apply it to the top of current working tree state • git stash apply [<stash>] • Like pop, but do not remove the stash from the stash list • git branch <branch name> [<stash>] • Creates and checks out a new branch named <branchname> starting from the commit at which the <stash> was originally created, applies the changes recorded in <stash> to the new working tree and index. Then, the stage is dropped • If no <stash> given, the latest is applied.
  • 23. commit • Record changes to the repository • git commit -m <your message> • git commit —interactive • git commit -a | —all • automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected. • git commit —amend • Amend new changes to previous commit
  • 25. branch • List, create, or delete branches • git branch <branch name> • Create a branch • git branch [-r] • list branches, with -r shows remote ones • git [—set-upstream-to=<upstream> | -u <upstream> | unset-upstream] <branch name> • set/remove the upstream of the branch • git branch [-d | -D] <branch name> • delete a branch. -D is a shortcut for ‘-d -f’ • git -m <old branch name> <new branch name> • Rename/move a branch
  • 26. checkout • Switch branches or restore working tree files • git checkout <branch> • Switch to the specified branch • git checkout — . • Restore working tree state • git checkout -b <branch> —track <remote>/<branch> • Create, checkout and track a remote branch with a local branch • git checkout [—ours | theirs] — <paths> • —ours: apply working tree with your change • —theirs: apply working tree with the change made by others
  • 27. tag • Create, list, delete or verify a tag object signed with GPG • git tag -a <tag name> [-m <message>] • light-weight tag: no -m option • annotated tag: with -m option • git tag -s <tag name> [-m <message>] • similar with -a, it signs GPG signature to the tag • git tag -l <pattern> • list tags that matches the pattern • e.g, git tag -l ‘v1.*’ • git tag -d <tag name> • Delete tag with the tag name • NOTE • Tags are usually used to tag official release versions or milestone versions
  • 28. push • Update remote refs along with associated objects • git push origin <local branch> • You may need to setup upstream
  • 29. pull • Fetch from and integrate with another repository or a local branch • git pull
  • 30. merge • Join two or more development histories together • git merge <branch> • Merge <branch> into current branch • git merge —abort • Abort merging when you did a mess • Merging ends with commit command
  • 31. rebase • Reapply commits on top of another base tip • git rebase <branch> • Rebase current branch with <branch> • git rebase —continue • Continue rebasing after solving conflicts • git rebase —skip • When rebasing encounters no changes, use this option to skip the commit and continue rebasing • git rebase —abort • Abort rebasing when you messed up
  • 32. Rebase or merge? • “If you would prefer a clean, linear history free of unnecessary merge commits, you should reach for git rebase instead of git merge when integrating changes from another branch.” — Atlassian • https://www.atlassian.com/git/tutorials/merging-vs- rebasing/conceptual-overview
  • 33. Rebase or merge? • Rebasing tremendous amount of changes may be difficult. Merging would be easier in this case
  • 34. reflog • Manage reflog information • A mechanism to record when the tip of branches are updated • You may have a chance of getting lost commits back (such as losing DETACHED branch). It will give you the commit hashes of the mis-placed commit • Once you got the commit hash or ref: • git checkout <hash/ref> • Example: • git checkout refs/heads/master@{10} • git checkout HEAD@{3} • git checkout d7a4926
  • 35. reflow - cont. • git reflog • Show reflogs • git reflow —all • Process the reflogs of all references
  • 36. git blame • Show what revision and author last modified each line of a file • git blame <path> • Blame a single file • git blame -L <start>, <end> <path> • Blame a single file with a range. The simplest is number, such as -L 1,10 (blame from line 1 to line 10)
  • 37. log • Show commit logs • git log • Show commit logs of current branch • git log -S <pattern> • you may use it to find commits of a deleted line with certain keyword or pattern • e.g. git log -S ‘to be deleted’ • git log —graph • Show a text-based graphical representation of the commit history
  • 38. git fetch • Download objects and refs from another repository • git fetch • When you have problems of refs with your local git repo, usually you may fix them by this command
  • 39. Appendix: Rebasing a branch pushed to remote • git checkout <the branch> • git pull • get the latest changes • git rebase <another branch> • Resolve conflicts if any, until all changes applied • git rebase —continue • When you’re done with rebase, you may find you cannot push the branch. DON’T PANIC! • git pull • if you didn’t set upstream, set it first • git commit