@@ -25,96 +25,32 @@ commands to explore your history.
25
25
26
26
Your Git history will look different depending on the merge
27
27
strategy you use when merging PRs
28
- and whether you allow merging ` main ` into a feature branch
29
- like we did in the last episode to resolve the conflict.
28
+ and whether you allow merging ` main ` into a feature branch.
30
29
It's up to you and your team to decide which strategy is
31
30
best for your repository.
32
31
32
+ ::: spoiler
33
+
33
34
## Viewing History
34
35
35
- You have already learnt that we can use the
36
- ` git log ` command to output the commit history
36
+ In the [ Introduction to Version Control
37
+ with Git] ( https://www.astropython.com/git-novice/05-history.html ) lesson you learnt that we can use the
38
+ ` git log ` command to view the commit history
37
39
of our repository.
38
40
39
- ``` bash
40
- $ git log
41
- ```
42
-
43
- ``` output
44
- commit acce45c86ece7fd4823ddc6c1addb43edf4c0794
45
- Merge: e3fc783 ca8aca9
46
- Author: Robert FitzRoy <[email protected] >
47
- Date: Mon Sep 23 15:50:15 2024 +0100
48
-
49
- Merge pull request #1 from MetOffice/mo-fitzroy-patch-1
50
-
51
- Create CITATION.cff
52
-
53
- commit ca8aca9f2f43a4d799eb5c9ce9596b42360faa8b
54
- Author: Robert FitzRoy <[email protected] >
55
- Date: Mon Sep 23 15:49:36 2024 +0100
56
-
57
- Create CITATION.cff
58
-
59
- commit e3fc783648222d5eef0739922b06794b8d690341
60
- Author: Robert FitzRoy <[email protected] >
61
- Date: Fri Sep 20 13:01:05 2024 +0100
62
-
63
- Initial commit
64
- ```
65
-
66
- This shows the first 3 commits to the ` git-training-demo ` repository (the full output isn't shown here because it's very long).
67
41
We can use certain flags with ` git log ` to better
68
42
visualise the history in graph form:
69
43
70
44
``` bash
71
45
$ git log --decorate --oneline --graph
72
46
```
73
47
74
- ``` output
75
- * d800b46 (HEAD -> main, origin/main, origin/HEAD) Merge pull request #2 from MetOffice/mo-fitzroy-patch-2
76
- |\
77
- | * dbc944d Add pre-commit checks
78
- |/
79
- * acce45c Merge pull request #1 from MetOffice/mo-fitzroy-patch-1
80
- |\
81
- | * ca8aca9 Create CITATION.cff
82
- |/
83
- * e3fc783 Initial commit
84
- ```
85
-
86
- The [ GitHub Documentation for git log] ( https://git-scm.com/docs/git-log ) has information on all the available flags.
87
- The key here is ` --graph ` shows us the graphical
88
- representation of our history on the left of the
89
- terminal.
90
- ` * ` 's are commits which are connected by lines.
91
- The vertical lines represent links between commits.
92
- The output above shows two feature branches each with
93
- only one commit which were then merged back into
94
- ` main ` via a pull request.
95
-
96
- You can either remember the flags using
97
- the phrase "git dog", ` d ` for ` --decorate ` ,
98
- ` o ` for ` --oneline ` , ` g ` for ` --graph ` or
99
- you can set an alias for the ` git log ` command:
100
-
101
- ``` bash
102
- $ git config --global alias.dog " log --decorate --oneline --graph"
103
- ```
104
-
105
- This alias makes these two commands equivalent:
106
-
107
- ``` bash
108
- $ git dog
109
- $ git log --decorate --oneline --graph
110
- ```
111
-
112
- You can of course customise the log command
113
- with other keywords and set more aliases for
114
- different log views.
115
- Some useful examples can be found on
48
+ The [ GitHub Documentation for git log] ( https://git-scm.com/docs/git-log ) has information on all the available flags.
49
+ Some useful examples of ` git log ` alias's and flags can be found on
116
50
[ this Stackoverflow comment] ( https://stackoverflow.com/questions/1838873/visualizing-branch-topology-in-git/34467298#34467298 ) .
117
51
52
+ :::
53
+
118
54
::: callout
119
55
120
56
### IDE Git History Extensions
@@ -127,14 +63,14 @@ If you use VSCode we recommend the [Git Graph extension](https://marketplace.vis
127
63
128
64
## Merge Options
129
65
130
- When you opened your PRs you were given
66
+ When you open a PR you are given
131
67
three options for merging your feature
132
68
branch into ` main ` .
133
69
We will now explore how each merging method
134
70
affects the history of your repository.
135
71
In all the examples below we start with the same git history.
136
72
137
- ### Merge
73
+ ## Merge
138
74
139
75
Starting with:
140
76
@@ -183,7 +119,7 @@ keeps all the individual commits that made
183
119
up your change so more accurately represents
184
120
the history of your repository.
185
121
186
- ### Squash and Merge
122
+ ## Squash and Merge
187
123
188
124
Starting with:
189
125
@@ -226,7 +162,7 @@ Squashing in this case will make bug hunting harder.
226
162
Remember you should try and break work down into
227
163
small pieces so you avoid huge branches.
228
164
229
- ### Rebase
165
+ ## Rebase
230
166
231
167
Starting with:
232
168
@@ -288,6 +224,6 @@ for your project.
288
224
branch into ` main ` .
289
225
- merge: creates a merge commit and results in a non-linear history unless you first rebase your feature branch.
290
226
- squash and merge: squashes all your feature branch commits into one merge commit on ` main ` . Your history is linear.
291
- - rebase: re-writes your git history so that all the feature branch commits are now on ` main ` . Your history is linear.
227
+ - rebase: re-writes your git history so that all the feature branch commits are now on ` main ` . Your history is linear.
292
228
293
229
::::::::::::::::::::::::::::::::::::::::::::::::::
0 commit comments