如何将 git 日志导出到文本文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10330425/
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-10 13:33:28  来源:igfitidea点击:

How do I export a git log to a text file?

git

提问by Inverted Llama

I want to export the log of all commits in a repo to a text file, is there any way to do this?

我想将 repo 中所有提交的日志导出到文本文件,有什么方法可以做到这一点?

回答by eis

You'll just need to disable the pager.

您只需要禁用寻呼机。

git --no-pager log > log.txt

If you want to format it to look nicer, you can use parametersof git log.

如果你想把它格式化得更好看,你可以使用git log 的参数

回答by Hindol

Have you tried git log > log.txt?

你试过git log > log.txt吗?

回答by a-man

git log | clip 

copies to clipboard, then paste to a textfile

复制到剪贴板,然后粘贴到文本文件

回答by Fryann Martinez

You may use the >symbol send the output to a file. For example:

您可以使用>符号将输出发送到文件。例如:

git log > commits.txt

回答by Do Nhu Vy

You can make log report more clearly, by

你可以让日志报告更清晰,通过

(1) setting number of latest commits (for example, in below command, we get latest 50 commits, you can change it to 100, 500, etc.)

(1) 设置最新提交的次数(例如,在下面的命令中,我们获得了最新的 50 次提交,您可以将其更改为 100、500 等)

(2) display long commit in one line This command is display commit log in current branch:

(2) display long commit in one line 这个命令是显示当前分支的提交日志:

 git log --oneline -50 > log50_latest_commits.txt

(3) If you want display commit at all branch

(3) 如果你想在所有分支上显示提交

 git log --all --oneline -50 > log50_latest_commits.txt

Generated text file will stand at the current directory.

生成的文本文件将位于当前目录。

Reference: https://git-scm.com/docs/git-log

参考:https: //git-scm.com/docs/git-log

(tested on git version 2.11.0.windows.1and it works on many other versions of Git)

(经过测试git version 2.11.0.windows.1,它适用于许多其他版本的 Git)

回答by Akash

This is what worked for me with Git Bashon Windows 7:

这对我Git Bash有用Windows 7

git log > /C/Users/<user-name>/Desktop/git-log.txt

git log > /C/Users/<user-name>/Desktop/git-log.txt

replace <user-name>with your user name.

替换<user-name>为您的user name.

The file will be exported to your Desktopfrom where you can readit.

该文件将从您可以导出的位置导出到您Desktop的位置read

Good Luck...

祝你好运...

回答by Ayed Mohamed Amine

git log --before="2019-2-23" --pretty=format:'"%h","%an","%ae","%aD","%s",' --shortstat --no-merges | paste - - - > log.txt

回答by Omar Hasan

In my case i found this was helpful

就我而言,我发现这很有帮助

git log --after="2020-3-20" --pretty=format:'Author : %an %nDate/Time : %aD%nCommit : %s' | paste > log.txt

git log --after="2020-3-20" --pretty=format:'Author : %an %nDate/Time : %aD%nCommit : %s' | paste > log.txt

This will generate :

这将生成:

Author : your name

作者:你的名字

Date/Time : Commit Date time

日期/时间:提交日期时间

Commit : Commit message

提交:提交消息

回答by Kunal Vohra

Its been long since this question was asked and by that time things have been evolved.

很久没有问这个问题了,到那时事情已经发展了。

But, it is very interesting that all answers here are correct but not really addressing a post command errorwhich is also very common. Lets try to understand . . . .

但是,非常有趣的是,这里的所有答案都是正确的,但并没有真正解决也很常见的 post命令错误。让我们试着理解。. . .

Who knew it was super easy. Run a simple command

谁知道这超级容易。运行一个简单的命令

git log -p --all > git_log.txt

but then I strucked on an error

但后来我发现了一个错误

> warning: inexact rename detection was skipped due to too many files.
> warning: you may want to set your diff.renameLimit variable to at least 2951 and retry the command.

and we had a problem. The output file was half a gig.

我们遇到了问题。输出文件是半个演出。

We just wanted the first half of 2018 which we are able to do with --afterand --until

我们只是想2018年上半年,我们能够与做--after--until

git log --pretty=format:"%ad - %an: %s" --after="2018-01-01" --until="2018-06-30" > git_log.txt

This worked nicely for our purposes and was nice to know that we could change the format if need be.

这对我们的目的很有效,很高兴知道我们可以根据需要更改格式。

回答by Ilya Rogatkin

It's simple. if you don't matter save a file you need the open terminal

这很简单。如果你不关心保存文件,你需要打开终端

cd {your git repository}
git log > your_file_name.txt

if you need a special directory, just write all path in the right side, like this

如果你需要一个特殊的目录,只需在右侧写下所有路径,就像这样

cd {your git repository}
git log > /home/user/logs/your_file_name.txt

This directory, for example, you could use any one of your needs. I write a log like this just now.

例如,您可以使用此目录中的任何一种。我刚刚写了一个这样的日志。

This example show how to write a text in a file via bash

此示例显示如何通过 bash 在文件中写入文本