• Stars
    star
    475
  • Rank 92,465 (Top 2 %)
  • Language
  • License
    Other
  • Created over 6 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

不走寻常路的Git教程

learn-git-the-super-hard-way

GitBook

目录

  1. 创建工作环境git init
  2. 直接操纵对象git commit
  3. 直接操纵引用git branch
  4. 直接操纵索引git add / restore
  5. 直接操纵HEADgit switch
  6. 直接操纵远程git pull / push
  7. 直接操纵mergegit diff / merge
  8. 直接操纵commitgit rebase
  9. 检索与查看历史git log / blame / grep
  10. 邪恶的submodulegit submodule
  11. 批处理与自动化
  12. 配置和aliasgit config
  13. 单repo多分支工作流
  14. GPG签名
  15. 数据的导入和导出git archive
  16. 数据抢修与急救

本教程还提供了cheatsheet,可以用来复习并检查学习效果。

如果你完全没有听说过cheatsheet里面的任何一条命令,那么你可能需要先学习一些基础教程:入门初级高级。其中高级可以跟本教程同时学习。

如果你已经完全掌握cheatsheet里面的所有命令,那么此教程可能对你来说太过浅显,建议移步Git ReferenceGit源码

学习完本教程以后,你应该掌握了git的全部用法的1%。

备注:git reset/git checkout的详解在第4章。强烈推荐改用功能更强大更直观的git restoregit switch

基本约定

为了更为本质地了解Git,本文会对同一种操作介绍多种不同的实现方法。 下表描述了不同使用场景下应该如何选择最适合的实现方法。

等级 含义 使用场景
Lv0 纯粹手工实现,完全不使用Git命令行 学习Git内部结构时
Lv1 使用底层Git命令行配合手工实现 实现极为特殊的Git操作时
Lv2 使用底层Git命令行实现 实现非常规Git操作时
Lv3 使用常规Git命令行实现 日常使用
Lv4 Git Alias 对Git进行扩展,日常使用
Lv5 编写脚本调用Git命令行 对Git进行非常规扩展,偶尔使用

Git命令行基础

全局命令行参数

  • cwd默认为.,表示先cd到那里再运行后续命令
  • work-tree默认为GIT_WORK_TREE或者.,但并非所有命令都涉及worktree
  • git-dir默认为GIT_DIR或者./.git
    • 若./.git是目录,则就以该目录为repo
    • 若./.git是文件,则以该文件内容(一般会是绝对路径)为repo
git [-C <cwd>] [--git-dir=<repo>] [--work-tree=<worktree>] <command> [args]

具体Git命令的参数

大部分命令的参数列表遵循以下格式:

  • object是对象的表达式
    • 一般由引用、对象SHA1、^、~、:等构成
    • 完整列表参见git rev-parse(Lv2)
  • path是路径
  • --在不引起歧义的情况下可以省略

注意:是否存在<path>参数可能对语义有本质的影响

git <command> [options] [<object>]
git <command> [options] [<object>] -- [<path>]

Git命令列表

本教程涵盖所有的Git常用命令和一半以上的Git非常用命令, 参见Roadmap

License

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

More Repositories

1

draw.io-export

Convert draw.io xml to pdf/png within command line. (diagrams.net)
JavaScript
63
star
2

graphql-advanced-projection

Fully customizable Mongoose/MongoDB projection generator.
JavaScript
46
star
3

ttyssh

ssh with tty (serial port) forwarding
Shell
39
star
4

git-get

Blazingly fast git clone alternative
Shell
36
star
5

ProfessionalAccounting

Accounting software with debit and credit. 使用借贷记帐法的记账软件
C#
27
star
6

hub-sync

Sync your github forks without git.
JavaScript
24
star
7

Deep-DarkFantasy

Global Dark Mode for ALL apps on ANY platforms.
Verilog
16
star
8

creepy-git-repo

A git repo that is creepy
15
star
9

why-i-gave-up-using-windows

全方位控诉Windows的使用和开发体验
12
star
10

copy-bibtex-to-clipboard

A Chrome extension that boost your paper writing (especially the literature review part).
JavaScript
11
star
11

c

c for cook: 根据食材列表自动推荐菜谱
JavaScript
10
star
12

