git 在 Magit 中查看文件的历史记录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14352932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:01:35  来源:igfitidea点击:

View a file's history in Magit?

gitemacsmagit

提问by eugene

View the change history of a file using Git versioningtalks about other ways of viewing history of a file in Git.

使用 Git 版本控制查看文件的更改历史讨论了在 Git 中查看文件历史的其他方法。

Can it be done in Emacs Magit?

可以在 Emacs Magit 中完成吗?

回答by Ragge

Since magit 2.1: magit-log-buffer-file(as per comment below)

从 magit 2.1 开始:(magit-log-buffer-file根据下面的评论)

Before magit 2.1: magit-file-logis what you are looking for. It will show you all commits for the file in the current buffer in the standard magit log view.

在 magit 2.1 之前:magit-file-log就是你要找的。它将在标准 magit 日志视图中显示当前缓冲区中文件的所有提交。

回答by Bryan Ash

Open your magit-statusbuffer, by typing M-x magit-status(I used to have this bound to C-. C-gbecause it is used all the time. These days, I use Spacemacs so it's <SPC> g s)

magit-status通过键入打开您的缓冲区M-x magit-status(我曾经绑定过C-. C-g它,因为它一直在使用。这些天,我使用 Spacemacs 所以它是<SPC> g s

  1. Type lto get log viewing option
  2. Type --to set the "Limit to files" option (used to be =f)
  3. Enter the file path you wish to view history for
  4. Type lto view the log of the current branch
  1. 键入l以获取日志查看选项
  2. 键入--以设置“限制到文件”选项(曾经是=f
  3. 输入要查看历史记录的文件路径
  4. 键入l查看当前分支的日志

If you're using Spacemacs, you can get the history of the currently visited file using <SPC> g f h

如果您使用的是 Spacemacs,则可以使用以下命令获取当前访问过的文件的历史记录 <SPC> g f h

回答by Bart Vandendriessche

In your *magit: <project>*buffer use lto go into logging mode, then press fto be prompted for a filename.

在您的*magit: <project>*缓冲区中使用l进入日志记录模式,然后按f提示输入文件名。

回答by sp3ctum

I do not know a way. I simply use M-x vc-print-logwhich seems to accomplish the same feat. It is not a magit-integrated way, though.

我不知道有什么办法。我只是使用M-x vc-print-log它似乎完成了同样的壮举。不过,这不是一种与 magit 集成的方式。

回答by VonC

If magit(user manual) doesn't have that feature, then you can have a look at other Emacs mode, and add you own git-log-filefunction:

如果magit用户手册)没有该功能,那么您可以查看其他Emacs模式,并添加您自己的git-log-file功能:

(defun git-log-file ()
  "Display a log of changes to the marked file(s)."
  (interactive)
  (let* ((files (git-marked-files))
         (buffer (apply #'git-run-command-buffer "*git-log*" "git-rev-list" \
"--pretty" "HEAD" "--" (git-get-filenames files))))  (with-current-buffer buffer
      ; (git-log-mode)  FIXME: implement log mode
      (goto-char (point-min))
      (setq buffer-read-only t))
    (display-buffer buffer)))