This is mostly for my own benefit, but here are some git commands that I’ve found useful:

  • simplified git log showing 1-line description of commits:
    git log --pretty=oneline
  • simplified git log showing tree structure of git repo:
    git log --graph --simplify-by-decoration --pretty=format:'%d' --all

    for more complicated logs, use gitk --all

  • deleting a local branch (in case you muck around with a branch too much and can’t seem to get things to reset properly with ):
    git branch -d the_local_branch

    when doing this, make sure you’re on another branch (i.e., you’re not on the branch you want to delete)

  • renaming a local branch:
    git branch -m old-branch-name new-branch-name
  • preventing merge from executing a fast-forward:
    git merge --no-ff

    This is useful when you’re trying to merge in a feature branch and, even if it’s fast-forward change, you still want it look like a merge in the git tree structure (because it’s helpful in understanding the commit history and will affect how things show up in gitk or in git log).

  • fetching changes that might have been rebased before using:
    git pull --rebase

    Good description of why this is useful is here. Basically it protects against conflicts that might have resulted from rebase changes like squash, etc.

  • remove a file from being tracked (and showing up in git status):
    git rm --cached path/to/file

    still shows up in working directory, but now git status will marked it as untracked

This article has 2 comments

  1. Andreas Reply

    asn@magrathea:~/workspace/projects/cmocka> grep log ~/.gitconfig
    l = log
    lo = log –pretty=oneline
    lg = log –color –graph –pretty=format:’%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset’ –abbrev-commit —
    rlog = log –reverse -p –stat

    • ktnode Reply

      Thanks for the suggestions, Andreas! I’ve already added these to the my gitconfig 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *