TL;DR:

  • git pickaxe
  • git add -p (add just specific changes to staging)
  • tig (useful commandline tool)
  • use git aliases to save keystrokes in your .basrc file
  • Octothree (browser extension)

If you are trying to find how code inside the project changed through time you can used so called git pickaxe.

$ git log -S "some code" --reverse --patch

What this does is shows you all the commits and its content (oldest commits first).

Cool git command I use regularly is

$ git add --patch
# or
$ git add -p

Which enables you to add specific code to staging and not just the whole file.

If you want to see what commit changes were made on particular file

$ git log -- my_file.txt

-- says that this is current branch. You can add --patch before -- to see the changes.

One command line tool I enjoy using is tig. I mostly use it for inspecting commits, commit history, diffs etc.

Because I often use commands like the ones listed below

$ git status -s
$ git commit
$ git diff
$ git log --oneline

To save few keystrokes I added these commands to aliases in my .zshrc file. If you use Bash you can add them to your .bashrc file.

alias gs='git status -s'
alias ga='git add '
alias gb='git branch '
alias gc='git commit'
alias gd='git diff'
alias gds='git diff --staged'
alias gp='git push '
alias gpl='git pull '
alias gl='git log --oneline'

The next trick is not just git specific but I found it so useful that I want to mention it here. If you use github and miss navigating the source code in the same way as in your text editor you can install Octothree. This is browser extension that enables you to navigate files and folder in a tree like structure.