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.
Answer from eis on Stack Overflowlogging - Git log output log file - Stack Overflow
git log - View the change history of a file using Git versioning - Stack Overflow
Can you some how "download" all of your git history?
How to have 'git log' show filenames like 'svn log -v' - Stack Overflow
Videos
I would recommend using a different format than the default. My usual choice is a summary with the graph, but a one-line summary alone usually does the trick.
Option 1: One-line summary with a graph
git log --pretty=format:'%h : %s' --graph > log.log
Results in:
* 2d3acf9 : ignore errors from SIGCHLD on trap
* 5e3ee11 : Merge branch 'master' of git://github.com/dustin/grit
|\
| * 420eac9 : Added a method for getting the current branch.
* | 30e367c : timeout code and tests
* | 5a09431 : add timeout protection to grit
* | e1193f8 : support for heads with slashes in them
|/
* d6016bc : require time for xmlschema
Option 2: One-line summary without a graph
git log --pretty=format:'%h was %an, %ar, message: %s' > log.log
Results in:
a6b444f was Scott Chacon, 5 days ago, message: dammit, this is the second time this has re
49d77f7 was Scott Chacon, 8 days ago, message: modified index to create refs/heads if it i
9764edd was Hans Engel, 11 days ago, message: Add diff-lcs dependency
e1ba1e3 was Hans Engel, 11 days ago, message: Add dependency for Open4
0f87b4d was Scott Chacon, 12 days ago, message: merged recent changes
You can find more formatting options in the documentation here.
Try this line
git log > log.txt
This lets Git generate the patches for each log entry:
git log -p -- <filename>
-p in git generates patch text
See git help log for more options — it can actually do a lot of nice things. :)
To get just the diff for a specific commit, use
git show <revision> -- <filename>
or specify any other revision by identifier.
To browse the changes visually:
gitk -- <filename>
To see changes visually without leaving the console, run:
git blame-log <filename>
However, first ensure blame-log command exists, by at least once running:
# Virables: raw=unchanged-line, c=clean, B=Buffer,
git config --global alias.blame-log "! cd -- \"\${GIT_PREFIX:-.}\" && \
( if git grep -qI \".\" \"\$1\"; then \
git log --oneline --color=always -L 1,\${2:-}:\"\$1\" | awk ' \
{ s=\$0; gsub(/\\033\\[[0-9;]*[mK]/, \"\", s) } \
s~/^(diff|---|\\+\\+\+)/{next} \
s~/^@@/{l=1;p=9;bi=0;cm=0;cp=0;next} s!~/^[-+ ]/{print;l=1;p=9;bi=0;cm=0;cp=0;next} \
/^ /{ cm=0;cp=0; if(p<3){print;p++}else{b[bi%3]=\$0; bl[bi%3]=l; bi++} l++; next } \
{ if(p>=3){ n=(bi<3?bi:3); st=(bi<3?0:bi%3); print \"\\033[36mLine \"(n?bl[st]:l)\":\\033[m\"; for(k=0;k<n;k++)print b[(st+k)%3] } \
p=0; if(s~/^-/){cm++;if(cm<=12)print;else if(cm==13)print\"...\"} else{cp++;if(cp<=12)print;else if(cp==13)print\"...\";l++} }'; \
else \
echo \"Detected binary file, hence not showing lines-changed.\"
git log --oneline --color=always \"\$1\";
fi ) | less -RX #"
Note that
blame-logis intentionally limited to showing few lines per change-range, for example, to skippackage-lock.jsonfaster.
For a graphical view, use gitk:
gitk [filename]
To follow the file across file renames:
gitk --follow [filename]
For a console view, maybe because you SSH into a head-less server, run:
git blame-log <filename>
However, first ensure blame-log command exists, by at least once running:
# Virables: raw=unchanged-line, c=clean, B=Buffer,
git config --global alias.blame-log "! cd -- \"\${GIT_PREFIX:-.}\" && \
( if git grep -qI \".\" \"\$1\"; then \
git log --oneline --color=always -L 1,\${2:-}:\"\$1\" | awk ' \
{ s=\$0; gsub(/\\033\\[[0-9;]*[mK]/, \"\", s) } \
s~/^(diff|---|\\+\\+\+)/{next} \
s~/^@@/{l=1;p=9;bi=0;cm=0;cp=0;next} s!~/^[-+ ]/{print;l=1;p=9;bi=0;cm=0;cp=0;next} \
/^ /{ cm=0;cp=0; if(p<3){print;p++}else{b[bi%3]=\$0; bl[bi%3]=l; bi++} l++; next } \
{ if(p>=3){ n=(bi<3?bi:3); st=(bi<3?0:bi%3); print \"\\033[36mLine \"(n?bl[st]:l)\":\\033[m\"; for(k=0;k<n;k++)print b[(st+k)%3] } \
p=0; if(s~/^-/){cm++;if(cm<=12)print;else if(cm==13)print\"...\"} else{cp++;if(cp<=12)print;else if(cp==13)print\"...\";l++} }'; \
else \
echo \"Detected binary file, hence not showing lines-changed.\"
git log --oneline --color=always \"\$1\";
fi ) | less -RX #"
Note that
blame-logis intentionally limited to showing few lines per change-range, for example, to skippackage-lock.jsonfaster.
I am hoping to create a frontend ui where a user can view all of their github/git data.
Something like:
on october 13, 2023, you
created:
file a
file b
file c
modified:
file d (10 insertions)
file e (12 insertions)
file f (13 insertions, 3 deletions)
on october 14, 2023, you ...
as well as stats:
your most frequent file edited is
file abc
it has been edited on:
march 1
march 2
march 7
...
for a total of 700 edits
But to do this, I will need to aggregate all of the git push data.
Is there a way for downloading such data?
Or maybe a way to parse it from the .git directory?
For full path names of changed files:
git log --name-only
For full path names and status of changed files:
git log --name-status
For abbreviated pathnames and a diffstat of changed files:
git log --stat
There are a lot more options. Check out the documentation.
NOTE: git whatchanged is deprecated, use git log instead
New users are encouraged to use git-log[1] instead. The
whatchangedcommand is essentially the same as git-log[1] but defaults to show the raw format diff output and to skip merges.The command is kept primarily for historical reasons; fingers of many people who learned Git long before
git logwas invented by reading Linux kernel mailing list are trained to type it.
You can use the command git whatchanged --stat to get a list of files that changed in each commit (along with the commit message).
References
- https://git-scm.com/docs/git-whatchanged
According to man git-log, this can be done by specifying the two commits you are comparing between, separated by an ellipsis ...
You can specify the commits with HEAD~ notation, or use the commit hash.
To display the information for the last commit only, the command is
git log --graph --decorate --pretty=oneline --abbrev-commit --patch --full-history --follow HEAD...HEAD~1 -- "${FileP}"
If you really want to be able to do this by providing only a single commit hash, the following Bash function should work.
commitlog() {
PREVIOUS_COMMIT=$(git log --oneline | awk '{print $1}' | grep -A 1 "$1" | tail -n 1)
git log --graph --decorate --pretty=oneline --abbrev-commit --patch --full-history --follow "$1"..."$PREVIOUS_COMMIT" -- "$2"
}
Once it has been declared, you can call it with
commitlog b8800d8 "${FileP}"
where b8800d8 is the commit hash and FileP is a variable containing the file name.
git log <the rest of your flags> -1 b8800d8 -- "${FileP}"
b8800d8 makes it start from that commit and -1 limits the output to
the first commit.
Like some utility that takes the git log text as an input and creates a UI to navigate it.
My use case being that I want to be able to preserve and look through the history without having the full repository and its data with me.