Git command cheat sheet on Ubuntu Linux - lifuzu/cafe GitHub Wiki

1. Git diff with external tool:

git difftool --tool=vimdiff

2. List all the files for a commit:

git diff-tree --no-commit-id --name-only -r <commit-id>

or

git show --pretty="format:" --name-only <commit-id>

3. List the most recent tag on the current branch, which has an annotate tag like: branchname_1.2.3.123

git describe --match `git rev-parse --abbrev-ref HEAD`* --tags

4. Make an annotate tag

git tag -a master_1.2.3.123

5. Get the current branch name

git rev-parse --abbrev-ref HEAD

or

git name-rev --name-only HEAD

or

git symbolic-ref HEAD --short

6. Get the remote from the current branch

git config branch.`git name-rev --name-only HEAD`.remote

7. Pull the remote branch as rebase way

git pull --rebase <remote name> <branch name>

http://gitready.com/advanced/2009/02/11/pull-with-rebase.html and set it default when pull

git config branch.<branch name="">.rebase true</branch>

8. Get the current upstream/branch info

git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)

9. List the revisions

if [ "$oldrev" -eq 0 ]; then
    # list everything reachable from newrev but not any heads
    git rev-list $(git for-each-ref --format='%(refname)' refs/heads/* | sed 's/^/\^/') "$newrev"
else
    git rev-list "$oldrev..$newrev"
fi
# Reference: http://stackoverflow.com/questions/3511057/git-receive-update-hooks-and-new-branches

9. Strip some folders from a repo

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch -r android/apps android/libraries ios' --prune-empty --tag-name-filter cat -- --all

10. Split a folder to an individual repo

git filter-branch --prune-empty --subdirectory-filter YOUR_FOLDER_NAME master

11. Sync to another repo with patch way

git format-patch <rev> <files...>
# example:
git format-patch 03f72698 android/jni/ common/ thirdparty/ Makefile

and apply patches:

git am *.patch
⚠️ **GitHub.com Fallback** ⚠️