-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcommand_help_git.txt
More file actions
299 lines (228 loc) · 11.1 KB
/
command_help_git.txt
File metadata and controls
299 lines (228 loc) · 11.1 KB
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
k########git常用命令################################################
###get a repository#####
增加远程地址的时候带上密码也是可以的。(推荐)
http://yourname:password@git.oschina.net/name/project.git
###Create a new repository o#######################
touch README.md //创建一个文件。文件名叫:README.md;
git init
git add README.md //这里是添加README这个文件;
git commit -m "first commit"
git remote add origin https://github.com/songbo/test.git
git push -u origin master
###Push an existing repository #####################
git remote add origin https://github.com/songbo/test.git
git push -u origin master
###git branch常用命令################################
//1.1查看远程分支
$ git branch -a
* br-2.1.2.2 分支1
master 主分支
test 分支2
前面带*号的代表你当前工作目录所处的分支
//1.2查看本地分支
$ git branch
//1.3创建分支
$ git branch branchname
//1.4本地创建并切换到新分支 如果有就切换 没哟就创建
$ git checkout -b branchname
//1.5推送分支 到远程
$ git push origin branchname
//1.6删除本地test分支
$ git br -d test or git branch -d test
//1.7 删除远程分支 两种方法
删除远程分支
$ git branch -r -d origin/branch-name
$ git push origin :branch-name
###1.6 五分支模型下的分支的合并与创建
$ git checkout -b myfeature develop
##################Switched to a new branch "myfeature AT develop branch
$ git checkout develop
##################Switched to branch 'develop'
$ git merge --no-ff myfeature
##################Updating ea1b82a..05e9557
##################(Summary of changes)
$ git branch -d myfeature
##################Deleted branch myfeature (was 05e9557).
$ git push origin develop
###1.7 发布release
$ git checkout -b release-1.2 develop
###################Switched to a new branch "release-1.2"
$ ./bump-version.sh 1.2
###################Files modified successfully, version bumped to 1.2.
$ git commit -a -m "Bumped version number to 1.2"
##################[release-1.2 74d9424] Bumped version number to 1.2
##################1 files changed, 1 insertions(+), 1 deletions(-)
$ git checkout master
###################Switched to branch 'master'
$ git merge --no-ff release-1.2
####################Merge made by recursive.
###################(Summary of changes)
$ git tag -a 1.2
###git tag 常用命令##############################
//2.1查看tag
git tag -l //本地
git tag -a //远程
//2.2创建tag
git tag -a 0.0.1 -m "注释"
//2.3 tag推送到远程
git push origin 0.0.1
//推送所有tags
git push origin --tags
//2.4删除本地tag
git tag -d 0.0.1
//2.5删除远程tag
git push origin :0.0.1
//也可以这样
git push origin --delete tag 0.0.1
7 ###git reset 回滚与撤销 变基 常用命令##############################$
git commit --amend
重做上一次commit,并包括指定文件的新变化。
合并缓存区的修改和最近的一次commit,并尝试重新commit。可以理解为,用一个全新的commit整个替换了最近一次commit。
如果缓存区没有内容, 可以用来编辑上一次的commit描述。
不要对一个公共的commit使用amend。如果amend了一个被其他开发者使用的commit, 可能会严重影响其他开发者。
git checkout
git checkout -- <file> # 丢弃工作区的修改
git reset HEAD <file> # 撤销暂存区的修改,重新放回工作区
git rebase
重新定义分支的起点,也就是将当前分支从一个commit移动到另一个commit作为起点。
分支上的老commit将被删除,保持了项目历史的干净。建议不要在一个公共的分支中使用rebase。
git rebase <base> # 将<base>做为当前分支的新起点, <base>可以是任何一种commit引用(如ID,branch name,tag,HEAD~N等)。
git rebase -i <base> # 交互式地将<base>做为当前分支的新起点,过程中可以对要rebase的commit做一定的修改。
git reset
用来撤销本地的修改。建议不要reset一个公共的项目历史。
git reset # 回退版本库到上一个commit的状态, 工作区不变。
git reset <commit> # 回退版本库到指定的<commit>, 工作区不变。
git reset --hard # 回退版本库和工作区到上一次commit的状态。 --hard表明覆盖所有的修改, 而且是不可逆的, 因此使用之前要谨慎。
git reset --hard <commit> # 回退版本库和工作区到指定的<commit>。
回退到上个版本:git reset --hard HEAD^ git reset --hard HEAD~
回退到上上个版本:git reset --hard HEAD^^ git reset --hard HEAD~1
以此类推。
########git submodule########
##添加子仓库
$ git submodule add <仓库地址> <本地路径>
$ git submodule add ssh://git@10.2.237.56:23/dennis/sub.git lib
## 子仓库检出(checkout)
// 初始化本地配置文件
$ git submodule init
// 检出父仓库列出的commit
$ git submodule update
## git 拉取所有子模块
git submodule foreach git pull
##更新所有子库
git submodule foreach --recursive git submodule update
##更新子模块
git submodule update
git submodule foreach git submodule update
###git分支实战 ##############
###Git鼓励大量使用分支:
##查看分支:
git branch
##创建分支:
git branch <name>
##切换分支:
git checkout <name>
##创建+切换分支:
git checkout -b <name>
##合并某分支到当前分支:
git merge <name>
##删除分支:
git branch -d <name>
###git分支实战:分支管理策略 ##################
##通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息。
##如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的commit,这样,从分支历史上就可以看出分支信息。
#下面我们实战一下--no-ff方式的git merge:
#合并分支时,加上--no-ff参数就可以用普通模式合并,合并后的历史有分支,能看出来曾经做过合并,而fast forward合并就看不出来曾经做过合并
###子模块
##添加子模块
git submodule add -b master http://ph.benemind.com/diffusion/129/skhome.git submodules/SKHome/
##更新子模块
git submodule foreach git pull ##更新
git submodule foreach 'git checkout -f' ##强制更新
#储藏与清理
#有时,当你在项目的一部分上已经工作一段时间后,所有东西都进入了混乱的状态,而这时你想要切换到另一个分支做一点别的事情。 问题是,你不想仅仅因为过会儿回到这一点而为做了一半的工作创建一次提交。 针对这个问题的答案是 git stash 命令。
#储藏会处理工作目录的脏的状态 - 即,修改的跟踪文件与暂存改动 - 然后将未完成的修改保存到一个栈上,而你可以在任何时候重新应用这些改动。
$ git status
#Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
# modified: index.html
#Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# modified: lib/simplegit.rb
#现在想要切换分支,但是还不想要提交之前的工作;所以储藏修改。 将新的储藏推送到栈上,运行 git stash 或 git stash save:
$ git stash
#Saved working directory and index state \
# "WIP on master: 049d078 added the index file"
#HEAD is now at 049d078 added the index file
#(To restore them type "git stash apply")
#工作目录是干净的了:
$ git status
# On branch master
#nothing to commit, working directory clean
#在这时,你能够轻易地切换分支并在其他地方工作;你的修改被存储在栈上。 要查看储藏的东西,可以使用 git stash list:
$ git stash list
#stash@{0}: WIP on master: 049d078 added the index file
#stash@{1}: WIP on master: c264051 Revert "added file_size"
#stash@{2}: WIP on master: 21d80a5 added number to log
#在本例中,有两个之前做的储藏,所以你接触到了三个不同的储藏工作。 可以通过原来 stash 命令的帮助提示中的命令将你刚刚储藏的工作重新应用:git stash apply。 如果想要应用其中一个更旧的储藏,可以通过名字指定它,像这样:git stash apply stash@{2}。 如果不指定一个储藏,Git 认为指定的是最近的储藏:
$ git stash apply
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: index.html
# modified: lib/simplegit.rb
#
#可以看到 Git 重新修改了当你保存储藏时撤消的文件。 在本例中,当尝试应用储藏时有一个干净的工作目录,并且尝试将它应用在保存它时所在的分支;但是有一个干净的工作目录与应用在同一分支并不是成功应用储藏的充分必要条件。 可以在一个分支上保存一个储藏,切换到另一个分支,然后尝试重新应用这些修改。 当应用储藏时工作目录中也可以有修改与未提交的文件 - 如果有任何东西不能干净地应用,Git 会产生合并冲突。
#文件的改动被重新应用了,但是之前暂存的文件却没有重新暂存。 想要那样的话,必须使用 --index 选项来运行 git stash apply 命令,来尝试重新应用暂存的修改。 如果已经那样做了,那么你将回到原来的位置:
$ git stash apply --index
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: index.html
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: lib/simplegit.rb
#
#应用选项只会尝试应用暂存的工作 - 在堆栈上还有它。 可以运行 git stash drop 加上将要移除的储藏的名字来移除它:
$ git stash list
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"
stash@{2}: WIP on master: 21d80a5 added number to log
$ git stash drop stash@{0}
Dropped stash@{0} (364e91f3f268f0900bc3ee613f9f733e82aaed43)
### 游离分支解决方案
# 1.查看所有提交日志 找到游离的commit_id
$ git reflog # 找到游离的commit_id
# 2.根据commit_id 新建一个分支
git branch brenchName commit_id
# 3.切换到主分支 合并新建的分支到主分支上
###git 配置相关以及密码相关操作
# 查看配置
git config --global --list
# vim修改
vim ~/.gitconfig
# 去除缓存
git config --unset-all credential.helper
# mac 缓存密码 到钥匙串 mac
git config --global credential.helper osxkeychain
# windows 缓存密码
git config --global credential.helper wincred
# 缓存到磁盘
git config --global credential.helper store
# 解绑缓存 git credential-manager uninstall
# 重置缓存
git config --global --unset credential.helper
git config --system --unset credential.helper
### git代理
#设置代理
git config --global https.proxy 'socks5://127.0.0.1:1080'
git config --global http.proxy 'socks5://127.0.0.1:1080'
#去除代理
git config --global --unset https.proxy
git config --global --unset http.proxy
# 解决github 无法clone 问题 更新github 地址
参考此文章https://www.cnblogs.com/iupoint/p/14552968.html