Git/log: Difference between revisions
No edit summary |
Add example of --cherry-pick |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[File:Git log color.png|thumb]] | [[File:Git log color.png|thumb]] | ||
We use < | We use <code>git log</code> for creating [[RELEASE NOTES]] (Refer to the script there.) | ||
| Line 279: | Line 279: | ||
You also get '''<tt>tformat</tt>''' behavior if you do not specify any 'format' word, but use '%-encoded' formatting strings. Thus, the following is equivalent to the previous example:<br> | You also get '''<tt>tformat</tt>''' behavior if you do not specify any 'format' word, but use '%-encoded' formatting strings. Thus, the following is equivalent to the previous example:<br> | ||
<code>git log -3 --pretty="* %h (%as) %(decorate:prefix=,suffix=,tag=v,separator= ) - %an: %s %b" 39.5.0...HEAD</code> | <code>git log -3 --pretty="* %h (%as) %(decorate:prefix=,suffix=,tag=v,separator= ) - %an: %s %b" 39.5.0...HEAD</code> | ||
== CSV Output for spreadsheets == | |||
By simply formatting your output into a "Comma Separated Values" file, you can easily work with log data in a spreadsheet with LibreOffice Calc. (Note that LibreOffice Calc does not support reading data directly from STDIN, so you can't use process substitution. You must create a (temporary) file from the log, and then open that file with LibreOffice. | |||
<code>git log nasa/main...origin/REL1_43 --date=iso-strict --pretty=format:'"%h","%ad","%an","%s"' --cherry-pick --right-only > meza.log.csv && libreoffice --calc meza.log.csv</code> | |||
== Keywords == | == Keywords == | ||
If your team | If your team writes [[Git/hacks#Good_and_Consistent_commit_messages|good commit messages]] with consistent keywords to describe the type of commits made, you can later easily filter and sort issues for better [[RELEASE NOTES]] In the example below, we filter and sort commits based on subjects that start with common actions or keywords. | ||
<code>git log 39.5.0..HEAD --pretty=format:"%s" --no-merges | grep -Ei "^(add|bug|chore|delete|doc|feat|fix|refactor|remove|style|test|update)" | sort</code> | <code>git log 39.5.0..HEAD --pretty=format:"%s" --no-merges | grep -Ei "^(add|bug|chore|delete|doc|feat|fix|refactor|remove|style|test|update)" | sort</code> | ||
| Line 292: | Line 297: | ||
<code>git log --since "2 years ago" --pretty=format:"%s" --no-merges | awk '{print tolower($1)}' | sort | uniq -c | sort -nr | head -20</code> | <code>git log --since "2 years ago" --pretty=format:"%s" --no-merges | awk '{print tolower($1)}' | sort | uniq -c | sort -nr | head -20</code> | ||
== Comparing branches and foreign (upstream) repos == | |||
As you may know, the triple dot notation means to find the common ancestor. Using that with <code>shortlog</code> allows to quickly find the differences between branches or even 'upstream' repos - especially in conjunction with <code>--cherry-pick --right-only</code>. | |||
This is the command you want if you've ever wondered how GitHub shows you that your fork is '''X commits ahead, Y commits behind''<nowiki/>' repo ACME and you want to get a quick overview of the situation. | |||
<code>git shortlog nasa/main...origin/REL1_43 --cherry-pick --right-only</code> | |||
== Cherry on top == | |||
By using the --cherry-pick option with --right-only, we can omit equivalent commits that appear on both sides. | |||
<syntaxhighlight lang="bash"> | |||
git log --graph --full-history nasa/main...origin/REL1_43 --color --date=short --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%ad %s" --cherry-pick --right-only | |||
</syntaxhighlight> | |||
[[Category:Best Practices]] | [[Category:Best Practices]] | ||