@@ -16,17 +16,18 @@ TMP='git-sample-repo'
16
16
clear
17
17
# Make the beginning of run easy to find:
18
18
echo " **********************************************************"
19
- echo " ******** STEP 01: Delete \" $TMP \" remnant from previous run:"
19
+ echo " ******** STEP Delete \" $TMP \" remnant from previous run:"
20
20
rm -rf ${TMP}
21
21
mkdir ${TMP}
22
22
cd ${TMP}
23
23
24
+ echo " ******** Git version :"
25
+ git --version
24
26
echo " ******** STEP Init repo :"
25
27
# init without --bare so we get a working directory:
26
28
git init
27
29
# return the .git path of the current project::
28
30
git rev-parse --git-dir
29
- ls -al
30
31
ls .git/
31
32
32
33
echo " ******** STEP Make develop the default branch instead of master :"
51
52
# echo "$GIT_COMMITTER_EMAIL=" $GIT_COMMITTER_EMAIL
52
53
# echo $GIT_AUTHOR_EMAIL
53
54
# Verify settings:
54
- git config user.name
55
- git config user.email
56
55
git config core.filemode false
57
56
58
57
# On Unix systems, ignore ^M symbols created by Windows:
@@ -65,92 +64,98 @@ git config core.editor "~/Sublime\ Text\ 3/sublime_text -w"
65
64
git config color.ui auto
66
65
67
66
# See https://git-scm.com/docs/pretty-formats :
68
- git config alias.l " log --pretty='%Cred%h%Creset %C(yellow)%d%Creset | %Cblue%s%Creset | (%cr) %Cgreen<%ae>%Creset' --graph"
69
- git config alias.s " status -s"
70
- git config alias.w " show -s --quiet --pretty=format:'%Cred%h%Creset | %Cblue%s%Creset | (%cr) %Cgreen<%ae>%Creset'"
67
+ git config alias.l " log --pretty='%Cred%h%Creset %C(yellow)%d%Creset | %Cblue%s%Creset' --graph"
68
+ git config alias.s " status -s"
69
+ # it config alias.w "show -s --quiet --pretty=format:'%Cred%h%Creset | %Cblue%s%Creset | (%cr) %Cgreen<%ae>%Creset'"
70
+ git config alias.w " show -s --quiet --pretty=format:'%Cred%h%Creset | %Cblue%s%Creset'"
71
+ git config alias.ca " commit -a --amend -C HEAD"
71
72
72
73
# Have git diff use mnemonic prefixes (index, work tree, commit, object) instead of standard a and b notation:
73
74
git config diff.mnemonicprefix true
75
+ git config rerere.enabled false
74
76
75
77
# Dump config file:
76
78
# git config --list
77
79
78
- echo " ******** STEP First commit: a "
80
+ echo " ******** STEP commit a1 - README.md : "
79
81
touch README.md
80
82
git add .
81
- git commit -am " a"
82
-
83
- echo " ******** STEP Second commit:"
83
+ git commit -m " Add README.md"
84
+ git l -1
85
+
86
+ echo " ******** STEP ammend commit a2 : "
87
+ # ammend last commit with all uncommitted and un-staged changes:
88
+ echo " some more" >> README.md
89
+ # Instead of git commit -a --amend -C HEAD
90
+ git ca # use this alias instead.
91
+ git l -1
92
+
93
+ echo " ******** STEP ammend commit a3 : "
94
+ # ammend last commit with all uncommitted and un-staged changes:
95
+ echo " still some more" >> README.md
96
+ # Instead of git commit -a --amend -C HEAD
97
+ git ca # use this alias instead.
98
+ git l -1
99
+
100
+ echo " ******** STEP commit b - .gitignore :"
84
101
echo " .DS_Store" >> .gitignore
85
- git status
86
102
git add .
87
- # git status
88
- git commit -m " b"
89
- git l
103
+ git commit -m " Add .gitignore"
104
+ git l -1
105
+ git reflog
106
+ ls -al
107
+ cat README.md
90
108
91
- echo " ******** STEP Third commit: branch F1"
109
+ echo " ******** STEP tag & commit branch F1 : -------------------------- "
92
110
git tag v1
93
111
git checkout v1 -b F1
94
- git branch
95
- git l
112
+ # git branch
113
+ ls .git/refs/heads/
114
+ git l -1
96
115
97
- echo " ******** STEP Fourth commit: c "
116
+ echo " ******** STEP Fourth commit c - LICENSE.md : "
98
117
echo " MIT" >> LICENSE.md
99
118
git add .
100
- git commit -m " c"
101
- git l
119
+ git commit -m " Add c"
120
+ git l -1
102
121
103
122
echo " ******** STEP commit: d"
104
123
echo " free!" >> LICENSE.md
105
124
echo " d" >> file-d.txt
106
125
git add .
107
- git commit -m " d"
108
- git l
126
+ git commit -m " Add d"
127
+ git l -1
128
+ ls -al
109
129
110
- echo " ******** STEP Merge:"
111
- git checkout $DEFAULT_BRANCH
112
- # git merge F1 --no-commit
130
+ echo " ******** STEP Merge F1 :"
131
+ # Instead of git checkout $DEFAULT_BRANCH :
132
+ git checkout @{-1} # checkout previous branch (develop, master)
133
+
134
+ git merge F1 --no-ff --no-commit # to see what may happen
113
135
# git merge F1 --no-ff <:q
114
- git merge F1 -- no-ff
115
- # Manually type ":q" to exit merge.
116
- git commit -m " merge F1"
136
+ git merge F1 -m " merge F1 " -- no-ff # --no-ff for "true merge".
137
+ # resolve conflicts here?
138
+ git commit -m " commit merge F1"
117
139
git branch
118
- git l
140
+ git l -1
119
141
120
- # echo "******** $NOW Remove Merge branch ref:"
142
+ # echo "******** $NOW Remove merged branch ref :"
121
143
# git branch -d F1
122
144
# git branch
123
- # git l
145
+ # git l -1
124
146
125
147
echo " ******** STEP commit: e"
126
148
echo " e" >> file-e.txt
127
149
git add .
128
- git status
129
150
git commit -m " e"
130
- git l
151
+ git l -1
131
152
132
153
echo " ******** STEP commit: f"
133
154
echo " f" >> file-f.txt
134
155
ls -al
135
156
git add .
136
157
git commit -m " f"
137
-
138
-
139
- # Undo last commit, preserving local changes:
140
- # git reset --soft HEAD~1
141
-
142
- # Undo last commit, without preserving local changes:
143
- # git reset --hard HEAD~1
144
-
145
- # Undo last commit, preserving local changes in index:
146
- # git reset --mixed HEAD~1
147
-
148
- # Undo non-pushed commits:
149
- # git reset origin/$DEFAULT_BRANCH
150
-
151
- # Reset to remote state:
152
- # git fetch origin
153
- # git reset --hard origin/$DEFAULT_BRANCH
158
+ git l -1
154
159
155
160
156
161
echo " Copy this and paste to a text edit for reference: --------------"
@@ -188,20 +193,60 @@ git w HEAD~2^2
188
193
echo " ******** show HEAD~2^3 :"
189
194
git w HEAD~2^3
190
195
196
+ # exit
197
+
191
198
echo " ******** Reflog: ---------------------------------------"
192
199
git reflog
200
+ ls -al
201
+
202
+ exit
193
203
194
204
echo " ******** Create archive file, excluding .git directory :"
195
205
NOW=$( date +%Y-%m-%d:%H:%M:%S-MT)
196
206
FILENAME=$( echo ${TMP} _${NOW} .zip)
197
207
echo $FILENAME
208
+ # Commented out to avoid creating a file from each run:
198
209
# git archive --format zip --output ../$FILENAME F1
199
210
# ls -l ../$FILENAME
200
211
212
+
201
213
echo " ******** checkout c :"
202
214
ls -al
215
+ git show HEAD@{5}
203
216
git checkout HEAD@{5}
204
217
ls -al
218
+ git reflog
219
+
220
+ echo " ******** checkout previous HEAD :"
221
+ git checkout HEAD
222
+ ls -al
223
+
224
+
225
+
226
+ # Undo last commit, preserving local changes:
227
+ # git reset --soft HEAD~1
228
+
229
+ # Undo last commit, without preserving local changes:
230
+ # git reset --hard HEAD~1
231
+
232
+ # Undo last commit, preserving local changes in index:
233
+ # git reset --mixed HEAD~1
234
+
235
+ # Undo non-pushed commits:
236
+ # git reset origin/$DEFAULT_BRANCH
237
+
238
+
239
+ # git stash save "text message here"
240
+ # git stash list /* shows whats in stash */
241
+ # git stash show -p stash@{0} /* Show the diff in the stash */
242
+ # git stash pop stash@{0} /* restores the stash deletes the tash */
243
+ # git stash apply stash@{0} /* restores the stash and keeps the stash */
244
+ # git stash clear /* removes all stash */
245
+ # git stash drop stash@{0}
246
+
247
+ # Reset to remote state:
248
+ # git fetch origin
249
+ # git reset --hard origin/$DEFAULT_BRANCH
205
250
206
251
# echo "******** Cover your tracks:"
207
252
# Remove from repository all locally deleted files:
0 commit comments