137
137
2 . 暂存区:输入命令:` git add 改动的文件名 ` ,此次改动就放到了‘暂存区’
138
138
3 . 本地仓库:输入命令:` git commit 此次修改的描述 ` ,此次改动就放到了’本地仓库’,每个commit,我叫它为一个‘版本’
139
139
4 . 远程仓库:输入命令:` git push 远程仓库 ` ,此次改动就放到了‘远程仓库’(github等)
140
+ 5 . commit-id:
140
141
141
- ## Everyday Git in twenty commands or so
142
- ``` sh
143
- git help everyday
144
- ```
145
-
146
- ## Show helpful guides that come with Git
142
+ ## 展示帮助信息
147
143
``` sh
148
144
git help -g
149
145
```
@@ -178,11 +174,6 @@ git diff --cached
178
174
git diff HEAD
179
175
```
180
176
181
- ## List all branches that are already merged into master
182
- ``` sh
183
- git branch --merged master
184
- ```
185
-
186
177
## 快速切换分支
187
178
``` sh
188
179
git checkout -
@@ -229,39 +220,40 @@ git tag -d <tag-name>
229
220
git push origin :refs/tags/< tag-name>
230
221
```
231
222
232
- ## Undo local changes with the last content in head
223
+ ## 放弃工作区的修改
233
224
``` sh
234
- git checkout -- < file_name>
225
+ git checkout < file_name>
235
226
```
236
227
237
- ## Revert: Undo a commit by creating a new commit
228
+ 放弃所有修改:
238
229
``` sh
239
- git revert < commit-ish >
230
+ git checkout .
240
231
```
241
232
242
- ## Reset: Discard commits, advised for private branch
233
+ ## 回到某一个commit的状态,并重新增添一个commit
243
234
``` sh
244
- git reset < commit-ish >
235
+ git revert < commit-id >
245
236
```
246
237
247
- ## Reword the previous commit message
238
+ ## 回到某个commit的状态,并删除后面的commit
239
+ 和revert的区别:reset命令会抹去某个commit id之后的所有commit
248
240
``` sh
249
- git commit -v --amend
241
+ git reset < commit-id >
250
242
```
251
243
252
- ## See commit history for just the current branch
244
+ ## 修改上一个commit的描述
253
245
``` sh
254
- git cherry -v master
246
+ git commit --amend
255
247
```
256
248
257
- ## Amend author.
249
+ ## 查看commit历史
258
250
``` sh
259
- git commit --amend --author= ' Author Name <email@address.com> '
251
+ git log
260
252
```
261
253
262
- ## Reset author, after author has been changed in the global config.
254
+ ## 修改作者名
263
255
``` sh
264
- git commit --amend --reset- author --no-edit
256
+ git commit --amend --author= ' Author Name <email@address.com> '
265
257
```
266
258
267
259
## 修改远程仓库的url
@@ -286,113 +278,65 @@ git branch -a
286
278
git branch -r
287
279
```
288
280
289
- ## Stage parts of a changed file, instead of the entire file
290
- ``` sh
291
- git add -p
292
- ```
293
-
294
- ## Get git bash completion
295
- ``` sh
296
- curl http://git.io/vfhol > ~ /.git-completion.bash && echo ' [ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~ /.bashrc
297
- ```
298
-
299
281
## 查看两个星期内的改动
300
282
``` sh
301
283
git whatchanged --since=' 2 weeks ago'
302
284
```
303
285
304
- ## See all commits made since forking from master
286
+ ## 把A分支的某一个commit,放到B分支上
287
+ 这个过程需要` cherry-pick ` 命令,[ 参考] ( http://sg552.iteye.com/blog/1300713#bc2367928 )
305
288
``` sh
306
- git log --no-merges --stat --reverse master..
289
+ git checkout < branch-name > && git cherry-pick < commit-id >
307
290
```
308
291
309
- ## Pick commits across branches using cherry-pick
310
- ``` sh
311
- git checkout < branch-name> && git cherry-pick < commit-ish>
312
- ```
292
+ ## 给git命令起别名
293
+ 简化命令
313
294
314
- ## Find out branches containing commit-hash
315
295
``` sh
316
- git branch -a --contains < commit-ish>
317
- ```
296
+ git config --global alias.< handle> < command>
318
297
298
+ 比如:git status 改成 git st,这样可以简化命令
319
299
320
- __ Alternatives:__
321
- ``` sh
322
- git branch --contains < commit-ish>
323
- ```
324
-
325
- ## Git Aliases
326
- ``` sh
327
- git config --global alias.< handle> < command>
328
300
git config --global alias.st status
329
301
```
330
302
331
- ## Saving current state of tracked files without commiting
303
+ ## 存储当前的修改,但不用提交commit
304
+ 详解可以参考[ 廖雪峰老师的git教程] ( http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137602359178794d966923e5c4134bc8bf98dfb03aea3000 )
332
305
``` sh
333
306
git stash
334
307
```
335
308
336
-
337
- __ Alternatives: __
309
+ ## 保存当前状态,包括untracked的文件
310
+ untracked文件:新建的文件
338
311
``` sh
339
- git stash save
312
+ git stash -u
340
313
```
341
314
342
- ## Saving current state including untracked files
343
- ``` sh
344
- git stash save -u
345
- ```
346
-
347
-
348
- __ Alternatives:__
349
- ``` sh
350
- git stash save --include-untracked
351
- ```
352
-
353
- ## Show list of all saved stashes
315
+ ## 展示所有stashes
354
316
``` sh
355
317
git stash list
356
318
```
357
319
358
- ## Apply any stash without deleting from the stashed list
320
+ ## 回到某个stash的状态
359
321
``` sh
360
322
git stash apply < stash@{n}>
361
323
```
362
324
363
- ## Apply last stashed state and delete it from stashed list
325
+ ## 回到最后一个stash的状态,并删除这个stash
364
326
``` sh
365
327
git stash pop
366
328
```
367
329
368
-
369
- __ Alternatives:__
370
- ``` sh
371
- git stash apply stash@{0} && git stash drop stash@{0}
372
- ```
373
-
374
- ## Delete all stored stashes
330
+ ## 删除所有的stash
375
331
``` sh
376
332
git stash clear
377
333
```
378
334
379
-
380
- __ Alternatives:__
381
- ``` sh
382
- git stash drop < stash@{n}>
383
- ```
384
-
385
- ## Grab a single file from a stash
335
+ ## 从stash中拿出某个文件的修改
386
336
``` sh
387
337
git checkout < stash@{n}> -- < file_path>
388
338
```
389
339
390
-
391
- __ Alternatives:__
392
- ``` sh
393
- git checkout stash@{0} -- < file_path>
394
- ```
395
-
396
340
## Show all tracked files
397
341
``` sh
398
342
git ls-files -t
@@ -666,11 +610,6 @@ git rebase -i --autosquash
666
610
git commit --only < file_path>
667
611
```
668
612
669
- ## Interactive staging.
670
- ``` sh
671
- git add -i
672
- ```
673
-
674
613
## 展示忽略的文件
675
614
``` sh
676
615
git status --ignored
0 commit comments