如何获取git存储库中特定文件的更改历史记录

时间:2010-05-17 19:00:46

标签: git diff history

我想做点什么:

git history my_file

可能的输出

2010-05-16
+ add this line
+ more code here

2010-05-15
+ delete code below
- bad code
- more bad codd

2010-05-12
+ changes made here

3 个答案:

答案 0 :(得分:18)

尝试:

git log -p -- filename

答案 1 :(得分:8)

最接近你想要的是git log

git log -p -U0 --pretty=format:%ai -- filename
  • -pCharles Bailey中的his answer提及:生成补丁
  • -U0:使用0行上下文而不是通常的三行生成差异。
  • --pretty=format:%ai:在补丁输出前面加上作者日期,ISO 8601格式。

示例:

/c/Prog/Git/git2/git (master)
$ git log -p -U0 --pretty=format:%ai -- wt-status.c
2010-03-24 16:25:43 -0700
2010-03-13 23:00:27 +0100
diff --git a/wt-status.c b/wt-status.c
index e0e915e..5848f1c 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -306,0 +307,2 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)
+       if (!s->show_untracked_files)
+               DIFF_OPT_SET(&rev.diffopt, IGNORE_UNTRACKED_IN_SUBMODULES);

2010-03-08 22:58:09 -0800
diff --git a/wt-status.c b/wt-status.c
index 5807fc3..dcaec7f 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -292,0 +293 @@ static void wt_status_collect_changes_index(struct wt_status *s)
+       struct setup_revision_opt opt;
@@ -295,2 +296,4 @@ static void wt_status_collect_changes_index(struct wt_status *s)
-       setup_revisions(0, NULL, &rev,
-               s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference);
+       memset(&opt, 0, sizeof(opt));
+       opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference;
+       setup_revisions(0, NULL, &rev, &opt);
+

答案 2 :(得分:4)

如果您将文件传递给Gitk安装附带的gitk,也会提供文件历史记录的精美UI视图。

在Windows上...

gitk.cmd <file>