116

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

eis
  • 51,991
  • 13
  • 150
  • 199
Inverted Llama
  • 1,522
  • 3
  • 14
  • 25
  • 1
    Possible duplicate of [Git log output log file](http://stackoverflow.com/questions/10063407/git-log-output-log-file) – Abhijeet Sep 01 '16 at 07:02

11 Answers11

183

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 parameters of git log.

eis
  • 51,991
  • 13
  • 150
  • 199
  • For some reason saving it like that it skips the header information for branches, any idea how i can get it? ex.: commit b28b1ae828ee87ffdc675dc1de299b51d3eb2ea2 (origin/master, ....etc, when i save it i dont see origin/master anymore – SubqueryCrunch Jul 26 '22 at 08:48
  • @SubqueryCrunch `--decorate` can be added to get that, see [this thread](https://stackoverflow.com/questions/55203481/git-log-oneline-gives-head-information-that-is-lost-when-piping-or-redirecting) – eis Jul 06 '23 at 17:34
28

Have you tried git log > log.txt ?

Sergey K.
  • 24,894
  • 13
  • 106
  • 174
Hindol
  • 2,924
  • 2
  • 28
  • 41
25
git log | clip 

copies to clipboard, then paste to a textfile.

(Especially if you have the problem of line-ending and thus by this method you can copy and paste it in a Microsoft word document(.docx); so there would be a new line for each commit!!!)

muel
  • 43
  • 1
  • 13
a-man
  • 657
  • 1
  • 6
  • 16
  • 4
    This seems to be the easiest way for Windows users to get around the Unix line-ending issue that writing straight to a file presents. – MarredCheese Jun 22 '17 at 01:14
12

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

git log > commits.txt
Arian Acosta
  • 6,491
  • 1
  • 35
  • 32
Fryann Martinez
  • 398
  • 3
  • 9
11
git log --before="2019-2-23" --pretty=format:'"%h","%an","%ae","%aD","%s",' --shortstat --no-merges | paste - - - > log.txt
Ayed Mohamed Amine
  • 587
  • 2
  • 10
  • 30
10

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 error which is also very common. Lets try to understand . . . .

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 --after and --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.

Kunal Vohra
  • 2,703
  • 2
  • 15
  • 33
4

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.)

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

 git log --oneline -50 > log50_latest_commits.txt

(3) If you want display commit at all branch

 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

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

Vy Do
  • 46,709
  • 59
  • 215
  • 313
3

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

This will generate :

Author : your name

Date/Time : Commit Date time

Commit : Commit message

Omar Hasan
  • 719
  • 7
  • 18
2

This is what worked for me with Git Bash on Windows 7:

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

replace <user-name> with your user name.

The file will be exported to your Desktop from where you can read it.

Good Luck...

Aakash
  • 21,375
  • 7
  • 100
  • 81
1

I found this article that could help you. Article of how generate a changelog One tool that you could use is changelog

npm install generate-changelog -g
changelog generate

It will create a well formed CHANGELOG.md file.

Greetings.

mariofertc
  • 383
  • 2
  • 7
0

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

Ilya Rogatkin
  • 69
  • 1
  • 7