Skip to content

Instantly share code, notes, and snippets.

@edofic
Created October 10, 2017 12:17
Show Gist options
  • Save edofic/89989e03c4f550dad47e72a4777bacea to your computer and use it in GitHub Desktop.
Save edofic/89989e03c4f550dad47e72a4777bacea to your computer and use it in GitHub Desktop.
Git commands notes

Table of Contents

Ask for help

    git --help
    git <command> --help

Commiting

  git commit -am wip
  git commit -m "Initial commit" --allow-empty
  git commit --amend --allow-empty --no-edit

Logs

    git log upstream/develop...my-pr ^my-other-pr
    git log develop --oneline --merges
    git reflog | grep 'moving from' | awk '{print $1,$6}' | head -n40
    git reflog WONDERLAND

Most commands work with paths

    git checkout upsream/release/v2.12 -- src/ggrc_risks
    git checkout .
    git reset .
    git log --oneline srg/ggrc/app.py
    git diff upstream/release/v2.13...upstream/release/v2.14 -- src/ggrc/migrations/
    git ls-files "*.py" | xargs flake8

But not all

    git reset --hard

Github down?

    git add .  # customize as you wish
    git diff --staged > changes.patch
    git apply changes.patch

Or send full commits

    git bundle create my-changes.bundle upstream/develop...HEAD
    git bundle unbundle my-changes.bundle
    git checkout 68335330d6ec880fc6998d123b577b1a4f626c78
    git checkout -b my-branch

You can also pick and choose

    git cherry-pick <hash>

Fixing litnt warnings in non-HEAD

    git blame <file>

Preferably use your IDE/editor integration (:Gblame in fugitive) Then fix the damn thing right there.

    git add .
    git commit --fixup=<hash>

When done

    git rebase upstream/develop -i --autosquash

Random useful things

    git clean -xdf
    git show upstream/release/v2.13:src/ggrc/app.py
    git checkout -
    git checkout --detach
    watch -cn1 'git grep --color -e "import ggrc.app" -e "from ggrc import app" -e "from ggrc.app" | grep -v unit '

GUI?

    git gui
    gitk
    tig

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