git notes main page | gitolite main page | license

IMPORTANT NOTE: although this page has a "gitolite.com" URL, this is not about gitolite. That's just an artifact of "sitaramc.github.com" being translated to "gitolite.com" and so ALL my git related stuff gets carried over. Gitolite documentation has another /gitolite in the URL, so you can tell. My apologies for this confusion.

useful commands

grep

git grep is very, very, powerful. It has pretty much all the normal grep options, plus:

log and show

reflog

…see this more detailed note

show-branch

cherry (not cherry-pick)

cat-file (repo object) and ls-tree (tree object)

Note: I’m not sure what, if any, is the difference between show and cat-file -p for “blob” objects. For commits there is a subtle difference. (Try it)

# any object
git cat-file [ -t | -s | -p ] 789abc
    # find the type or size of an object, or pretty print it
    # If it's a blob, I'd use use "git show" until we find out what
    # "pretty" means for arbitrary blobs :-)
git cat-file blob 789abc        # cat the object

# any tree
git ls-tree         # files and directories, top level only
git ls-tree -l      # also show the size of the object
git ls-tree -d      # only directories
git ls-tree -r      # recurse, only files
git ls-tree -r -d   # recurse, only directories
git ls-tree -r -t   # recurse, both directories and files

ls-files

To get listings of various types of files, use git ls-files. The common but less intuitive ones are shown here, the rest can be had from the man page:

# deleted files and modified files (deleted files are also counted as
# modified, so may come up twice...
git ls-files -d -m
# what's in the index; includes files that were "git add"ed
git ls-files -s
# conflicted files
git ls-files -u
# "other files"; includes EVERYthing not in d/m/s, I think
# seems to be equal to untracked + ignored
git ls-files -o
# untracked files only
git ls-files --exclude-standard -o
# ignored files only
git ls-files --exclude-standard -o -i