首页 > 其他 > 详细

git基本命令--status, diff, commit, log

时间:2015-10-17 01:49:54      阅读:327      评论:0      收藏:0      [点我收藏+]

git status:

  git status命令的输出十分详细,但其用语有些繁琐。 如果你使用 git status -s 命令或 git status --short 命令,你将得到一种更为紧凑的格式输出:

  

$ git status -s
 M README
MM Rakefile
A  lib/git.rb
M  lib/simplegit.rb
?? LICENSE.txt

 

  • ??:新添加,未跟踪
  • 右M:被修改,未放入暂存区
  • 左M:被修改,放入暂存区
  • A:新添加,放入暂存区

  git status -v 将会显示详细的diff情况。

git diff:

  

a-----, b+++++
git diff
a=staged, b=workspace

git diff --cached
a=repository, b=staged

git diff --cached = git diff --staged
git difftool

  使用 git difftool --tool= 命令来设置 Git Diff 插件。

  比较两个commit之间的区别:(待验证)

$ git diff 07659f9169f6fe 5817e240edb1ed
$ git difftool 07659f9169f6fe 5817e240edb1ed

 

git commit:

  git commit -a 跳过使用暂存区

  git commit --amend  重新提交

$ git commit -m initial commit
$ git add forgotten_file
$ git commit --amend

  git commit --amend 只针对修改上一次的提交,如果想修改前几次的提交,需要配合git rebase -i,详见 git-重写历史

 

git log:

  一个常用的选项是 -p,用来显示每次提交的内容差异。 你也可以加上 -2 来仅显示最近两次提交:

$ git log -p -2

  如果你想看到每次提交的简略的统计信息,你可以使用:

$ git log --stat
commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Mon Mar 17 21:52:11 2008 -0700

    changed the version number

 Rakefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Sat Mar 15 16:40:33 2008 -0700

    removed unnecessary test

 lib/simplegit.rb | 5 -----
 1 file changed, 5 deletions(-)

commit a11bef06a3f659402fe7563abf99ad00de2209e6
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Sat Mar 15 10:31:28 2008 -0700

    first commit

 README           |  6 ++++++
 Rakefile         | 23 +++++++++++++++++++++++
 lib/simplegit.rb | 25 +++++++++++++++++++++++++
 3 files changed, 54 insertions(+)
$ git log --pretty=oneline
ca82a6dff817ec66f44342007202690a93763949 changed the version number
085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 removed unnecessary test
a11bef06a3f659402fe7563abf99ad00de2209e6 first commit
$ git log --pretty=format:"%h - %an, %ar : %s"
ca82a6d - Scott Chacon, 6 years ago : changed the version number
085bb3b - Scott Chacon, 6 years ago : removed unnecessary test
a11bef0 - Scott Chacon, 6 years ago : first commit

%H

提交对象(commit)的完整哈希字串

%h

提交对象的简短哈希字串

%T

树对象(tree)的完整哈希字串

%t

树对象的简短哈希字串

%P

父对象(parent)的完整哈希字串

%p

父对象的简短哈希字串

%an

作者(author)的名字

%ae

作者的电子邮件地址

%ad

作者修订日期(可以用 --date= 选项定制格式)

%ar

作者修订日期,按多久以前的方式显示

%cn

提交者(committer)的名字

%ce

提交者的电子邮件地址

%cd

提交日期

%cr

提交日期,按多久以前的方式显示

%s

提交说明

$ git log --pretty=format:"%h %s" --graph
* 2d3acf9 ignore errors from SIGCHLD on trap
*  5e3ee11 Merge branch master of git://github.com/dustin/grit
|| * 420eac9 Added a method for getting the current branch.
* | 30e367c timeout code and tests
* | 5a09431 add timeout protection to grit
* | e1193f8 support for heads with slashes in them
|/
* d6016bc require time for xmlschema
*  11d191e Merge branch defunkt into local
git log 的常用选项
选项说明

-p

按补丁格式显示每个更新之间的差异。

--stat

显示每次更新的文件修改统计信息。

--shortstat

只显示 --stat 中最后的行数修改添加移除统计。

--name-only

仅在提交信息后显示已修改的文件清单。

--name-status

显示新增、修改、删除的文件清单。

--abbrev-commit

仅显示 SHA-1 的前几个字符,而非所有的 40 个字符。

--relative-date

使用较短的相对时间显示(比如,“2 weeks ago”)。

--graph

显示 ASCII 图形表示的分支合并历史。

--pretty

使用其他格式显示历史提交信息。可用的选项包括 oneline,short,full,fuller 和 format(后跟指定格式)。


  

 

  其它关于log的详见:https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2

 

git基本命令--status, diff, commit, log

原文:http://www.cnblogs.com/drizzlewithwind/p/4874574.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!