git常用命令

git一直以来都在用,用到的命令总共就那么几个,没有用到的很多,不熟悉的更多,先把用过的记录下:
git init –bare创建一个空项目(仓库)

1
git init --bare test01.server

git clone获取一个新的项目

1
git clone /tmp/test01.server/ test01.work

git add,git status,git commit,git push分别是向本地仓库增加文件、查看文件最新状态、提交文件到本地仓库、提交文件到中心(远端)仓库

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
$ git add .
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: test.sh
#
$ git commit -a -m "201509141437"
[master (root-commit) 4709391] 201509141437
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 test.sh
#本例中远端仓库在本地,第一次提交需要指定路径和分支
$ git push /tmp/test01.server/ master
Counting objects: 3, done.
Writing objects: 100% (3/3), 215 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /tmp/test01.server/
* [new branch] master -> master
#以后提交默认是master分支
$ git push
Everything up-to-date

git log查看提交历史

1
2
3
4
5
6
7
#查看最新的一次提交记录
$ git log -1
commit 47093915f04ddfbaa8da68b64ad60a4d945d2f4c
Author:
Date: Mon Sep 14 14:37:41 2015 +0800

201509141437

git show查看修改信息

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
$ git show 47093915f04ddfbaa8da
commit 47093915f04ddfbaa8da68b64ad60a4d945d2f4c
Author:
Date: Mon Sep 14 14:37:41 2015 +0800

201509141437

diff --git a/test.sh b/test.sh
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/test.sh
@@ -0,0 +1 @@
+test
#可以只显示文件名和状态
$ git show 47093915f04ddfbaa8da --name-status
commit 47093915f04ddfbaa8da68b64ad60a4d945d2f4c
Author:
Date: Mon Sep 14 14:37:41 2015 +0800

201509141437

A test.sh
#不加版本号默认显示最新提交记录,A就是新增,M就是有修改,D就是删除等
$ git show --name-status
commit 47093915f04ddfbaa8da68b64ad60a4d945d2f4c
Author:
Date: Mon Sep 14 14:37:41 2015 +0800

201509141437

A test.sh
#也可以只显示文件名
$ git show --name-only
commit 47093915f04ddfbaa8da68b64ad60a4d945d2f4c
Author:
Date: Mon Sep 14 14:37:41 2015 +0800

201509141437

test.sh

git diff比较不同版本之前的差异,参数和git show类似

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#查看版本之间的详细差异
$ git diff e57333269e043817c 47093915f04ddf
diff --git a/a.sh b/a.sh
deleted file mode 100644
index fa49b07..0000000
--- a/a.sh
+++ /dev/null
@@ -1 +0,0 @@
-new file
diff --git a/test.sh b/test.sh
index a6cf9be..9daeafb 100644
--- a/test.sh
+++ b/test.sh
@@ -1,2 +1 @@
test
-new line
#只显示文件名
$ git diff e57333269e043817c 47093915f04ddf --name-only
a.sh
test.sh
#显示文件名和状态
$ git diff e57333269e043817c 47093915f04ddf --name-status
D a.sh
M test.sh

当下能想起来的就这些了,如果还有常用的命令在补。

----------------本文结束 感谢阅读----------------