Skip to content

Using git

Jonathan Hu edited this page Apr 25, 2017 · 1 revision

Useful git commands

git pull --rebase

Pull with rebase. Create a cleaner commit tree. Can be set by default: git config branch.autosetuprebase always. You can still override this with --no-rebase.

git stash show -p

Shows diffs between stash and HEAD using tkdiff

git stash show [<stash>]

Show the changes recorded in the stash as a diff between the stashed state and its original parent. When no is given, shows the latest one. By default, the command shows the diffstat, but it will accept any format known to git-diff (e.g., git stash show -p stash@{1} to view the second most recent stash in patch form).

git status -uno

Status but leave out untracked files.

git rebase --interactive HEAD~2

More on Interactive rebasing.

  git config --global --add difftool.prompt false #do this just the first time
  git pull                                        # on master
  git checkout -b view-diffs-branch
  git am *.patch
  git difftool ORIG_HEAD
  git reset --hard ORIG_HEAD                      # if you want to get rid of the patches you just committed

Interactively use a gui to diff a bunch of patches with the extension ".patch":

History

git log -- <filename>

See the log of a file that's been deleted.

git log --follow -p MueLu_Utilities_def.hpp

See the log of a file, plus patches.

git log origin/master..master

How to tell which commits haven't been pushed yet

git log --all --format="%aN" <dir> | sort | uniq -c | sort -n

List authors who contributed to <dir> (useful for knowing developers of a specific package).

git log --oneline

One line summaries of git commits.

Graphical interfaces

gitk [file/dir]

Graphical git browser. Useful to browse log, revert commit, ...

git gui blame <filename>

Graphical blame tool

tig

A curses based interface. Available at https://github.com/jonas/tig.

External References