MineSweeperProb

A deterministic Minesweeper solver
C++
7
star
13

no-evil-eol-newline

Hide the last 'new line' in Atom, just like vim does.
JavaScript
7
star
14

e-curtain

Minimalistic IoT on Raspberry Pi, C++, Matlab/Simulink, Rust, JavaScript
C++
6
star
15

b1f6c1c4

⇑ Detailed list of my repos inside. 点进来瞧瞧吧~
6
star
16

IPA-JFK

IPA narrow transcription of English words in New York City accent
JavaScript
6
star
17

remote-exec

Run command on remote machine using sshfs
Shell
6
star
18

cp-mv-paste

Two-step file copy/move. Specify source file(s) in one command, cd to another directory, paste there.
Shell
5
star
19

cpp-create-objects

How many ways to create object(s) in C++?
C++
5
star
20

jest-mongoose

Mongoose integration test made easy and terse.
JavaScript
5
star
21

shared-git-config

Keep your git config synchronized across different computers.
4
star
22

unfk

Remove all f**ks in your git commit history
Shell
4
star
23

git-fancy-push

The Ultimate Solution towards "shallow update not allowed" in git push
Shell
3
star
24

ansys-moe

Computer-automated Design (CautoD) System 自动化设计系统
JavaScript
3
star
25

pythoness

Check how pythonic a Github user is.
JavaScript
3
star
26

ajnin

A Beautiful, Distributive Ninja generator
C++
3
star
27

git-suir

git submodule update --init --recursive
Shell
3
star
28

b1cal

Minimal web-based calendar.
JavaScript
2
star
29

findbug

Locate bug(s) for ANY program with YES/NO feedback only.
JavaScript
2
star
30

tty-switcher

Switch b/w TTYs (Linux Console), call vlock(1), etc. using Adafruit MACROPAD RP2040
C
2
star
31

CPU

A system with overly simplified MIPS instruction set, with an associated assembler, an debugger, and example programs.
C#
2
star
32

advanced-injection-plugin

Versatile asset injection for html-webpack-plugin.
JavaScript
2
star
33

git-freeze

Convert git submodules to regular directories
Shell
2
star
34

memobird-cli

lpr for memobird
JavaScript
2
star
35

learn-ffmpeg-the-super-easy-way

走寻常路的ffmpeg教程
2
star
36

gradle-run-with-arguments

IntelliJ IDEA plugin: gradlew run --args "..."; System.out.print(...);
Java
2
star
37

ballot

Customizable anonymous online balloting system with ring signature authentication.
JavaScript
2
star
38

naive-garble

Naïve implementation of garbled circuits.
C
2
star
39

shared-vim-config

Keep your vim config synchronized across different computers.
Vim Script
2
star
40

tipa2unicode

Convert LaTeX/TIPA to Unicode IPA
JavaScript
1
star
41

try-react

A react boilerplate
JavaScript
1
star
42

pha

MATLAB
1
star
43

IPA-PEK

IPA narrow transcription of Chinese Mandarin words in Beijing accent
JavaScript
1
star
44

wicky-monads

Pain-reliever for build systems.
C++
1
star
45

CSharpHttpServer

HTTP server written in plain C# (absolutely NOT ASP.NET)
C#
1
star
46

WebLearnCli

C#
1
star
47

protect

Protect a folder from accidental rm -rf
Shell
1
star
48

lecroy_tcp

TCP/IP (VICP) Control of a LeCroy DSO with Linux, mirror of http://optics.eee.nottingham.ac.uk/lecroy_tcp/
C
1
star
49

MWLite

C++
1
star
50

stv

Single transferable vote (STV) computation written in Haskell
Haskell
1
star
51

lab-scpi

Easily configurable lab assistant that logs data using SCPI protocol
C++
1
star
52

git-lad

git add that follows symbolic links
Shell
1
star
53

AlarmSystem

Verilog
1
star
54

Inverter

Invert your screen color when you want to
1
star
55

overwatch-arcade-shortcut

JavaScript
1
star
56

renpy-counter

Estimate the length of your Ren'Py game (i.e. how long an average player plays your game)
JavaScript
1
star