Skip to content

Instantly share code, notes, and snippets.

@gpfreitas
Last active November 16, 2023 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpfreitas/2c160eed187cbef0166f17034301590a to your computer and use it in GitHub Desktop.
Save gpfreitas/2c160eed187cbef0166f17034301590a to your computer and use it in GitHub Desktop.
# Am I in the right branch? Did I push my latest commit?
git log

# Who has worked on this project/folder?
git log -- .  # Then search "author" with the pager

# What have I worked on recently? Or, What branches have I authored?
git log --branches --no-walk --author=Guilherme

# When did we last touch this file? When was it added
# cwd is /Users/guilherme.freitas/ml/projects/pricing/connections/cputils/cputils
git log --name-status -- fetch.py

# I remember logging when this code was working with a specific upstream data source (MVIPRenewals flow)... when was that?
# I'll search messages for the word "works" for the relevant folder
# cwd is ml/projects/churn/mvip
git log --grep works --author=Guilherme -- .

# What's the history of changes in this file? Did it ever have this string?
git log --patch -- fetch.py  # then search for the string manually

# Did I ever commit the docs for the revenue model for C+ Pricing? I know it had the word "concave"
# cwd is /Users/guilherme.freitas/ml/
git log --author=Guilherme --patch -G concave --all

# Where is Maanit's MVIPRenewal's flow defined? It's not in master, and I need to run it because of pandas version issues
git log -G MVIPRenewals --all --author=Maanit  # you could use --patch to look at the code to confirm
git branch -a --contains d1cb2af0c6c3ce56cccb0e92a4b1366cabd2d91b  # to find the actual branch if you want the latest code with that

# What's the history of this function?
# cwd is /Users/guilherme.freitas/ml/projects/pricing/connections/cputils/cputils
git log -L ':get_market_tags:fetch.py'

# What's the history of this query (note we just define a code block by regex to pick the query)?
# cwd is ml/projects/pricing/connections/cputils/cputils/queries
git log -L '/REFERRAL_RPL_FROM_ANALYTICS_QUERY = """/,/"""/:referral.py'

# For performance review: what have I worked on in the last year?
# This is not a perfect answer, but it helps.
git log  --author=Guilherme --since='2022-05-01' master

# When was the latest time someone used shap in our codebase?
git log -G 'import shap' --oneline --name-status --pretty=reference
@gpfreitas
Copy link
Author

The main thing is

git log --{patch,name-status,stat} -- .

with --all or not. And if using --all, it's a good idea to restrict in some other way, like --author.

@gpfreitas
Copy link
Author

gpfreitas commented May 9, 2023

Also, you can add local notes (you can push them too if you need to) to your git logs, especially useful in development for me, with the git notes add command, and then you will see it every time you do a git log.

@gpfreitas
Copy link
Author

See also: https://gist.github.com/eyecatchup/3fb7ef0c0cbdb72412fc/forks for things like the git shortlog command to see commit stats by author/folder, etc.

@gpfreitas
Copy link
Author

gpfreitas commented Jul 13, 2023

Not git log related, but I need to put this somewhere:

Had to develop your_branch off of another dev branch (not master)? Now need to merge just your work from your_branch into master without the another commits?

One option would be to revert all the commits from the another branch. I had a hard time doing that, so eventually gave up.

But rebase worked like a charm:

git rebase -i --onto master another your_branch

In fact this is in the git rebase man/help page (search for --onto):

First let’s assume your topic is based on branch next. For example, a feature developed in topic depends on some
       functionality which is found in next.

               o---o---o---o---o  master
                    \
                     o---o---o---o---o  next
                                      \
                                       o---o---o  topic

       We want to make topic forked from branch master; for example, because the functionality on which topic depends was merged
       into the more stable master branch. We want our tree to look like this:

               o---o---o---o---o  master
                   |            \
                   |             o'--o'--o'  topic
                    \
                     o---o---o---o---o  next

       We can get this using the following command:

           git rebase --onto master next topic

My use-case was: I needed to run a flow that was in maanit/mvip_renewals to do my work on mvip_churn_request_by_mark_maanit_20230710. But I didn't need code from Maanit's branch, just the results of the flow, so at merge time, I ran git rebase -i --onto master maanit/mvip_renewals mvip_churn_request_by_mark_maanit_20230710 to get just the commits I wrote.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment