git日志的查看与修改

1.命令行中查看日志

git log

默认是显示所有的日志信息,之前出来的界面显示的日志,很少。

最后发现,只需要使用键盘上向下键↓,就可以继续浏览更多的日志

空格键,可以翻页浏览日志。 

向左←  向右 →  的箭头,可以水平移动查看日志

 

 

2.将日志按照格式导出到文件中

git log --pretty=format:'%h was %an, %ar, message: %s' > log.log

参考资料:Git log output log file

 

3.修改日志  [tortoisegit的图形界面已经支持]

最近一次commit的修改  

git commit --amend

 

如果需要批量修改日志,参考这篇文章git批量修改提交历史     官方文档

假设现在的提交为C1<--C2<--C3

如果需要修改C3和C2,那么使用如下命令

Administrator@LUJUNTAO /d/Colleague/JianQiang/TianJin/ZITaker (master)
$ git rebase --interactive HEAD~2

显示出这个

pick aa28b20 add NPOIExcel      //C2
pick c8c01a0 add Hydraumatic project   //C3

假设我们需要修改的是C2,

那么做出如下修改:

edit aa28b20 add NPOIExcel      //C2       把pick改为edit
pick c8c01a0 add Hydraumatic project   //C3

最后退出vim编辑器,使用wq退出

Successfully rebased and updated refs/heads/master.

 

然后使用git commit --amend

再使用git rebase --continue

 

 

4.查看某一个目录的日志

http://stackoverflow.com/questions/16343659/how-to-show-git-log-history-for-a-sub-directory-of-a-git-repo

$ git log --pretty=format:'%h was %an, %ar, message: %s' ZITaker  > log.log

 

5.修改某一个commit的作者和提交时间 [TortoiseGit的图形界面已经支持]

http://stackoverflow.com/questions/454734/how-can-one-change-the-timestamp-of-an-old-commit-in-git

 $ git commit --amend --reset-author --no-edit  //这个操作会将电脑当前时间作为最后一次commit的提交时间

 如果需要处理多个commit的提交时间的话,那就创建一个临时分支,temp。将temp分支reset到你需要修改提交时间的那个commit上。然后再使用上面的命令

已经修改了“调整历史数据的查询...”的commit。

然后需要将代码微调这个cherrypick到temp分支。重复上面的操作。 【同时记得修改系统时间】

 

也有支持批量处理的,用的脚本,我看不懂

http://giantdorks.org/alain/how-to-reset-date-timestamps-for-one-or-more-git-commits/

 

 

6.git shortlog

git shortlog -sn  按照提交的commit数量进行统计

git shortlog -sn --since="7 weeks" --until="1 weeks"  对某一个时间段进行统计

 

7.Walk Behavior

https://tortoisegit.org/docs/tortoisegit/tgit-dug-showlog.html

可以clone https://github.com/tart/tartJS 来查看不同的Behavior有什么效果

Walk Behaviour → First Parent just follow up first parent commit. This will help understand overwhole history.

Walk Behaviour → No merges Skips all merge points.

Walk Behaviour → Follow renames This is available to a single file only, which tracks renames. Otherwise, the log list stops at the commit that the current filename introduced.

Walk Behaviour → Compressed Graph The log graph is simplified to include merge points, commits with references, and possibly other commits.

Walk Behaviour → Show labelled commits only The log graph is simplified to include commits with references only.

 

posted @ 2015-08-11 16:30  ChuckLu  阅读(15727)  评论(1编辑  收藏  举报