-
Notifications
You must be signed in to change notification settings - Fork 0
/
readMe.txt
363 lines (214 loc) · 10.8 KB
/
readMe.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
0. make your global config:
git config --global user.name "Alireza Rezaei"
git config --global user.email "alireza.rezaeikalat@gmail.com"
git config --list
git <verb> --help : git config --help
1. to make git repository
<!-- git init-->
2. to see the status of files:
<!-- git status -->
<!-- git diff --> (you can see the changes by this command)
3. to discard changes in working directory
<!-- git restore <filename>-->
4. to add to stage area
<!-- git add <index.html> -->
to add all the files to staging area
<!-- git add -A -->
5. to remove from stage area
<!-- git rm --cached <index.html> -->
or
<!-- git reset <filename> -->
to remove all the files from staging area-->
<!-- git reset -->
6. to commit
<!-- git commit -m '<description>' -->
7. to see the commit history
<!-- git log -->
<!-- git log -oneline -->
8. to go back in time in read only mode
<!-- git checkout <commit id that you want go to>-->
9. <!--!!! to make a new commit and undo particular one -->
<!-- git revert <commit id that you want to undo>-->
10. to go to special commit and delete the after ones but the changes is visible in editor:
a. <!-- git reset <commit id that you want go to> -->
to reset and remove the changes from editor:
b. <!-- git reset <commit id that you want go to> --hard -->
11. to make a new branch
<!-- git branch <branch name>-->
12. to delete the branch first switch to master branch then:
<!-- git branch -d <branch name>-->
13. to see the tree of files
(*) shows the current branch
<!-- git branch -a -->
or
to see all branches locally
<!-- git branch -->
14. to go to branches
<!-- git checkout <branch name>-->
15. to merge the branch to master branch
first you have to go to master branch
<!-- git checkout master -->
you can see all the merged branch
<!-- git branch --merged -->
Then you can merge
<!-- git merge <name of the branch that you want to merge to master> -->
if you have the conflict first remove the comments
then commit with:
a. <!-- git add . -->
b. <!-- git commit -->
to quit
a. <!-- shift + : -->
b. <!-- wq -->
[ATTENTION]
We have two types of merge:
a. fast forward merge: It just change the current branch tip to -F and combines histories of two branch
-D - E -F
A - B - C
b. three way merge (git uses 3 commits to generate the merge commit- head of two branch and common ancestor)
[ATTENTION]
If you are in the middle of merge, you stop it completely:
git merge --abort
16. to push to the remote repository
first commite the changes in your local repository
a. <!-- git add . -->
b. <!-- git commit -m <description> -->
to push
a. <!-- git push <url or origin name> <branch to push> -->
17. to make alias for the url of the remote repository
<!-- git remote add <alias> <url> -->
to see the alias name
<!-- git remote -v -->
18. to clone the repository
<!-- git clone <url> <where to clone> -->
<!-- !!! and also makes origin alias -->
//////////////// a common workflow for working in the team //////////
19. Working in the team
first update your local repo
<!-- git pull origin master -->
then make a new branch to make changes in that branch
<!-- git branch <branch name> -->
<!-- git checkout <branch name> -->
after your changes push the new branch to remote repo
<!-- git push -u origin <branch name> -->
Then make pull request to merge it to master branch in github site
Then the manager can accept the changes
if you have the permission to push the master branch:
after accepting the branch, you can merge the branch locally
go to master branch
<!-- git checkout master -->
<!-- git pull origin master -->
merge the branch
<!-- git merge <branch name> -->
now push the master branch
<!-- git push origin master -->
now you can delete the branch locally: <pay attention to the locally>
deleting the branch
git branch -d <branch name>
but if you see the branches the remote branch is still there
<!-- git branch -a -->
to delete the branch on remote repository
<!-- git push origin --delete <branch name> -->
//////// fixing mistakes in git //////////
20. if you add a commit with wrong message, you can change the commit message of the last one:
git commit --amend -m 'new message' but in this way you will change the commit hash
git commit --amend for example if you left a file from commit first add it then use --amend
(and the commit hash will be different)
(so do this, if you haven't push your commit to the remote repository)
21. if you commit to a wrong branch, you can add the commit to the right branch and remove the commit from the wrong branch:
a. first get the commit hash from the wrong branch:
git log (then copy the id)
b. then go to the right branch:
git checkout <right branch name>
c. copy the commit to the right branch:
git cherry-pick <commit id>
d. delete the commit on the wrong branch:
git checkout <wrong branch>
git reset --soft <the previous commit id> --soft reset the changes but keep the changes in the staging area
git reset <the previous commit id> --mixed this is the default one, reset the changes and remove from the staging
area but keep it in the editor
git reset --hard <the previous commit id> --hard removes the changes and remove it from staging area and the editor as well
but it will not removed the untacked files, for example if you add another file
that is not in the commit that you reset to. so you have to delete this file
manually or use another instruction:
git clean -df (-d for directory and -f for files)
22. if you remove the commit using git reset --hard you can still access the deleted commit:
a. first get the hash code of the deleted commit:
git reflog
b. then go to the deleted commit in detached head:
git checkout <the deleted commit id> (now you are in the detached head)
c. then make new branch to save attach head to this (cat .git/HEAD)
git checkout -b <your new branch name>
d. then if you want, merge the branch to the master branch:
git checkout master
git merge <branch name>
23. if you are in a situation that you push your commits, and other people pull your commits, it is not good practise to change the
git history by using reset or ammend, in this situations you can use revert:
git revert <commit id that you want ro revert>
/////////// using git stash ////////////
24. if you want to remove your changes temporary before commit, and can get them back, when you want, you can use:
git stash save "your message"
25. you can get the list of stashes:
git stash list
26. you can reapply the stash:
git stash apply <stash@{0}> // but the stash is still in the stash list
git stash pop // get the latest stash and remove it from stash list
26. remove the stash from stash list
git stash drop <stash@{0}>
27. to remove all the stashes:
git stash clear
[ATTENTION]
28. using stash is a good way, to fixed the common error when you make changes on the wrong branch:
a. you make changes to wrong branch but you haven't commit it, but when you want to change your branch, you will get an
error that is you have uncommited change, so you can stash your changes:
git stash save "wrong change in the master branch"
b. go to the branch that is right:
git checkout <branch name>
c. apply the stash:
git stash pop
/////////// using diff merge tool ////////
29. first download DiffMerge
30. config your git for gitmerge:
git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd 'diffmerge "$LOCAL" "$REMOTE"'
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'
git config --global mergetool.diffmerge.trustExitCode true
31. opening difftool:
git difftool
32. you can use merge tool:
git mergetool
//// different between git add //////////
33. git add -A (it is going to add all the modified files, deleted files, and new files in all tree of files)
git add -A mydir/ (only in the mydir folder) (git add -A is the default behavior for git)
git add -u (add only modified and deleted files not new files in all tree)
git add . (add all the files in current directory, because the default behavior is -A)
///////////// using tags in git ////////////
34. Git has the ability to tag specific points in a repository’s history as being important. Typically, people use this
functionality to mark release points (v1.0, v2.0 and so on). working with tags are just like working with branches
a. list all the tags:
git tag (optional -l or --list)
b. list tags with special pattern:
git tag -l "v1.8.5*"
c. creating annotated tag:
git tag -a v1.4 -m 'my version 1.4'
see the tag information:
git show v1.4
tagger: ...
date: ....
d. create lightweight tag:
git tag v.14
see the tag:
git show v.14
e. tagging later (you can tag older commits)
git tag -a v1.3 <commit id>
f. after making tags, you have to push tags to remote servers, like branches:
git push origin <tag name>
to push all your tags:
git push origin --tags
g. deleting tags;
git tag -d <tag name>
delete on the remote server:
git push origin --delete <tag name>
h. to check out to the tag
git checkout <tagname>
but in this situation you are in the detach head, so you have to make new branch to save your commits