git log 查看某文件的修改历史

时间:2023-11-13 08:45:32


*/

.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
background: #f0f0f0;
-webkit-text-size-adjust: none;
}

.hljs,
.hljs-subst,
.hljs-tag .hljs-title,
.nginx .hljs-title {
color: black;
}

.hljs-string,
.hljs-title,
.hljs-constant,
.hljs-parent,
.hljs-tag .hljs-value,
.hljs-rules .hljs-value,
.hljs-preprocessor,
.hljs-pragma,
.haml .hljs-symbol,
.ruby .hljs-symbol,
.ruby .hljs-symbol .hljs-string,
.hljs-template_tag,
.django .hljs-variable,
.smalltalk .hljs-class,
.hljs-addition,
.hljs-flow,
.hljs-stream,
.bash .hljs-variable,
.apache .hljs-tag,
.apache .hljs-cbracket,
.tex .hljs-command,
.tex .hljs-special,
.erlang_repl .hljs-function_or_atom,
.asciidoc .hljs-header,
.markdown .hljs-header,
.coffeescript .hljs-attribute {
color: #800;
}

.smartquote,
.hljs-comment,
.hljs-annotation,
.diff .hljs-header,
.hljs-chunk,
.asciidoc .hljs-blockquote,
.markdown .hljs-blockquote {
color: #888;
}

.hljs-number,
.hljs-date,
.hljs-regexp,
.hljs-literal,
.hljs-hexcolor,
.smalltalk .hljs-symbol,
.smalltalk .hljs-char,
.go .hljs-constant,
.hljs-change,
.lasso .hljs-variable,
.makefile .hljs-variable,
.asciidoc .hljs-bullet,
.markdown .hljs-bullet,
.asciidoc .hljs-link_url,
.markdown .hljs-link_url {
color: #080;
}

.hljs-label,
.hljs-javadoc,
.ruby .hljs-string,
.hljs-decorator,
.hljs-filter .hljs-argument,
.hljs-localvars,
.hljs-array,
.hljs-attr_selector,
.hljs-important,
.hljs-pseudo,
.hljs-pi,
.haml .hljs-bullet,
.hljs-doctype,
.hljs-deletion,
.hljs-envvar,
.hljs-shebang,
.apache .hljs-sqbracket,
.nginx .hljs-built_in,
.tex .hljs-formula,
.erlang_repl .hljs-reserved,
.hljs-prompt,
.asciidoc .hljs-link_label,
.markdown .hljs-link_label,
.vhdl .hljs-attribute,
.clojure .hljs-attribute,
.asciidoc .hljs-attribute,
.lasso .hljs-attribute,
.coffeescript .hljs-property,
.hljs-phony {
color: #88f;
}

.hljs-keyword,
.hljs-id,
.hljs-title,
.hljs-built_in,
.css .hljs-tag,
.hljs-javadoctag,
.hljs-phpdoc,
.hljs-dartdoc,
.hljs-yardoctag,
.smalltalk .hljs-class,
.hljs-winutils,
.bash .hljs-variable,
.apache .hljs-tag,
.hljs-type,
.hljs-typename,
.tex .hljs-command,
.asciidoc .hljs-strong,
.markdown .hljs-strong,
.hljs-request,
.hljs-status {
font-weight: bold;
}

.asciidoc .hljs-emphasis,
.markdown .hljs-emphasis {
font-style: italic;
}

.nginx .hljs-built_in {
font-weight: normal;
}

.coffeescript .javascript,
.javascript .xml,
.lasso .markup,
.tex .hljs-formula,
.xml .javascript,
.xml .vbscript,
.xml .css,
.xml .hljs-cdata {
opacity: 0.5;
}
#container {
padding: 15px;
margin-left:20px;
}
pre {
border: 1px solid #ccc;
border-radius: 4px;
display: block;
}
pre code {
white-space: pre-wrap;
}
.hljs,
code {
font-family: Monaco, Menlo, Consolas, 'Courier New', monospace;
}

