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.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM