Git命令快速参考
Git
Command Quick Reference/
E/ f, q0 c1 n( L- P9 ~( G6 O
;
c6 I9 Z& J6 Z3 n' V2 G1 E! X
本附录为Git常见命令快速参考。每节介绍一种操作类型。9
^4 c: l1 m# L5 X4 Q! {
这里会列出很多命令,而相应的解释却不多。对于还不熟悉Git的读者,可回头翻阅第1章“Git的版本控制之道”(第3页)。
*
K( V3 ?! m/ x: u; m# J, ^6 Z
A.1安装和初始化.
?+ F/ i }0 n) V k/ d* ?
Setup
and Initialization7
P+ C. z! r- q/ m
,
o3 v2 d% R4 t2 ]
在使用Git之前,须要先进行配置。在使用一个新的版本库之前,须要先初始化。本节介绍与Git设置和初始化相关的命令。
配置全局用户名和电子邮件地址
prompt> git
config --global user.name "Your Name"
prompt> git
config --global user.email "you@example.com"
为特定的版本库配置用户名和电子邮件地址+
x+ s( _0 F. o9 q; s
,
k- X8 [2 V0 w% U
注意:你可以为每个版本库单独设置用户名和邮件地址。这使得用户可在不同项目中使用不同的用户名和/或不同的邮件地址。
prompt> cd
/path/to/repo
prompt> git
config user.name "Your Name"
prompt> git
config user.email you@example.com4
v1 e; k! [( t* V6 ~9 Z5 y) p% R# i
在命令行中使用不同颜色显示不同内容
prompt> git
config --global color.ui "auto"
初始化新版本库
prompt> mkdir
/path/to/repo
prompt> cd
/path/to/repo
prompt> git
init
Initialized
empty Git repository in /path/to/repo/.git/
prompt>6
|* {* D- \3 d0 c y/ C
...
create file(s) for first commit ...
prompt> git
add ..
o6 n) d' n( y6 H. E$ f R
prompt> git
commit -m 'initial import'
Created
initial commit bdebe5c: initial import
1 files changed, 1 insertions(+), 0 deletions(-):
U4 t( X( Q' s0 v5 v! I
5
F+ W- Z5 `2 A, b0 J# _) `
create mode 100644 <some file>
+
q3 Q* ~. ?5 }/ p( c; a- d
克隆版本库'
|$ i, W/ {& `, `5 J
prompt> git
clone <repository url>3
v( e: x. O. T+ ~
Initialize
repo/.git,
x O9 b( l+ l) n7 r8 S5 A3 f
Initialized
empty Git repository in /work/<remote repository>/.git/3
R+ d( E( y6 Z5 f
将目录中的内容纳入Git版本控制+
|$ X9 M. ?$ P/ b; X/ b
prompt> cd
/path/to/existing/directory
prompt> git
init
Initialized
empty Git repository in /path/to/existing/directory/.git/
prompt> git
add .
prompt> git
commit -m "initial import of some project"(
x2 [- q) q4 ]: s: S
4
[9 {/ j6 b Y
在本地版本库中设置远程版本库的别名,
N( x7 a4 l+ I" w# U
...
from within the repository directory ...:
o8 `7 _8 ~& y1 {2 J# y& K5 L
prompt> git
remote add <remote repository> <repository url>*
K8 I7 Y- R% t0 v6 _0 H
%
W; H2 A) a `' T$ |3 @0 X9 o
/
K S3 A* c" L2 s2 C, {+ \
A.2 日常操作7
h- V5 s# }. j$ g$ D% n
Normal
Usage%
g6 S8 y# f: V2 O8 N* |2 H7 _