Skip to content

Instantly share code, notes, and snippets.

@mariocesar
Last active November 9, 2023 12:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariocesar/1aef39d5393ba3e94a18cbf73c1053af to your computer and use it in GitHub Desktop.
Save mariocesar/1aef39d5393ba3e94a18cbf73c1053af to your computer and use it in GitHub Desktop.
Git useful commands

Searching for a text in all the history of the repo.

function grep_git_history() {
  local term="${@}"
  git grep -e "${term}" $(git log -S "${term}" --pretty=format:"%H")
}

grep_git_history 'var = 1'
grep_git_history '{% url'

Get all modified files on the last commit

git diff --name-only HEAD $(git merge-base HEAD HEAD^)

Useful for CI jobs to skip if files for an directory are not updated. For example to run tests just if there are commits in src/frontend

if [[ ! -z $(git diff --name-only HEAD $(git merge-base HEAD HEAD^) | grep src/frontend) ]]; 
then 
  npm install;
  npm run test;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment