Skip to content

Instantly share code, notes, and snippets.

@daluu
Last active May 2, 2022 23:07
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 daluu/2173f4f8821c56f009f37b788d48bfb0 to your computer and use it in GitHub Desktop.
Save daluu/2173f4f8821c56f009f37b788d48bfb0 to your computer and use it in GitHub Desktop.
git and github notes

get current branch name: git rev-parse --abbrev-ref HEAD

revert commit: git reset --soft HEAD~1

revert add: git reset HEAD $1

pushing after rebase: git push --force-with-lease

Resources: https://makandracards.com/makandra/12107-git-show-current-branch-name-only

git SSH & golang: https://gist.github.com/dmitshur/6927554


checking for changed files:

MATCH_FILE_LIST=(
  filename1
  filename2
)
MATCH_FILE_PATTERN=$(printf "|%s" "${MATCH_FILE_LIST[@]}" | cut -c2-)

# change diff command here if there's a better working version than this (that works in CircleCI)
if [[ $(git diff-tree --no-commit-id --name-only -r HEAD | egrep "${MATCH_FILE_PATTERN}" | wc -l) -gt 0 ]]; then
  # whatever you want to do here...
fi

commit tracking

git tag FIRST_COMMIT $(git rev-list --max-parents=0 HEAD)

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