pre{
background-color: #dddddd;
padding:8px 0px 8px 30px;
word-wrap: break-word;
}
table tbody tr:nth-child(2n) {
background: rgba(158,188,226,0.12);
}
:not(pre) > code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
background-color: #f9f2f4;
white-space: nowrap;
border-radius: 4px;
}
th, td {
border: 1px solid #ccc;
padding: 6px 12px;
}
blockquote {
border-left-width: 10px;
background-color: rgba(102,128,153,0.05);
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
padding: 1px 20px
}
blockquote.pull-right small:before,blockquote.pull-right .small:before {
content: ''
}

blockquote.pull-right small:after,blockquote.pull-right .small:after {
content: '\00A0 \2014'
}

blockquote:before,blockquote:after {
content: ""
}
blockquote {
margin: 0 0 1.1em
}
blockquote p {
margin-bottom: 1.1em;
font-size: 1em;
line-height: 1.45
}

blockquote ul:last-child,blockquote ol:last-child {
margin-bottom: 0
}
blockquote {
margin: 0 0 21px;
border-left: 10px solid #dddddd;
}
-->

git log 查看提交历史

git手册的使用

  • 对于git所有的命令,都可以在本地的使用手册中查询如何使用
    git log -- help

常见的命令

git log

  • git log 可以查看当前工作目录的所有提交历史, 结果基本如下所示
commit 8200fc34e51f51048fe2be8ffe53830a5123b763 (HEAD -> master, origin/master)
Author: dhlin <542072149@qq.com>
Date: Sat May 30 20:58:31 2020 +0800 update readme commit 247912dc5a0afc3eed5b11ab5bdc01216157cd7a
Author: dhlin <542072149@qq.com>
Date: Sat May 30 14:37:40 2020 +0800 first commit
  • git log --stat 相比git log 可以查看每次提交对应修改的文件列表,修改的行数等
commit 8200fc34e51f51048fe2be8ffe53830a5123b763 (HEAD -> master, origin/master)
Author: dhlin <542072149@qq.com>
Date: Sat May 30 20:58:31 2020 +0800 update readme readme.md | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 179 insertions(+) commit 247912dc5a0afc3eed5b11ab5bdc01216157cd7a
Author: dhlin <542072149@qq.com>
Date: Sat May 30 14:37:40 2020 +0800 first commit binart-tree.js | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 96 insertions(+)
  • git log -- readme.md 过滤提交记录,只查看该文件的提交记录
commit 8200fc34e51f51048fe2be8ffe53830a5123b763 (HEAD -> master, origin/master)
Author: dhlin <542072149@qq.com>
Date: Sat May 30 20:58:31 2020 +0800 update readme
  • git log -p readme.md 过滤提交记录,并且能查看每次提交记录中,对该文件的修改
commit 8200fc34e51f51048fe2be8ffe53830a5123b763 (HEAD -> master, origin/master)
Author: dhlin <542072149@qq.com>
Date: Sat May 30 20:58:31 2020 +0800 update readme diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..b27ae30
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,179 @@
+# js 简单版本的二叉树实现
+
+### 概念
  • git show commit-id readme.md 根据commit-id过滤,只显示该提交中对此文件的修改
git show c16f82bbb9cd80e797a8b69a82bec48dcba2a04d readme.md
commit c16f82bbb9cd80e797a8b69a82bec48dcba2a04d (HEAD -> master)
Author: dhlin <542072149@qq.com>
Date: Sat May 30 21:56:24 2020 +0800 update 2 diff --git a/readme.md b/readme.md
index b27ae30..b55889e 100644
--- a/readme.md
+++ b/readme.md
@@ -1,3 +1,5 @@
+Author: dhlin
+
# js 简单版本的二叉树实现 ### 概念
  • git show commit-id 查看某次提交中的对所有文件的修改

  • gitk gitk是git的一个图形化工具,有很多可以替代的产品,比如sourceTree等

  • 以下是一些基本命令

选项 说明
-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(后跟指定格式)。
-(n) 仅显示最近的 n 条提交
--since, --after 仅显示指定时间之后的提交。
--until, --before 仅显示指定时间之前的提交。
--author 仅显示指定作者相关的提交。
--committer 仅显示指定提交者相关的提交。
--grep 仅显示含指定关键字的提交
-S 仅显示添加或移除了某个关键字的提交