git常用命令

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

git init --bare test01.server

git clone获取一个新的项目

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

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

[root@xxx test01.work]# git add .
[root@xxx test01.work]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   test.sh
#
[root@xxx test01.work]# git commit -a -m "201509141437"
[master (root-commit) 4709391] 201509141437
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 test.sh
#本例中远端仓库在本地,第一次提交需要指定路径和分支
[root@xxx test01.work]# 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分支
[root@xxx test01.work]# git push
Everything up-to-date

git log查看提交历史

#查看最新的一次提交记录
[root@xxx test01.work]# git log -1
commit 47093915f04ddfbaa8da68b64ad60a4d945d2f4c
Author:
Date:   Mon Sep 14 14:37:41 2015 +0800

    201509141437

git show查看修改信息

[root@xxx test01.work]# 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
#可以只显示文件名和状态
[root@xxx test01.work]# git show 47093915f04ddfbaa8da --name-status
commit 47093915f04ddfbaa8da68b64ad60a4d945d2f4c
Author:
Date:   Mon Sep 14 14:37:41 2015 +0800

    201509141437

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

    201509141437

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

    201509141437

test.sh

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

#查看版本之间的详细差异
[root@xxx test01.work]# 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
#只显示文件名
[root@xxx test01.work]# git diff e57333269e043817c 47093915f04ddf --name-only
a.sh
test.sh
#显示文件名和状态
[root@xxx test01.work]# git diff e57333269e043817c 47093915f04ddf --name-status
D       a.sh
M       test.sh

当下能想起来的就这些了,如果还有常用的命令在补,文章出处:http://www.xiaomastack.com/2015/09/14/git-command/

发表评论:

你的电子邮件地址将不会被公开.

+ 34 = 42