@@ -233,15 +233,19 @@ git ls-files --others -i --exclude-standard
233
233
```
234
234
235
235
## 强制删除untracked的文件
236
- 清空工作区untracked的文件
236
+ 可以用来删除新建的文件。如果不指定文件文件名,则清空所有工作的untracked文件。` clean ` 命令,** 注意两点** :
237
+ 1 . clean后,删除的文件无法找回
238
+ 2 . 不会影响tracked的文件的改动,只会删除untracked的文件
239
+
237
240
``` sh
238
- git clean -f
241
+ git clean < file_name > -f
239
242
```
240
243
241
244
## 强制删除untracked的目录
242
- 清空工作区untracked的目录
245
+ 可以用来删除新建的目录,** 注意** :这个命令也可以用来删除untracked的文件。详情见上一条
246
+
243
247
``` sh
244
- git clean -df
248
+ git clean < directory_name > -df
245
249
```
246
250
247
251
## 重命名分支
@@ -265,62 +269,31 @@ git bundle create <file> <branch-name>
265
269
git clone repo.bundle < repo-dir> -b < branch-name>
266
270
```
267
271
268
- ## Ignore one file on commit (e.g. Changelog).
269
- ``` sh
270
- git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog
271
- ```
272
-
273
- ## Stash changes before rebasing
272
+ ## 执行rebase之前自动stash
274
273
``` sh
275
274
git rebase --autostash
276
275
```
277
276
278
- ## Fetch pull request by ID to a local branch
277
+ ## 从远程仓库根据ID,拉下某一状态,到本地分支
279
278
``` sh
280
279
git fetch origin pull/< id> /head:< branch-name>
281
280
```
282
281
283
-
284
- __ Alternatives:__
285
- ``` sh
286
- git pull origin pull/< id> /head:< branch-name>
287
- ```
288
-
289
- ## Show the most recent tag on the current branch.
282
+ ## 展示当前分支的最近的tag
290
283
``` sh
291
284
git describe --tags --abbrev=0
292
285
```
293
286
294
- ## Show inline word diff.
287
+ ## 详细展示一行中的修改
295
288
``` sh
296
289
git diff --word-diff
297
290
```
298
291
299
- ## Don’t consider changes for tracked file.
300
- ``` sh
301
- git update-index --assume-unchanged < file_name>
302
- ```
303
-
304
- ## Undo assume-unchanged.
305
- ``` sh
306
- git update-index --no-assume-unchanged < file_name>
307
- ```
308
-
309
- ## Clean the files from ` .gitignore ` .
292
+ ## 清除` .gitignore ` 文件中记录的文件
310
293
``` sh
311
294
git clean -X -f
312
295
```
313
296
314
- ## Restore deleted file.
315
- ``` sh
316
- git checkout < deleting_commit> ^ -- < file_path>
317
- ```
318
-
319
- ## Restore file to a specific commit-hash
320
- ``` sh
321
- git checkout < commit-ish> -- < file_path>
322
- ```
323
-
324
297
## 展示所有alias和configs.
325
298
``` sh
326
299
git config --list
@@ -336,31 +309,6 @@ git status --ignored
336
309
git log Branch1 ^Branch2
337
310
```
338
311
339
- ## reuse recorded resolution, record and reuse previous conflicts resolutions.
340
- ``` sh
341
- git config --global rerere.enabled 1
342
- ```
343
-
344
- ## Open all conflicted files in an editor.
345
- ``` sh
346
- git diff --name-only | uniq | xargs $EDITOR
347
- ```
348
-
349
- ## Count unpacked number of objects and their disk consumption.
350
- ``` sh
351
- git count-objects --human-readable
352
- ```
353
-
354
- ## Prune all unreachable objects from the object database.
355
- ``` sh
356
- git gc --prune=now --aggressive
357
- ```
358
-
359
- ## Instantly browse your working repository in gitweb.
360
- ``` sh
361
- git instaweb [--local] [--httpd=< httpd> ] [--port=< port> ] [--browser=< browser> ]
362
- ```
363
-
364
312
## 在commit log中显示GPG签名
365
313
``` sh
366
314
git log --show-signature
@@ -377,104 +325,41 @@ git config --global --unset <entry-name>
377
325
git checkout --orphan < branch_name>
378
326
```
379
327
380
- ## Extract file from another branch.
328
+ ## 展示任意分支某一文件的内容
381
329
``` sh
382
330
git show < branch_name> :< file_name>
383
331
```
384
332
385
- ## List only the root and merge commits.
386
- ``` sh
387
- git log --first-parent
388
- ```
389
-
390
- ## Change previous two commits with an interactive rebase.
391
- ``` sh
392
- git rebase --interactive HEAD~2
393
- ```
394
-
395
- ## List all branch is WIP
396
- ``` sh
397
- git checkout master && git branch --no-merged
398
- ```
399
-
400
- ## Find guilty with binary search
401
- ``` sh
402
- git bisect start # Search start
403
- git bisect bad # Set point to bad commit
404
- git bisect good v2.6.13-rc2 # Set point to good commit|tag
405
- git bisect bad # Say current state is bad
406
- git bisect good # Say current state is good
407
- git bisect reset # Finish search
408
-
409
- ```
410
-
411
- ## Bypass pre-commit and commit-msg githooks
412
- ``` sh
413
- git commit --no-verify
414
- ```
415
-
416
- ## List commits and changes to a specific file (even through renaming)
417
- ``` sh
418
- git log --follow -p -- < file_path>
419
- ```
420
-
421
- ## Clone a single branch
333
+ ## clone下来指定的单一分支
422
334
``` sh
423
335
git clone -b < branch-name> --single-branch https://github.com/user/repo.git
424
336
```
425
337
426
- ## Create and switch new branch
338
+ ## 创建并切换到该分支
427
339
``` sh
428
340
git checkout -b < branch-name>
429
341
```
430
342
431
-
432
- __ Alternatives:__
433
- ``` sh
434
- git branch < branch-name> && git checkout < branch-name>
435
- ```
436
-
437
- ## Ignore file mode changes on commits
343
+ ## 关闭Ignore文件的功能
438
344
``` sh
439
345
git config core.fileMode false
440
346
```
441
347
442
- ## Turn off git colored terminal output
443
- ``` sh
444
- git config --global color.ui false
445
- ```
446
-
447
- ## specific color settings
448
- ``` sh
449
- git config --global < specific command e.g branch, diff> < true, false or always>
450
- ```
348
+ ## 展示本地所有的分支的commit
349
+ 最新的放在最上面
451
350
452
- ## Show all local branches ordered by recent commits
453
351
``` sh
454
352
git for-each-ref --sort=-committerdate --format=' %(refname:short)' refs/heads/
455
353
```
456
354
457
- ## Find lines matching the pattern (regex or string) in tracked files
458
- ``` sh
459
- git grep --heading --line-number ' foo bar'
460
- ```
355
+ ## 在commit log中查找相关内容Search Commit log across all branches for given text
356
+ 通过grep查找,given-text:所需要查找的字段
461
357
462
- ## Clone a shallow copy of a repository
463
- ``` sh
464
- git clone https://github.com/user/repo.git --depth 1
465
- ```
466
-
467
- ## Search Commit log across all branches for given text
468
358
``` sh
469
359
git log --all --grep=' <given-text>'
470
360
```
471
361
472
- ## Get first commit in a branch (from master)
473
- ``` sh
474
- git log master..< branch-name> --oneline | tail -1
475
- ```
476
-
477
- ## 把暂存区的内容放到工作区中
362
+ ## 把暂存区的指定file放到工作区中
478
363
``` sh
479
364
git reset < file-name>
480
365
```
0 commit comments