forked from michaelliao/learngit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_learning_note__hellozuizui.txt
170 lines (140 loc) · 5.85 KB
/
git_learning_note__hellozuizui.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
This is my first git learning note.
by hellozuizui
***************************************
*** git learning note ***
***************************************
******************
git setup
******************
1__setup git from git web:https://git-scm.com
2__config git user & email by CMD of windows:
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
******************
create git repository
******************
1__mddir & cd to the dir
2__create git repository by CMD cmd:
git init
******************
version management
******************
git add <filename> ____add file to stage
git rm <filename> ____remove file to stage
git commit -m "noticement" ____push stage file to workspace
git push ____push workspace file to master
git log ____view git version info & commit id
git log --pretty=oneline ____oneline display of "git log"
git log --graph --pretty=oneline --abbrev-commit ____get log with branch message display by graphics
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
____alise CMD(git log), and config log colorful
git reflog ____display all your operation of version, expect "push".You can find forward version which has been gone back
******************
version go back
******************
git reset HEAD <filename> ____undo stage file, it will not change actually file, just clean stage file which is not visible
git reset --hard HEAD ____go to current version, commit & before any change
git reset --hard HEAD~ ____go to last version
git reset --hard HEAD~~ ____go to last 2 version
git reset --hard HEAD~10 ____go to last 10 version
git reset --hard <commit id> ____go to corresponding commit id version
git checkout -- <filename> ____undo modify, all modify back to stage or workspace
******************
remote repository
******************
1__generate SSH key by CMD:
ssh-keygen -t rsa -C "<youremail@example.com>"
dir .ssh will generate 2 file: id_t=rsa & id_rsa.pub, id_rsa is private key should be secret, id_rsa.pub is public key to identify your SSH info
2__add ssh key into github
login in github,
choose "account setting"
"add ssh key": id_rsa.pub file
comfirm
3__create new repository
login in github,
"new repository"
add repository name
create
4__link repository
CMD:
git remote add origin git@github.com:<github_name>/<repository_name>.git
5__first time to push master branch
CMD:
git push -u origin master
******************
repository clone
******************
CMD:
git clone git@github.com:<github_name>/<repo_name>.git
the cmd will auto create a repo dir
******************
branch management
******************
git checkout -b <branch_name> ____create new branch & switch to it
= git branch <branch_name> ____create new branch
+ git checkout <branch_name> ____switch to branch
git checkout -b origin/<branch_name> ____create new origin branch at local, and switch to it
git branch ____show branch, the curent branch is tag with *
git branch -d <branch_name> ____delete branch
git merge <branch_name> ____merge branch: curent branch & <branch_name>, if branch merge, info will auto display at raw files which are conflicted
git merge --no-ff -m "merge with no-ff" dev ____merge current branch to master without "fast forward" mode:keep branch history in log
******************
remote management
******************
git push ____(Not recommended)useful only when you just have one branch local
git push origin <branch_name> ____push local branch to origin
git remote ____show remote info
git remote -v ____show more detal of remote
git pull ____show remote push info
git rebase ____rebase branch to one
conflict test 1:1_2
conflict test 2:2_2
******************
about conflict
******************
conflict:
1__two branch medified same file at same place or close place
no conflict:
1__two branch medified same file at dif place, and nor close to each other
2__two branch medified dif files
******************
General branch management strategies
******************
__________________________________master for main branch to release
|_____|_________|_________|___dev for beta branch to test
| |______|__|______|________<developer> for private branch to developer
|________|_________|________<feature> for actual feature branch downstream of <developer> or team
******************
break and recovery
******************
git stash ____stash files, even those not add; stash is a FILO not FIFO.
git stash apply ____recover from last stash
git stash drop ____remove stash
git stash pop ____recover from stash and remove stash
******************
tag
******************
git tag <tag_name> ____tag HEAD with <tag_name>
git tag ____show all tag info
git tag <tag_name> <version_number> ____tag <version_number> with <tag_name>
git tag -a <tag_name> -m "tag_description" ____tag <version_number> with <tag_name> & <tag_description>
git show <tag_name> ____show tag description of <tag_name>
git tag -d <tag_name> ____delete tag
git push origin <tag_name> ____push <tag_name> to remote
git push origin --tags ____push all tags to remote
git push origin :refs/tags/<tag_name> ____delete remote <tag_name>
******************
ignore
******************
1__create a file: .gitignore, and write the <file_name> in it, you will not add <file_name>
2__this use to ignore some trash file/mid process file/secret file
CMD:
git add -f <file_name> ____force to add ignore file
******************
alise
******************
git config (--global) alise.<alisement> <raw_CMD> ____alise <raw_CMD> to <alisement>, (--global) means useful for curent uesr, if no, CMD just useful for curent project
******************
build a private server
******************
TBD