4/25/2016 - 2:25 PM

Just some personal git-foo I want to reference.

  • git commit --amend: Shove changes onto last commit (easy rebase if you want to add more to previous commit)
  • git config --list: I use it to find if the clone is using https or ssh
    • git config remote.origin.url git@xxx.git: Set your project to use SSH (grab the full SSH URL from the repo page)
  • git fetch && git diff master..origin/master --name-status: Get list of incoming changes from the remote origin.
    • --name-only For just names
  • git filter-branch: If you want to remove some changes to some files in a branch across all commits in the feature-branch.
    • git filter-branch --force --tree-filter 'git checkout {some-commit-sha} -- some-file.js; {other-commands-if-you-want-like-rm-or-other-git-checkouts}' --prune-empty develop..feature/some-feature-branch
  • git show :/myqueryhere: search commits
  • git branch --contains {some-commit-sha}: Find which branchs have a certain commit
  • git reset --soft HEAD^: Undo but keep changes in working copy
  • git log develop.. --oneline: List only commits on feature branch based off of develop

  • git config --global rerere.eneabled 1: Eases merging (why not do this?)
  • git config --global color.ui 1: Add color to CLI

Git default merge commit messages not including conflicts

You can use the prepare-commit-msg hook to do so.

Copy .git/hooks/prepare-commit-msg.sample to .git/hooks/prepare-commit-msg

The example inside it actually adds # to the Conflicts part:

case "$2,$3" in
    /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;

This hook makes sense because previous versions were doing this by default (like in Linux git version

Now what you want to do is exactly the opposite: removing # on the Conflicts part. Indeed, the git version comments out by default the Conflicts part so you can just update the command in prepare-commit-msg with:

/usr/bin/perl -i.bak -ne 's/^#// if /^# Conflicts/ .. /^#\R/; print' "$1" ;;

via Igal S.,

Ideas for Git tool

  • Edit past commit title/description without any conflicts
    • For some reason, you can run into a conflict when rebasing even if you only change the commit title
  • Find the oldest branch a commit was introduced in
  • Find PR for branch
  • Reset PR from the base again. Get rid of the merge commits (save conflict resolutions of course) but only put the change commits on top of the latest for that branch
    • git rebase master?