1
© 2016 Brent Laster
1
© 2016 Brent Laster@BrentCLaster
Advanced Git:Functionality and Features
Open Source 101 ConferenceFebruary 4, 2017
Brent Laster (author of Professional Git)
2
© 2016 Brent Laster
2
@BrentCLaster
About me
Senior Manager, R&D at SAS in Cary, NC Global Trainer and Speaker Git, Gerrit, Gradle, Jenkins, Pipelines Author - NFJS magazine, Professional Git book LinkedIn https://www.linkedin.com/in/brentlaster Twitter @BrentCLaster
3
© 2016 Brent Laster
3
@BrentCLaster
Professional Git
Available on: Amazon.com Wiley.com
4
© 2016 Brent Laster
4
@BrentCLaster
Agenda Core concepts refresh Merging and Rebasing Stash Reset and Revert Rerere Bisect Worktrees Submodules Subtrees Interactive Rebase Notes Grep
5
© 2016 Brent Laster
Check Out
CommitChekout
Checkout
Commit
Clone
Remote Repository
Local Environment
Central Server
Local Machine
Centralized Version Control Model Distributed Version Control Model
Centralized vs. Distributed VCS
6
© 2016 Brent Laster
6
@BrentCLaster
Git in One Picture
Dev
Prod
Public
Test
7
© 2016 Brent Laster
7
@BrentCLaster
Git in One Picture
Working DirectoryDev
Prod
Public
Test
8
© 2016 Brent Laster
8
@BrentCLaster
Git in One Picture
Staging Area
Working DirectoryDev
Prod
Public
Test
9
© 2016 Brent Laster
9
@BrentCLaster
Git in One Picture
Staging Area
Local Repository
Working DirectoryDev
Prod
Public
Test
10
© 2016 Brent Laster
10
@BrentCLaster
Git in One Picture
Staging Area
Local Repository
Working DirectoryDev
Prod
Public
Test
11
© 2016 Brent Laster
11
@BrentCLaster
Git in One Picture
Staging Area
Local Repository
Working DirectoryDev
Prod
Public
Test
Local Machine
12
© 2016 Brent Laster
12
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Local Machine
13
© 2016 Brent Laster
13
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Local Machine
14
© 2016 Brent Laster
14
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Server
Local Machine
15
© 2016 Brent Laster
15
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Server
Local Machine
16
© 2016 Brent Laster
16
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Server
Add
Local Machine
17
© 2016 Brent Laster
17
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Server
Add
Local Machine
18
© 2016 Brent Laster
18
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Server
Add
Commit
Local Machine
19
© 2016 Brent Laster
19
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Server
Add
Commit
Local Machine
20
© 2016 Brent Laster
20
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Checkout
Server
Add
Commit
Local Machine
21
© 2016 Brent Laster
21
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Checkout
Server
Add
Commit
Local Machine
22
© 2016 Brent Laster
22
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Checkout
Server
Add
Commit
Push
Local Machine
23
© 2016 Brent Laster
23
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Checkout
Server
Add
Commit
Push
Local Machine
24
© 2016 Brent Laster
24
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Checkout
Server
Add
Commit
Push Clone
Local Machine
25
© 2016 Brent Laster
25
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Checkout
Server
Add
Commit
Push Clone
Local Machine
26
© 2016 Brent Laster
26
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Checkout
Server
Add
Commit
Push Clone
Local Machine
Fetch
27
© 2016 Brent Laster
27
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Checkout
Server
Add
Commit
Push Clone
Local Machine
Fetch
28
© 2016 Brent Laster
28
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working Directory
Pull
Dev
Prod
Public
Test
Checkout
Server
Add
Commit
Push Clone
Local Machine
Fetch
29
© 2016 Brent Laster
29
@BrentCLaster
Git Granularity (What is a unit?)
30
© 2016 Brent Laster
30
@BrentCLaster
Git Granularity (What is a unit?)
In traditional source control, the unit of granularity is usually a file
31
© 2016 Brent Laster
31
@BrentCLaster
Git Granularity (What is a unit?)
In traditional source control, the unit of granularity is usually a file
file1.javafile1.java
32
© 2016 Brent Laster
32
@BrentCLaster
Git Granularity (What is a unit?)
In traditional source control, the unit of granularity is usually a file
file1.java
CVS
file1.java
33
© 2016 Brent Laster
33
@BrentCLaster
Git Granularity (What is a unit?)
In traditional source control, the unit of granularity is usually a file
file1.java
CVS
file1.javaDelta
34
© 2016 Brent Laster
34
@BrentCLaster
Git Granularity (What is a unit?)
In traditional source control, the unit of granularity is usually a file
In Git, the unit of granularity is usually a tree
file1.java
CVS
file1.javaDelta
35
© 2016 Brent Laster
35
@BrentCLaster
Git Granularity (What is a unit?)
In traditional source control, the unit of granularity is usually a file
In Git, the unit of granularity is usually a tree
dir: proj1
file1.java
file2.java
Working directory
file1.java
CVS
file1.javaDelta
36
© 2016 Brent Laster
36
@BrentCLaster
Git Granularity (What is a unit?)
In traditional source control, the unit of granularity is usually a file
In Git, the unit of granularity is usually a tree
dir: proj1
file1.java
file2.java
Working directory
file1.java
CVS
file1.javaDelta
37
© 2016 Brent Laster
37
@BrentCLaster
Git Granularity (What is a unit?)
In traditional source control, the unit of granularity is usually a file
In Git, the unit of granularity is usually a tree
dir: proj1
file1.java
file2.java
Working directory
file1.java
CVS
Git Commit
file1.javaDelta
38
© 2016 Brent Laster
38
@BrentCLaster
Git Granularity (What is a unit?)
In traditional source control, the unit of granularity is usually a file
In Git, the unit of granularity is usually a tree
dir: proj1
file1.java
file2.java
Working directory
file1.java
CVS
Git Commit
file1.javaDelta
39
© 2016 Brent Laster
39
@BrentCLaster
Git Granularity (What is a unit?)
In traditional source control, the unit of granularity is usually a file
In Git, the unit of granularity is usually a tree
dir: proj1
file1.java
file2.java
Working directory
file1.java
CVS
Git
file1.javaDelta
Commit
Snapshot
40
© 2016 Brent Laster
40
@BrentCLaster
Merging: What is a Fast-forward?
Assume you have three branches as below You want to merge hotfix into master (so master will
have your hotfix for future development)
C2
C3
C0 C1 C4
feature
hotfix
41
© 2016 Brent Laster
41
@BrentCLaster
Merging: What is a Fast-forward?
Assume you have three branches as below You want to merge hotfix into master (so master will
have your hotfix for future development)$ git checkout master
C2
C3
C0 C1 C4
feature
hotfix
42
© 2016 Brent Laster
42
@BrentCLaster
Merging: What is a Fast-forward?
Assume you have three branches as below You want to merge hotfix into master (so master will
have your hotfix for future development)$ git checkout master$ git merge hotfix
C2
C3
C0 C1 C4
feature
hotfix
43
© 2016 Brent Laster
43
@BrentCLaster
Merging: What is a Fast-forward?
Assume you have three branches as below You want to merge hotfix into master (so master will
have your hotfix for future development)$ git checkout master$ git merge hotfixUpdating f42c576..3a0874cFast ForwardREADME | 1-1 files changed, 0 insertions(+) 1 deletions (-)
C2
C3
C0 C1 C4
feature
hotfix
44
© 2016 Brent Laster
44
@BrentCLaster
Merging: What is a Fast-forward?
Assume you have three branches as below You want to merge hotfix into master (so master will
have your hotfix for future development)$ git checkout master$ git merge hotfixUpdating f42c576..3a0874cFast ForwardREADME | 1-1 files changed, 0 insertions(+) 1 deletions (-)
About “Fast Forward” – because commit pointed to by branch merged was directly “upstream” of the current commit, Git moves the pointer forward
C2
C3
C0 C1 C4
feature
hotfix
45
© 2016 Brent Laster
45
@BrentCLaster
Merging: What is a Fast-forward?
Assume you have three branches as below You want to merge hotfix into master (so master will
have your hotfix for future development)$ git checkout master$ git merge hotfixUpdating f42c576..3a0874cFast ForwardREADME | 1-1 files changed, 0 insertions(+) 1 deletions (-)
About “Fast Forward” – because commit pointed to by branch merged was directly “upstream” of the current commit, Git moves the pointer forward
(Both branches were in the same line of development, so the net result is that master and hotfix point to the same commit)
C2
C3
C0 C1 C4
feature
hotfix
46
© 2016 Brent Laster
46
@BrentCLaster
Assume branching scenario below
Merging: What is a 3-way Merge?
C2
C3
C4
C5
feature
C0 C1
Common Ancestor
Branch Tip
Branch Tip
master
47
© 2016 Brent Laster
47
@BrentCLaster
Assume branching scenario below master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot)
Merging: What is a 3-way Merge?
C2
C3
C4
C5
feature
C0 C1
Common Ancestor
Branch Tip
Branch Tip
master
48
© 2016 Brent Laster
48
@BrentCLaster
Assume branching scenario below master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot) Intent is to change to master and merge in feature
Merging: What is a 3-way Merge?
C2
C3
C4
C5
feature
C0 C1
Common Ancestor
Branch Tip
Branch Tip
master
49
© 2016 Brent Laster
49
@BrentCLaster
Assume branching scenario below master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot) Intent is to change to master and merge in feature Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)
Merging: What is a 3-way Merge?
C2
C3
C4
C5
feature
C0 C1
Common Ancestor
Branch Tip
Branch Tip
master
50
© 2016 Brent Laster
50
@BrentCLaster
Assume branching scenario below master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot) Intent is to change to master and merge in feature Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5) Git does 3-way merge using common ancestor
Merging: What is a 3-way Merge?
C2
C3
C4
C5
feature
C0 C1
Common Ancestor
Branch Tip
Branch Tip
master
51
© 2016 Brent Laster
51
@BrentCLaster
Assume branching scenario below master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot) Intent is to change to master and merge in feature Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5) Git does 3-way merge using common ancestor
Merging: What is a 3-way Merge?
$ git checkout master
C2
C3
C4
C5
feature
C0 C1
Common Ancestor
Branch Tip
Branch Tip
master
52
© 2016 Brent Laster
52
@BrentCLaster
Assume branching scenario below master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot) Intent is to change to master and merge in feature Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5) Git does 3-way merge using common ancestor
Merging: What is a 3-way Merge?
$ git checkout master$ git merge feature
C2
C3
C4
C5
feature
C0 C1
Common Ancestor
Branch Tip
Branch Tip
master
53
© 2016 Brent Laster
53
@BrentCLaster
Assume branching scenario below master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot) Intent is to change to master and merge in feature Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5) Git does 3-way merge using common ancestor
Merging: What is a 3-way Merge?
$ git checkout master$ git merge feature
C2
C3
C4
C5
feature
C0 C1
Common Ancestor
Branch Tip
Branch Tip
master
54
© 2016 Brent Laster
54
@BrentCLaster
Assume branching scenario below master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot) Intent is to change to master and merge in feature Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5) Git does 3-way merge using common ancestor
Merging: What is a 3-way Merge?
$ git checkout master$ git merge feature
C2
C3
C4
C5
feature
C0 C1
Common Ancestor
Branch Tip
Branch Tip
master
55
© 2016 Brent Laster
55
@BrentCLaster
Assume branching scenario below master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot) Intent is to change to master and merge in feature Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5) Git does 3-way merge using common ancestor
Merging: What is a 3-way Merge?
$ git checkout master$ git merge feature
C2
C3
C4
C5
feature
C0 C1
Common Ancestor
Branch Tip
Branch Tip
master
56
© 2016 Brent Laster
56
@BrentCLaster
Assume branching scenario below master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot) Intent is to change to master and merge in feature Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5) Git does 3-way merge using common ancestor Instead of just moving branch pointer forward, Git creates a new snapshot and
a new commit that points to it called a “merge commit”
Merging: What is a 3-way Merge?
$ git checkout master$ git merge feature
C2
C3
C4
C5
feature
C0 C1
Common Ancestor
Branch Tip
Branch Tip
master
57
© 2016 Brent Laster
57
@BrentCLaster
Merging: What is a Rebase?
C3
C4
C5
C0
Common Ancestor
C2
feature
C1
master
58
© 2016 Brent Laster
58
@BrentCLaster
Merging: What is a Rebase? Rebase – take all of the changes that were committed on one branch and replay
them on another one.
C3
C4
C5
C0
Common Ancestor
C2
feature
C1
master
59
© 2016 Brent Laster
59
@BrentCLaster
Merging: What is a Rebase? Rebase – take all of the changes that were committed on one branch and replay
them on another one. Concepts in simple syntax (git rebase branch2 [branch1]):
C3
C4
C5
C0
Common Ancestor
C2
feature
C1
master
60
© 2016 Brent Laster
60
@BrentCLaster
Merging: What is a Rebase? Rebase – take all of the changes that were committed on one branch and replay
them on another one. Concepts in simple syntax (git rebase branch2 [branch1]):
Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)
C3
C4
C5
C0
Common Ancestor
C2
feature
C1
master
61
© 2016 Brent Laster
61
@BrentCLaster
Merging: What is a Rebase? Rebase – take all of the changes that were committed on one branch and replay
them on another one. Concepts in simple syntax (git rebase branch2 [branch1]):
Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base) Current branch (or branch1 if supplied) is one having its branchpoint moved
C3
C4
C5
C0
Common Ancestor
C2
feature
C1
master
62
© 2016 Brent Laster
62
@BrentCLaster
Merging: What is a Rebase? Rebase – take all of the changes that were committed on one branch and replay
them on another one. Concepts in simple syntax (git rebase branch2 [branch1]):
Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base) Current branch (or branch1 if supplied) is one having its branchpoint moved Branch2 (or commit) provided as first/only argument is the new branchpoint
C3
C4
C5
C0
Common Ancestor
C2
feature
C1
master
63
© 2016 Brent Laster
63
@BrentCLaster
Merging: What is a Rebase? Rebase – take all of the changes that were committed on one branch and replay
them on another one. Concepts in simple syntax (git rebase branch2 [branch1]):
Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base) Current branch (or branch1 if supplied) is one having its branchpoint moved Branch2 (or commit) provided as first/only argument is the new branchpoint In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
C3
C4
C5
C0
Common Ancestor
C2
feature
C1
master
64
© 2016 Brent Laster
64
@BrentCLaster
Merging: What is a Rebase? Rebase – take all of the changes that were committed on one branch and replay
them on another one. Concepts in simple syntax (git rebase branch2 [branch1]):
Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base) Current branch (or branch1 if supplied) is one having its branchpoint moved Branch2 (or commit) provided as first/only argument is the new branchpoint In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
Process:
C3
C4
C5
C0
Common Ancestor
C2
feature
C1
master
65
© 2016 Brent Laster
65
@BrentCLaster
Merging: What is a Rebase? Rebase – take all of the changes that were committed on one branch and replay
them on another one. Concepts in simple syntax (git rebase branch2 [branch1]):
Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base) Current branch (or branch1 if supplied) is one having its branchpoint moved Branch2 (or commit) provided as first/only argument is the new branchpoint In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
Process:
$ git checkout feature$ git rebase master
C3
C4
C5
C0
Common Ancestor
C2
feature
C1
master
66
© 2016 Brent Laster
66
@BrentCLaster
Merging: What is a Rebase? Rebase – take all of the changes that were committed on one branch and replay
them on another one. Concepts in simple syntax (git rebase branch2 [branch1]):
Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base) Current branch (or branch1 if supplied) is one having its branchpoint moved Branch2 (or commit) provided as first/only argument is the new branchpoint In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
Process: Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing
onto)
$ git checkout feature$ git rebase master
C3
C4
C5
C0
Common Ancestor
C2
feature
C1 C2
master
67
© 2016 Brent Laster
67
@BrentCLaster
Merging: What is a Rebase? Rebase – take all of the changes that were committed on one branch and replay
them on another one. Concepts in simple syntax (git rebase branch2 [branch1]):
Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base) Current branch (or branch1 if supplied) is one having its branchpoint moved Branch2 (or commit) provided as first/only argument is the new branchpoint In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
Process: Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing
onto) Gets the diff introduced by each commit of the branch you are on, saving them to temporary files
$ git checkout feature$ git rebase master
C3
C4
C5
C0
Common Ancestor
C2
feature
C1 C2
master
68
© 2016 Brent Laster
68
@BrentCLaster
Merging: What is a Rebase? Rebase – take all of the changes that were committed on one branch and replay
them on another one. Concepts in simple syntax (git rebase branch2 [branch1]):
Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base) Current branch (or branch1 if supplied) is one having its branchpoint moved Branch2 (or commit) provided as first/only argument is the new branchpoint In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
Process: Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing
onto) Gets the diff introduced by each commit of the branch you are on, saving them to temporary files Applies each change in turn
$ git checkout feature$ git rebase master
C3
C4
C5
C0
Common Ancestor
C2
feature
C1 C3’ C5’C2
master
69
© 2016 Brent Laster
69
@BrentCLaster
Merging: What is a Rebase? Rebase – take all of the changes that were committed on one branch and replay
them on another one. Concepts in simple syntax (git rebase branch2 [branch1]):
Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base) Current branch (or branch1 if supplied) is one having its branchpoint moved Branch2 (or commit) provided as first/only argument is the new branchpoint In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
Process: Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing
onto) Gets the diff introduced by each commit of the branch you are on, saving them to temporary files Applies each change in turn Moves the branch to the new rebase point
$ git checkout feature$ git rebase master
C3
C4
C5
C0
Common Ancestor
C2
feature
C1 C3’ C5’C2
master
70
© 2016 Brent Laster
70
@BrentCLaster
Merging: What is a Rebase? Rebase – take all of the changes that were committed on one branch and replay
them on another one. Concepts in simple syntax (git rebase branch2 [branch1]):
Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base) Current branch (or branch1 if supplied) is one having its branchpoint moved Branch2 (or commit) provided as first/only argument is the new branchpoint In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
Process: Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing
onto) Gets the diff introduced by each commit of the branch you are on, saving them to temporary files Applies each change in turn Moves the branch to the new rebase point
$ git checkout feature$ git rebase master
C3
C4
C5
C0
Common Ancestor
C2
feature
C1 C3’ C5’C2
master
71
© 2016 Brent Laster
71
@BrentCLaster
Command: Git Stash Purpose -- allow you to keep a backup copy of your work
that hasn’t been committed yet Use case - you want to switch branches but don’t want
to lose work that hasn’t been committed; you want to save something you’ve tried and may want to come back to
Syntax:
72
© 2016 Brent Laster
72
@BrentCLaster
Stash
73
© 2016 Brent Laster
73
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
74
© 2016 Brent Laster
74
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory*
75
© 2016 Brent Laster
75
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory*
*
76
© 2016 Brent Laster
76
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory*
*
> git stash
77
© 2016 Brent Laster
77
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory*
*
> git stash
78
© 2016 Brent Laster
78
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
stash@{0}
Staging Area *
Working Directory *
stash@{0}
> git stash
79
© 2016 Brent Laster
79
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
stash@{0}
Staging Area *
Working Directory *
**
stash@{0}
> git stash
80
© 2016 Brent Laster
80
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
stash@{0}
Staging Area *
Working Directory *
**
**
stash@{0}
> git stash
81
© 2016 Brent Laster
81
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
stash@{0}
Staging Area *
Working Directory *
**
**
stash@{0}
> git stash
#
82
© 2016 Brent Laster
82
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
stash@{0}
Staging Area *
Working Directory *
**
**
stash@{0}
> git stash > git stash -u
#
83
© 2016 Brent Laster
83
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
stash@{0}
Staging Area *
Working Directory *
stash@{1}Staging Area **
Working Directory
**#
stash@{0}
stash@{0}
stash@{1}
> git stash -u
84
© 2016 Brent Laster
84
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
stash@{0}
Staging Area *
Working Directory *
stash@{1}Staging Area **
Working Directory
**#
***
stash@{0}
stash@{0}
stash@{1}
> git stash -u
85
© 2016 Brent Laster
85
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
stash@{0}
Staging Area *
Working Directory *
stash@{1}Staging Area **
Working Directory
**#
***
***
stash@{0}
stash@{0}
stash@{1}
> git stash -u
86
© 2016 Brent Laster
86
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
stash@{0}
Staging Area *
Working Directory *
stash@{1}Staging Area **
Working Directory
**#
***
***
stash@{0}
stash@{0}
stash@{1}
> git stash save “cool feature”
87
© 2016 Brent Laster
87
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
stash@{0}
Staging Area *
Working Directory *
stash@{1}Staging Area **
Working Directory
**#
stash@{0}Staging Area ***
stash@{2}
stash@{1}
stash@{0}
stash@{0}stash@{1}
stash@{1}stash@{2}
“cool feature”
Working Directory
***
88
© 2016 Brent Laster
88
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
stash@{0}
Staging Area *
Working Directory *
stash@{1}Staging Area **
Working Directory
**#
stash@{0}Staging Area ***
stash@{2}
stash@{1}
stash@{0}
stash@{0}stash@{1}
stash@{1}stash@{2}
“cool feature”
Working Directory
***
> git stash apply stash@{1}
89
© 2016 Brent Laster
89
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
stash@{0}
Staging Area *
Working Directory *
stash@{1}Staging Area **
Working Directory
**#
stash@{0}Staging Area ***
stash@{2}
**
**
stash@{1}
stash@{0}
stash@{0}stash@{1}
stash@{1}stash@{2}
“cool feature”
Working Directory
*** #
> git stash apply stash@{1}
90
© 2016 Brent Laster
90
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
stash@{0}
Staging Area *
Working Directory *
stash@{1}Staging Area **
Working Directory
**#
stash@{0}Staging Area ***
stash@{2}
**
**
stash@{1}
stash@{0}
stash@{0}stash@{1}
stash@{1}stash@{2}
“cool feature”
Working Directory
*** #
$ git stash pop stash@{2}
91
© 2016 Brent Laster
91
@BrentCLaster
Stash
Staging AreaStaging Area
Local Repository
Working Directory
Staging Area *
Working Directory *
stash@{1}Staging Area **
Working Directory
**#
stash@{0}Staging Area ***
***
***
stash@{0}stash@{1}
“cool feature”
Working Directory
*** #
$ git stash pop stash@{2}
92
© 2016 Brent Laster
92
@BrentCLaster
Command: Git Reset Purpose -- allow you to “roll back” so that your branch
points at a previous commit ; optionally also update staging area and working directory to that commit
Use case - you want to update your local environment back to a previous point in time; you want to overwrite or a local change you’ve made
Syntax:
Warning: --hard overwrites everything
93
© 2016 Brent Laster
93
@BrentCLaster
Command: Git Revert Purpose -- allow you to “undo” by adding a new change
that cancels out effects of previous one Use case - you want to cancel out a previous change but
not roll things back Syntax:
Note: The net result of using this command vs. reset can be the same. If so, and content that is being reset/revert has been pushed such that others may be consuming it, preference is for revert.
94
© 2016 Brent Laster
94
@BrentCLaster
Local Repository
Reset and Revert
Line 1
Staging Area
Working Directory
XYZ
ABC
Line 1
87ba8bc 43bd3ef d21be2c
Line 1Line 2Line 3
Line 1Line 2Line 1Line 1 Line 1Line 2
tag: current
95
© 2016 Brent Laster
95
@BrentCLaster
Local Repository
git reset --hard 87ba8bc
Reset and Revert
Line 1
Staging Area
Working Directory
XYZ
ABC
Line 1
87ba8bc 43bd3ef d21be2c
Line 1Line 2Line 3
Line 1Line 2
Line 1
Line 1 Line 1Line 2
tag: current
96
© 2016 Brent Laster
96
@BrentCLaster
Local Repository
git reset --hard 87ba8bc
Reset and Revert
Line 1
Staging Area
Working Directory
XYZ
ABC
Line 1
87ba8bc 43bd3ef d21be2c
Line 1Line 2Line 3
Line 1Line 2
Line 1
Line 1 Line 1Line 2
tag: current
97
© 2016 Brent Laster
97
@BrentCLaster
Local Repository
git reset current~1 [--mixed]
Reset and Revert
Line 1
Staging Area
Working Directory
XYZ
ABC
Line 1
87ba8bc 43bd3ef d21be2c
Line 1Line 2Line 3
Line 1Line 2
Line 1
Line 1 Line 1Line 2
tag: current
98
© 2016 Brent Laster
98
@BrentCLaster
Local Repository
git reset current~1 [--mixed]
Reset and Revert
Line 1
Staging Area
Working Directory
87ba8bc 43bd3ef d21be2c
Line 1Line 2Line 3
Line 1 Line 1Line 2
tag: current
99
© 2016 Brent Laster
99
@BrentCLaster
Local Repository
git revert HEAD~1
Reset and Revert
Line 1
Staging Area
Working Directory
87ba8bc 43bd3ef d21be2c
Line 1Line 2Line 3
Line 1Line 2
Line 1 Line 1Line 2
tag: current
100
© 2016 Brent Laster
100
@BrentCLaster
Local Repository
git revert HEAD~1
Reset and Revert
Line 1
Staging Area
Working Directory
87ba8bc 43bd3ef d21be2c
Line 1Line 2Line 3
c1c8bd4
Line 1Line 2
Line 1 Line 1Line 2
tag: current
101
© 2016 Brent Laster
101
@BrentCLaster
Local Repository
Reset and Revert
Line 1
Staging Area
Working Directory
87ba8bc 43bd3ef d21be2c
Line 1Line 2Line 3
c1c8bd4
Line 1Line 2
Line 1 Line 1Line 2
tag: current
102
© 2016 Brent Laster
102
@BrentCLaster
Command: Git Rerere (Reuse Recorded Resolution) Purpose -- allows recording of how you solve a merge
situation and then can automatically resolve the same situation in the same way if needed later
Use case - trial and repeated merges; merging newer versions of a branch with the same conflicts into a newer one periodically; resolve conflicts after reset or revert; applicable to any repeated merge case: rebase, merge
Syntax: Note: This is a “state” command. Enabled by turning on
a state in Git, rather than just running a command Enabled via git config --global rerere.enabled 1
» Then runs automatically Invoked directly via git rerere for related commands or options
103
© 2016 Brent Laster
103
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File BFile B
File A File C
Git Rerere 1
104
© 2016 Brent Laster
104
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master
File C
File A
File B
master
File A
File C
File B
File A
File C
File BFile B
File A File C
Git Rerere 1
105
© 2016 Brent Laster
105
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1
File C
File A
File B
master
File A
File C
File B
File A
File C
File BFile B
File A File C
rr-cacheGit Rerere 1
106
© 2016 Brent Laster
106
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1$ git merge feature
File C
File A
File B
master
File A
File C
File B
File A
File C
X
File A File C
rr-cacheGit Rerere 1
107
© 2016 Brent Laster
107
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1$ git merge feature
File C
File A
File B
master
File A
File C
File B
File A
File C
File B<<>>
File A File CFile A File C
rr-cacheGit Rerere 1
108
© 2016 Brent Laster
108
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1$ git merge feature
File C
File A
File B
master
File A
File C
File B
File A
File C
File B<<>>
File A File CFile A File C
rr-cache
File A File C
Git Rerere 1
109
© 2016 Brent Laster
109
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1$ git merge feature
File C
File A
File B
master
File A
File C
File B
File A
File C
File B<<>>
File A File CFile A File C
rr-cache
File A File C
File B<<>>
preimageGit Rerere 1
110
© 2016 Brent Laster
110
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1$ git merge feature Recorded preimage for ‘File B’
File C
File A
File B
master
File A
File C
File B
File A
File C
File B<<>>
File A File CFile A File C
rr-cache
File A File C
File B<<>>
preimageGit Rerere 1
111
© 2016 Brent Laster
111
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1$ git merge feature Recorded preimage for ‘File B’$ git status
Changes to be committed:modified: File Amodified: File C
Unmerged pathsboth modified: File B
File C
File A
File B
master
File A
File C
File B
File A
File C
File B<<>>
File A File CFile A File C
rr-cache
File A File C
File B<<>>
preimageGit Rerere 1
112
© 2016 Brent Laster
112
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1$ git merge feature Recorded preimage for ‘File B’$ git status
Changes to be committed:modified: File Amodified: File C
Unmerged pathsboth modified: File B
[fix conflicts]
File C
File A
File B
master
File A
File C
File B
File A
File C
File B<<>>File B
File A File CFile A File C
rr-cache
File A File C
File B<<>>
preimageGit Rerere 1
113
© 2016 Brent Laster
113
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1$ git merge feature Recorded preimage for ‘File B’$ git status
Changes to be committed:modified: File Amodified: File C
Unmerged pathsboth modified: File B
[fix conflicts]$ git add .
File C
File A
File B
master
File A
File C
File B
File A
File C
File B
File A File CFile BFile A File C
rr-cache
File A File C
File B<<>>
preimageGit Rerere 1
114
© 2016 Brent Laster
114
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1$ git merge feature Recorded preimage for ‘File B’$ git status
Changes to be committed:modified: File Amodified: File C
Unmerged pathsboth modified: File B
[fix conflicts]$ git add . $ git commit –m “finalize merge”
File C
File A
File B
master
File A
File C
File B
File A
File C
File A File C
File B
File A File C
rr-cache
File A File C
File B<<>>
preimageGit Rerere 1
115
© 2016 Brent Laster
115
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1$ git merge feature Recorded preimage for ‘File B’$ git status
Changes to be committed:modified: File Amodified: File C
Unmerged pathsboth modified: File B
[fix conflicts]$ git add . $ git commit –m “finalize merge”
File C
File A
File B
master
File A
File C
File B
File A
File C
File A File C
File B
File A File C
rr-cache
File A File C
File B<<>>
preimage postimageGit Rerere 1
116
© 2016 Brent Laster
116
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1$ git merge feature Recorded preimage for ‘File B’$ git status
Changes to be committed:modified: File Amodified: File C
Unmerged pathsboth modified: File B
[fix conflicts]$ git add . $ git commit –m “finalize merge”
File C
File A
File B
master
File A
File C
File B
File A
File C
File A File C
File B
File A File C
rr-cache
File A File C
File B<<>>
preimage postimage
File BGit Rerere 1
117
© 2016 Brent Laster
117
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1$ git merge feature Recorded preimage for ‘File B’$ git status
Changes to be committed:modified: File Amodified: File C
Unmerged pathsboth modified: File B
[fix conflicts]$ git add . $ git commit –m “finalize merge” Recorded resolution for ‘File B’
File C
File A
File B
master
File A
File C
File B
File A
File C
File A File C
File B
File A File C
rr-cache
File A File C
File B<<>>
preimage postimage
File BGit Rerere 1
118
© 2016 Brent Laster
118
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git checkout master$ git config --global rerere.enabled 1$ git merge feature Recorded preimage for ‘File B’$ git status
Changes to be committed:modified: File Amodified: File C
Unmerged pathsboth modified: File B
[fix conflicts]$ git add . $ git commit –m “finalize merge” Recorded resolution for ‘File B’
File C
File A
File B
master
File A
File C
File B
File A
File C
File A File C
File B
File A File C
rr-cache
File A File C
File B<<>>
preimage postimage
File BGit Rerere 1
119
© 2016 Brent Laster
119
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git reset --hard HEAD~1
File C
File A
File B
master
File A
File C
File B
File A
File C
File BFile B
File A File C
rr-cacheFile B<<>>
preimage postimage
File BGit Rerere 2
120
© 2016 Brent Laster
120
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git reset --hard HEAD~1$ git checkout master
File C
File A
File B
master
File A
File C
File B
File A
File C
File BFile B
File A File C
rr-cacheFile B<<>>
preimage postimage
File BGit Rerere 2
121
© 2016 Brent Laster
121
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git reset --hard HEAD~1$ git checkout master$ git merge feature Merge conflict in ‘File B’
File C
File A
File B
master
File A
File C
File B
File A
File C
File B<<>>
File A File CFile A File C
rr-cache
File A File C
File B<<>>
preimage postimage
File BGit Rerere 2
122
© 2016 Brent Laster
122
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
$ git reset --hard HEAD~1$ git checkout master$ git merge feature Merge conflict in ‘File B’ Resolved ‘File B’ using previous resolution
File C
File A
File B
master
File A
File C
File B
File A
File C
File A File C
File B
File A File C
rr-cache
File A File C
File B<<>>
preimage postimage
File BGit Rerere 2
123
© 2016 Brent Laster
123
@BrentCLaster
Command: Bisect Purpose - Use “automated” binary search through Git’s history to find a
specific commit that first introduced a problem (i.e. “first bad commit”) Use case - Quickly locate the commit in Git’s history that introduced a
bug Syntax:
124
© 2016 Brent Laster
124
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
125
© 2016 Brent Laster
125
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
checkout latest version
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
126
© 2016 Brent Laster
126
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
checkout latest version
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
127
© 2016 Brent Laster
127
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
checkout latest version try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
128
© 2016 Brent Laster
128
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
checkout latest version try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
129
© 2016 Brent Laster
129
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
checkout latest version try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
130
© 2016 Brent Laster
130
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
checkout latest version try code git bisect start
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
131
© 2016 Brent Laster
131
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
checkout latest version try code git bisect start git bisect bad
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
132
© 2016 Brent Laster
132
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
133
© 2016 Brent Laster
133
@BrentCLaster
LOCAL REPOSITORY
Version 1
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
134
© 2016 Brent Laster
134
@BrentCLaster
LOCAL REPOSITORY
Version 1
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
135
© 2016 Brent Laster
135
@BrentCLaster
LOCAL REPOSITORY
Version 1
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
136
© 2016 Brent Laster
136
@BrentCLaster
LOCAL REPOSITORY
Version 1
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
137
© 2016 Brent Laster
137
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
138
© 2016 Brent Laster
138
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5) try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
139
© 2016 Brent Laster
139
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5) try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
140
© 2016 Brent Laster
140
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5) try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
141
© 2016 Brent Laster
141
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5) try code git bisect good (bisect checks out version 7)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 7
Version 6
WORKING DIRECTORY
142
© 2016 Brent Laster
142
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5) try code git bisect good (bisect checks out version 7) try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 7
Version 6
WORKING DIRECTORY
143
© 2016 Brent Laster
143
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5) try code git bisect good (bisect checks out version 7) try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 7
Version 6
WORKING DIRECTORY
144
© 2016 Brent Laster
144
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5) try code git bisect good (bisect checks out version 7) try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 7
Version 6
WORKING DIRECTORY
145
© 2016 Brent Laster
145
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5) try code git bisect good (bisect checks out version 7) try code git bisect bad (bisect checks out version 6)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 6
WORKING DIRECTORY
146
© 2016 Brent Laster
146
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5) try code git bisect good (bisect checks out version 7) try code git bisect bad (bisect checks out version 6) try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 6
WORKING DIRECTORY
147
© 2016 Brent Laster
147
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5) try code git bisect good (bisect checks out version 7) try code git bisect bad (bisect checks out version 6) try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 6
WORKING DIRECTORY
148
© 2016 Brent Laster
148
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5) try code git bisect good (bisect checks out version 7) try code git bisect bad (bisect checks out version 6) try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 6
WORKING DIRECTORY
149
© 2016 Brent Laster
149
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5) try code git bisect good (bisect checks out version 7) try code git bisect bad (bisect checks out version 6) try code git bisect bad (git reports version 6 as the first
bad commit)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 6
WORKING DIRECTORY
150
© 2016 Brent Laster
150
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
checkout latest version try code git bisect start git bisect bad checkout earlier version ( user checks out) try code git bisect good (bisect checks out version 5) try code git bisect good (bisect checks out version 7) try code git bisect bad (bisect checks out version 6) try code git bisect bad (git reports version 6 as the first
bad commit)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 6
FIRST BAD COMMIT
WORKING DIRECTORY
151
© 2016 Brent Laster
151
@BrentCLaster
Background: Switching between Branches
Local Repository
Working Directory
87ba8bc
43bd3ef d21be2c c1c8bd4
152
© 2016 Brent Laster
152
@BrentCLaster
Background: Switching between BranchesCommand: git checkout <branch>
Local Repository
Working Directory
87ba8bc
43bd3ef d21be2c c1c8bd4
153
© 2016 Brent Laster
153
@BrentCLaster
Background: Switching between BranchesCommand: git checkout <branch>git checkout master
Local Repository
Working Directory
87ba8bc
43bd3ef d21be2c c1c8bd4
154
© 2016 Brent Laster
154
@BrentCLaster
Background: Switching between BranchesCommand: git checkout <branch>git checkout master
Does three things
Local Repository
Working Directory
87ba8bc
43bd3ef d21be2c c1c8bd4
155
© 2016 Brent Laster
155
@BrentCLaster
Background: Switching between BranchesCommand: git checkout <branch>git checkout master
Does three things Moves HEAD pointer back to <branch>
Local Repository
Working Directory
87ba8bc
43bd3ef d21be2c c1c8bd4
156
© 2016 Brent Laster
156
@BrentCLaster
Background: Switching between BranchesCommand: git checkout <branch>git checkout master
Does three things Moves HEAD pointer back to <branch> Reverts files in working directory to
snapshot pointed to by <branch>
Local Repository
Working Directory
87ba8bc
43bd3ef d21be2c c1c8bd4
157
© 2016 Brent Laster
157
@BrentCLaster
Background: Switching between BranchesCommand: git checkout <branch>git checkout master
Does three things Moves HEAD pointer back to <branch> Reverts files in working directory to
snapshot pointed to by <branch> Updates indicators
Local Repository
Working Directory
87ba8bc
43bd3ef d21be2c c1c8bd4
158
© 2016 Brent Laster
158
@BrentCLaster
Background: Switching between BranchesCommand: git checkout <branch>git checkout master
Does three things Moves HEAD pointer back to <branch> Reverts files in working directory to
snapshot pointed to by <branch> Updates indicators
git branch
Local Repository
Working Directory
*
87ba8bc
43bd3ef d21be2c c1c8bd4
mastertesting
159
© 2016 Brent Laster
159
@BrentCLaster
Background: Switching between BranchesCommand: git checkout <branch>git checkout master
Does three things Moves HEAD pointer back to <branch> Reverts files in working directory to
snapshot pointed to by <branch> Updates indicators
git checkout testing
git branch
Local Repository
Working Directory
*
87ba8bc
43bd3ef d21be2c c1c8bd4
mastertesting
160
© 2016 Brent Laster
160
@BrentCLaster
Background: Switching between BranchesCommand: git checkout <branch>git checkout master
Does three things Moves HEAD pointer back to <branch> Reverts files in working directory to
snapshot pointed to by <branch> Updates indicators
git checkout testinggit checkout master
git branch
Local Repository
Working Directory
*
87ba8bc
43bd3ef d21be2c c1c8bd4
mastertesting
161
© 2016 Brent Laster
161
@BrentCLaster
Background: Switching between BranchesCommand: git checkout <branch>git checkout master
Does three things Moves HEAD pointer back to <branch> Reverts files in working directory to
snapshot pointed to by <branch> Updates indicators
git checkout testinggit checkout mastergit checkout testing
git branch
Local Repository
Working Directory
*
87ba8bc
43bd3ef d21be2c c1c8bd4
mastertesting
162
© 2016 Brent Laster
162
@BrentCLaster
Command: Worktrees Purpose - Allows multiple, separate Working Areas attached
to one Local Repository Use case - Simultaneous development in multiple branche Syntax
git worktree add [-f] [--detach] [-b <new-branch>] <path> [<branch>] git worktree list [--porcelain] git worktree prune [-n] [-v] [--expire <expire>]
Notes “Traditional” working directory is called the main working tree; Any
new trees you create with this command are called linked working trees
Information about working trees is stored in the .git area (assuming .git default GIT_DIR is used)
Working tree information is stored in .git/worktrees/<name of worktree>.
163
© 2016 Brent Laster
163
@BrentCLaster
Worktrees
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory (master)
Local Machine
164
© 2016 Brent Laster
164
@BrentCLaster
Worktrees git worktree add -b exp tree1
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory (master)
Local Machine
165
© 2016 Brent Laster
165
@BrentCLaster
Worktrees git worktree add -b exp tree1
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory (master)
Local Machine
worktrees/ tree1
166
© 2016 Brent Laster
166
@BrentCLaster
Worktrees git worktree add -b exp tree1
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory (master)
Local Machine
worktrees/ tree1
167
© 2016 Brent Laster
167
@BrentCLaster
Worktrees git worktree add -b exp tree1
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory (master)
Local Machine
worktrees/ tree1
gitdirHEAD
etc.
168
© 2016 Brent Laster
168
@BrentCLaster
Worktrees git worktree add -b exp tree1
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory (master)
Local Machine
worktrees/ tree1
gitdirHEAD
etc.
tree1
Linked Working Tree
Staging Area
Working Directory (exp)
169
© 2016 Brent Laster
169
@BrentCLaster
Worktrees git worktree add -b exp tree1 git worktree add -b prod tree2
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory (master)
Local Machine
worktrees/ tree1
gitdirHEAD
etc.
tree1
Linked Working Tree
Staging Area
Working Directory (exp)
gitdirHEAD
etc.
tree2
Linked Working Tree
Staging Area
Working Directory (prod)
tree2
170
© 2016 Brent Laster
170
@BrentCLaster
Command: Submodules Purpose - Allows including a separate repository with your current repository Use case - include the Git repository for one or more dependencies along with the
original repository for a project Syntax
git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--depth <depth>] [--] <repository> [<path>]
git submodule [--quiet] status [--cached] [--recursive] [--] [<path>… ]git submodule [--quiet] init [--] [<path>… ]git submodule [--quiet] deinit [-f|--force] [--] <path>… git submodule [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--rebase|--merge] [--reference <repository>]
[--depth <depth>] [--recursive] [--] [<path>… ]git submodule [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
[commit] [--] [<path>… ]git submodule [--quiet] foreach [--recursive] <command>git submodule [--quiet] sync [--recursive] [--] [<path>… ]
Notes Creates a subdirectory off of your original repository that contains a clone of another Git
repository Original repository is typically called superproject Metadata stored in .gitmodules file
171
© 2016 Brent Laster
171
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Submodules 1
172
© 2016 Brent Laster
172
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
What happens when you add a submodule?
Submodules 1
173
© 2016 Brent Laster
173
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
What happens when you add a submodule?
Submodules 1
174
© 2016 Brent Laster
174
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
Submodules 1
175
© 2016 Brent Laster
175
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
Submodules 1
176
© 2016 Brent Laster
176
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.
Submodules 1
177
© 2016 Brent Laster
177
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.
Submodules 1
178
© 2016 Brent Laster
178
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
Submodules 1
179
© 2016 Brent Laster
179
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
.gitmodules
Submodules 1
180
© 2016 Brent Laster
180
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
.gitmodules
Submodules 1
181
© 2016 Brent Laster
181
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
4. Git adds the .gitmodules file to the index, ready to be committed.
.gitmodules
Submodules 1
182
© 2016 Brent Laster
182
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
4. Git adds the .gitmodules file to the index, ready to be committed.
.gitmodules
Submodules 1
183
© 2016 Brent Laster
183
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
4. Git adds the .gitmodules file to the index, ready to be committed.
5. Git adds the current commit ID of the submodule to the index, ready to be committed.
.gitmodules
Submodules 1
184
© 2016 Brent Laster
184
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
4. Git adds the .gitmodules file to the index, ready to be committed.
5. Git adds the current commit ID of the submodule to the index, ready to be committed.
.gitmodulesmod1
<current commit>
Submodules 1
185
© 2016 Brent Laster
185
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
4. Git adds the .gitmodules file to the index, ready to be committed.
5. Git adds the current commit ID of the submodule to the index, ready to be committed.
.gitmodulesmod1
<current commit>
Submodules 1
186
© 2016 Brent Laster
186
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
4. Git adds the .gitmodules file to the index, ready to be committed.
5. Git adds the current commit ID of the submodule to the index, ready to be committed.
6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory:
.gitmodulesmod1
<current commit>
Submodules 1
187
© 2016 Brent Laster
187
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
4. Git adds the .gitmodules file to the index, ready to be committed.
5. Git adds the current commit ID of the submodule to the index, ready to be committed.
6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory:
7. Commit
modules/mod1
gitdirHEAD
etc.
Submodules 1
188
© 2016 Brent Laster
188
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
4. Git adds the .gitmodules file to the index, ready to be committed.
5. Git adds the current commit ID of the submodule to the index, ready to be committed.
6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory:
7. Commit
modules/mod1
gitdirHEAD
etc.
submodulereference
Submodules 1
189
© 2016 Brent Laster
189
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
4. Git adds the .gitmodules file to the index, ready to be committed.
5. Git adds the current commit ID of the submodule to the index, ready to be committed.
6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory:
7. Commit
modules/mod1
gitdirHEAD
etc.
submodulereference
commit pointed to by submodulereference
Submodules 1
190
© 2016 Brent Laster
190
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
4. Git adds the .gitmodules file to the index, ready to be committed.
5. Git adds the current commit ID of the submodule to the index, ready to be committed.
6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory:
7. Commit
modules/mod1
gitdirHEAD
etc.
submodulereference
commit pointed to by submodulereference
Head of branch
Submodules 1
191
© 2016 Brent Laster
191
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
4. Git adds the .gitmodules file to the index, ready to be committed.
5. Git adds the current commit ID of the submodule to the index, ready to be committed.
6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory:
7. Commit
modules/mod1
gitdirHEAD
etc.
submodulereference
commit pointed to by submodulereference
Head of branch
8. Push
Submodules 1
192
© 2016 Brent Laster
192
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory.
2. By default, Git checks out the master branch.3. Git adds the submodule’s path for cloning to the .gitmodules file.
4. Git adds the .gitmodules file to the index, ready to be committed.
5. Git adds the current commit ID of the submodule to the index, ready to be committed.
6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory:
7. Commit
modules/mod1
gitdirHEAD
etc.
submodulereference
commit pointed to by submodulereference
Head of branch
8. Push
Submodules 1
193
© 2016 Brent Laster
193
@BrentCLaster
Remote Repository
How do we clone a repository with submodules?
Submodules 2
194
© 2016 Brent Laster
194
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
modules/mod1
gitdirHEAD
etc.
How do we clone a repository with submodules?1. git clone - puts in structure - but submodules areas are empty
Submodules 2
195
© 2016 Brent Laster
195
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
modules/mod1
gitdirHEAD
etc.
How do we clone a repository with submodules?1. git clone - puts in structure - but submodules areas are empty
2. git submodule init - puts submodule location information in superproject’s config file
Remote Repository
Submodules 2
196
© 2016 Brent Laster
196
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
modules/mod1
gitdirHEAD
etc.
How do we clone a repository with submodules?1. git clone - puts in structure - but submodules areas are empty
2. git submodule init - puts submodule location information in superproject’s config file
Remote Repository
Submodules 2
197
© 2016 Brent Laster
197
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
modules/mod1
gitdirHEAD
etc.
How do we clone a repository with submodules?1. git clone - puts in structure - but submodules areas are empty
2. git submodule init - puts submodule location information in superproject’s config file
Remote Repository
3. git submodule update - actually clones repositories for submodules into the corresponding subdirectories and checks out the indicated commits for the containing project
Submodules 2
198
© 2016 Brent Laster
198
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
How do we clone a repository with submodules?1. git clone - puts in structure - but submodules areas are empty
2. git submodule init - puts submodule location information in superproject’s config file
Remote Repository
3. git submodule update - actually clones repositories for submodules into the corresponding subdirectories and checks out the indicated commits for the containing project
Submodules 2
199
© 2016 Brent Laster
199
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
How do we clone a repository with submodules?1. git clone - puts in structure - but submodules areas are empty
2. git submodule init - puts submodule location information in superproject’s config file
Remote Repository
3. git submodule update - actually clones repositories for submodules into the corresponding subdirectories and checks out the indicated commits for the containing project
submodulereference
Submodules 2
200
© 2016 Brent Laster
200
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
How do we clone a repository with submodules?1. git clone - puts in structure - but submodules areas are empty
2. git submodule init - puts submodule location information in superproject’s config file
Remote Repository
3. git submodule update - actually clones repositories for submodules into the corresponding subdirectories and checks out the indicated commits for the containing project
Note: Shortcuts - git submodule update --init and git clone --recursive or --recurse-submodules
submodulereference
Submodules 2
201
© 2016 Brent Laster
201
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
Incorporating updates to submodules:
Submodules 3
202
© 2016 Brent Laster
202
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:
Submodules 3
203
© 2016 Brent Laster
203
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can
Submodules 3
204
© 2016 Brent Laster
204
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
Submodules 3
205
© 2016 Brent Laster
205
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
Submodules 3
206
© 2016 Brent Laster
206
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
Submodules 3
207
© 2016 Brent Laster
207
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
Submodules 3
208
© 2016 Brent Laster
208
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master
Submodules 3
209
© 2016 Brent Laster
209
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/masterOR
Submodules 3
210
© 2016 Brent Laster
210
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/masterOR $ git submodule update --remote
Submodules 3
211
© 2016 Brent Laster
211
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/masterOR $ git submodule update --remote
2. Although module has been updated, references that the superproject has to it haven’t been updated
Submodules 3
212
© 2016 Brent Laster
212
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/masterOR $ git submodule update --remote
2. Although module has been updated, references that the superproject has to it haven’t been updated
Submodules 3
213
© 2016 Brent Laster
213
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/masterOR $ git submodule update --remote
2. Although module has been updated, references that the superproject has to it haven’t been updated
Submodules 3
3. To update: add, commit, and push reference changes.
214
© 2016 Brent Laster
214
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/masterOR $ git submodule update --remote
2. Although module has been updated, references that the superproject has to it haven’t been updated
Submodules 3
3. To update: add, commit, and push reference changes.
215
© 2016 Brent Laster
215
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/masterOR $ git submodule update --remote
2. Although module has been updated, references that the superproject has to it haven’t been updated
Submodules 3
3. To update: add, commit, and push reference changes.
216
© 2016 Brent Laster
216
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc. commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/masterOR $ git submodule update --remote
2. Although module has been updated, references that the superproject has to it haven’t been updated
.gitmodulesmod1
<current commit>
Submodules 3
3. To update: add, commit, and push reference changes.
217
© 2016 Brent Laster
217
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc. commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/masterOR $ git submodule update --remote
2. Although module has been updated, references that the superproject has to it haven’t been updated
Submodules 3
3. To update: add, commit, and push reference changes.
218
© 2016 Brent Laster
218
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/masterOR $ git submodule update --remote
2. Although module has been updated, references that the superproject has to it haven’t been updated
Submodules 3
3. To update: add, commit, and push reference changes.
219
© 2016 Brent Laster
219
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/masterOR $ git submodule update --remote
2. Although module has been updated, references that the superproject has to it haven’t been updated
Submodules 3
3. To update: add, commit, and push reference changes.
220
© 2016 Brent Laster
220
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/masterOR $ git submodule update --remote
2. Although module has been updated, references that the superproject has to it haven’t been updated
Submodules 3
3. To update: add, commit, and push reference changes.
221
© 2016 Brent Laster
221
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/mod1
gitdirHEAD
etc.
commit pointed to by submodulereference
Head of branch
Remote Repository
submodulereference
new commitIncorporating updates to submodules:1. You can $ cd mod1; git checkout <branch> ; git pull
OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/masterOR $ git submodule update --remote
2. Although module has been updated, references that the superproject has to it haven’t been updated
Submodules 3
3. To update: add, commit, and push reference changes.
222
© 2016 Brent Laster
222
@BrentCLaster
Submodule - Challenges Challenges around using submodules nearly always
involve keeping submodule content (and “current” commit) in sync with submodule references in superproject
If references are wrong, operations like “git submodule update” will backlevel submodule content to commits in reference
If these references are out of sync and that inconsistency is pushed to the remote for the superproject, then other users that pull that version of the superproject can end up back-leveling their submodules, even if they’ve updated their superproject before.
223
© 2016 Brent Laster
223
@BrentCLaster
Command: Subtrees
Purpose - Allows including a copy of a separate repository with your current repository
Use case - include a copy of a Git repository for one or more dependencies along with the original repository for a project
Syntax
Notes No links like a submodule - just a copy in a subdirectory Advantage - no links to maintain Disadvantage - extra content to carry around with your project
git subtree add -P <prefix> <commit> git subtree add -P <prefix> <repository> <ref> git subtree pull -P <prefix> <repository> <ref> git subtree push -P <prefix> <repository> <ref> git subtree merge -P <prefix> <commit> git subtree split -P <prefix> [OPTIONS] [<commit>]
224
© 2017 Brent Laster
224
Subtrees
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
225
© 2017 Brent Laster
225
Subtrees Adding a copy from a remote as
a subtree
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
226
© 2017 Brent Laster
226
Subtrees Adding a copy from a remote as
a subtree cd myproject
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
227
© 2017 Brent Laster
227
Subtrees Adding a copy from a remote as
a subtree cd myproject git subtree add --prefix
subproject --squash subproj.git master
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
228
© 2017 Brent Laster
228
Subtrees Adding a copy from a remote as
a subtree cd myproject git subtree add --prefix
subproject --squash subproj.git master
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
229
© 2017 Brent Laster
229
Subtrees Adding a copy from a remote as
a subtree cd myproject git subtree add --prefix
subproject --squash subproj.git master
Use “prefix” option to specify path for subproject
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
230
© 2017 Brent Laster
230
Subtrees Adding a copy from a remote as
a subtree cd myproject git subtree add --prefix
subproject --squash subproj.git master
Use “prefix” option to specify path for subproject
Use “squash” option to compress history from remote before adding it
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
231
© 2017 Brent Laster
231
Subtrees Adding a copy from a remote as
a subtree cd myproject git subtree add --prefix
subproject --squash subproj.git master
Use “prefix” option to specify path for subproject
Use “squash” option to compress history from remote before adding it
branch (master) is optional
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
232
© 2017 Brent Laster
232
Subtrees Adding a copy from a remote as
a subtree cd myproject git subtree add --prefix
subproject --squash subproj.git master
Use “prefix” option to specify path for subproject
Use “squash” option to compress history from remote before adding it
branch (master) is optional
directory listing of myproject now shows subproj as subdirectory
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
233
© 2017 Brent Laster
233
Subtrees Adding a copy from a remote as
a subtree cd myproject git subtree add --prefix
subproject --squash subproj.git master
Use “prefix” option to specify path for subproject
Use “squash” option to compress history from remote before adding it
branch (master) is optional
directory listing of myproject now shows subproj as subdirectory
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
234
© 2017 Brent Laster
234
Subtrees Adding a copy from a remote as
a subtree cd myproject git subtree add --prefix
subproject --squash subproj.git master
Use “prefix” option to specify path for subproject
Use “squash” option to compress history from remote before adding it
branch (master) is optional
directory listing of myproject now shows subproj as subdirectory
Looking in the logs of the subproject will show the squashed history
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
235
© 2017 Brent Laster
235
Subtrees Adding a copy from a remote as
a subtree cd myproject git subtree add --prefix
subproject --squash subproj.git master
Use “prefix” option to specify path for subproject
Use “squash” option to compress history from remote before adding it
branch (master) is optional
directory listing of myproject now shows subproj as subdirectory
Looking in the logs of the subproject will show the squashed history
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
236
© 2017 Brent Laster
236
Subtrees Adding a copy from a remote as
a subtree cd myproject git subtree add --prefix
subproject --squash subproj.git master
Use “prefix” option to specify path for subproject
Use “squash” option to compress history from remote before adding it
branch (master) is optional
directory listing of myproject now shows subproj as subdirectory
Looking in the logs of the subproject will show the squashed history
To get the latest, use pull
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
237
© 2017 Brent Laster
237
Subtrees Adding a copy from a remote as
a subtree cd myproject git subtree add --prefix
subproject --squash subproj.git master
Use “prefix” option to specify path for subproject
Use “squash” option to compress history from remote before adding it
branch (master) is optional
directory listing of myproject now shows subproj as subdirectory
Looking in the logs of the subproject will show the squashed history
To get the latest, use pull git subtree pull --prefix subproject
--squash subproj.git master
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
238
© 2016 Brent Laster
238
@BrentCLaster
Subtrees - split split subcommand can be used to extract a subproject’s
content into a separate branch extracts the content and history related to <prefix> and
puts the resulting content at the root of the new branch instead of in a subdirectory
As output, Git prints out the SHA1 value for the HEAD of
the newly created tree Provides a reference to work with for that HEAD if needed New branch shows only the set of content from the subproject
that was split out (as opposed to content from the superproject).
239
© 2016 Brent Laster
239
@BrentCLaster
Subtree - create new project from split content Since can split out content from a subtree, may want to
transfer that split content into another project Very simple with Git
create new, empty project
pull contents of new branch into the new project (repository)
240
© 2016 Brent Laster
240
@BrentCLaster
Subtree - push
subtree command also supports a push subcommand This command does a split followed by an attempt to
push the split content over to the remote Example: the following command splits out the
subproject directory and then pushes it to the sub_origin remote reference and into a new branch named new branch:
241
© 2016 Brent Laster
241
@BrentCLaster
Command: (Interactive) Rebase Purpose - allows you to modify commits in the git history Use case - you need to make some kind of modification
to one or more commits in the repository (rewrite history)
Syntax
Notes - creates an interactive script/batch file to modify commits
Cautions - don’t use this on anything already pushed
242
© 2016 Brent Laster
242
@BrentCLaster
Interactive Rebase
243
© 2016 Brent Laster
243
@BrentCLaster
Interactive Rebase
244
© 2016 Brent Laster
244
@BrentCLaster
Interactive Rebase Choose set of
commits
245
© 2016 Brent Laster
245
@BrentCLaster
Interactive Rebase Choose set of
commits
246
© 2016 Brent Laster
246
@BrentCLaster
Interactive Rebase Choose set of
commits Initiate
interactive rebase
247
© 2016 Brent Laster
247
@BrentCLaster
Interactive Rebase Choose set of
commits Initiate
interactive rebase
248
© 2016 Brent Laster
248
@BrentCLaster
Interactive Rebase Choose set of
commits Initiate
interactive rebase
Git presents initial script
249
© 2016 Brent Laster
249
@BrentCLaster
Interactive Rebase Choose set of
commits Initiate
interactive rebase
Git presents initial script
250
© 2016 Brent Laster
250
@BrentCLaster
Interactive Rebase Choose set of
commits Initiate
interactive rebase
Git presents initial script
Modify commands (save and exit)
251
© 2016 Brent Laster
251
@BrentCLaster
Interactive Rebase Choose set of
commits Initiate
interactive rebase
Git presents initial script
Modify commands (save and exit)
252
© 2016 Brent Laster
252
@BrentCLaster
Interactive Rebase Choose set of
commits Initiate
interactive rebase
Git presents initial script
Modify commands (save and exit)
Act on prompts
253
© 2016 Brent Laster
253
@BrentCLaster
Interactive Rebase Choose set of
commits Initiate
interactive rebase
Git presents initial script
Modify commands (save and exit)
Act on prompts
254
© 2016 Brent Laster
254
@BrentCLaster
Interactive Rebase Choose set of
commits Initiate
interactive rebase
Git presents initial script
Modify commands (save and exit)
Act on prompts
255
© 2016 Brent Laster
255
@BrentCLaster
Interactive Rebase Choose set of
commits Initiate
interactive rebase
Git presents initial script
Modify commands (save and exit)
Act on prompts
256
© 2016 Brent Laster
256
@BrentCLaster
Interactive Rebase Choose set of
commits Initiate
interactive rebase
Git presents initial script
Modify commands (save and exit)
Act on prompts
257
© 2016 Brent Laster
257
@BrentCLaster
Interactive Rebase Choose set of
commits Initiate
interactive rebase
Git presents initial script
Modify commands (save and exit)
Act on prompts Commits are
updated
258
© 2016 Brent Laster
258
@BrentCLaster
Interactive Rebase Choose set of
commits Initiate
interactive rebase
Git presents initial script
Modify commands (save and exit)
Act on prompts Commits are
updated
259
© 2016 Brent Laster
259
@BrentCLaster
Command: Notes Purpose - Add additional information to objects in the Git repository
or look at such information Use case - At some point after making a commit, you may decide
that there are additional comments or other non-code information that you’d like to add with the commit - without changing the commit itself.
Syntaxgit notes [list [<object>]]git notes add [-f] [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]git notes copy [-f] ( --stdin | <from-object> <to-object> )git notes append [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]git notes edit [--allow-empty] [<object>]git notes show [<object>]git notes merge [-v | -q] [-s <strategy> ] <notes-ref>git notes merge --commit [-v | -q]git notes merge --abort [-v | -q]git notes remove [--ignore-missing] [--stdin] [<object>… ]git notes prune [-n | -v]git notes get-ref
260
© 2016 Brent Laster
260
@BrentCLaster
Notes Create a note Create a note in a custom
namespace (add --ref)
View a note (for a specific revision)
List notes in log
261
© 2016 Brent Laster
261
@BrentCLaster
Command: grep Purpose - provides a convenient (and probably familiar) way to search for
regular expressions in your local Git environment. Use case - self-explanatory Syntax
git grep [-a | --text] [-I] [--textconv] [-i | --ignore-case] [-w | --word-regexp] [-v | --invert-match] [-h|-H] [--full-name] [-E | --extended-regexp] [-G | --basic-regexp] [-P | --perl-regexp] [-F | --fixed-strings] [-n | --line-number] [-l | --files-with-matches] [-L | --files-without-match] [(-O | --open-files-in-pager) [<pager>]] [-z | --null] [-c | --count] [--all-match] [-q | --quiet] [--max-depth <depth>] [--color[=<when>] | --no-color] [--break] [--heading] [-p | --show-function] [-A <post-context>] [-B <pre-context>] [-C <context>] [-W | --function-context] [--threads <num>] [-f <file>] [-e] <pattern> [--and|--or|--not|(|)|-e <pattern>… ] [ [--[no-]exclude-standard] [--cached | --no-index | --untracked] | <tree>… ] [--] [<pathspec>… ]
Notes Several options are similar to OS grep options
262
© 2016 Brent Laster
262
@BrentCLaster
grep Default behavior - search for all instances of an expression across all tracked files in
working directory Search for all instances off expression “database” across all java files (note use of -- )
-p option tells Git to try and show header of method or function where search target was found
--break - make output easier to read --heading - prints filename above output
boolean operators search in staging area search in specific commit(s)
263
© 2016 Brent Laster
263
© 2016 Brent Laster@BrentCLaster
That’s all - thanks!