Memo for some Git commands and tasks
git checkout <commit> <file> # check out a certain verion of a file
git cherry -v # output commits that are not in the remote branch (-v verbose)
git cherry -v <remote>/<branch> # output commits that are not in another upstream branch
git clean -df # force removing files/directories that are not under version control
git config -l # show all inherited values from: system, global and local (-l shorthand of --list)
git config -e # edit config (-e shorthand of --edit)
git diff --cached # show staged change
git diff --name-only # only show diffed file names
git diff <branch> -- <file> # diff the file in different branch
git fetch origin # synchronize with origin
git lfs install # install LFS. If LFS is installed by brew, it has to be installed in the project directory
git lfs track <pattern> # start tracking a certain pattern
git lfs track # list tracked patterns
git lfs ls-files # list tracked files
git log --author=<pattern> # show commits matching author pattern
git log --after=<yyyy-m-d> --before=<yyyy-m-d> # show commits within a assigned date range
git log --grep=<pattern> # search matching commit messages
git log <file path> # show commits of the specified file
git log origin<branch> # show commits in the origin remote
git remote show origin # show remote origin
git remote add <remote_name> <remote_url> # add a new remote
git remote -v # print remote info
git remote rename <old_name> <new_name> # rename remote
git remote rm <name> # remove remote
git remote update # fetch updates from remotes
git reset <filepath> # unstage staged changes in the file
git reset HEAD~<number> # reset a number of commits, --hard, --soft, --mixed(default)
git show-ref --tags # show tagged commits
git stash save <message> # save stash with a message
git stash list # show all stashes
git stash pop # apply the latest stash
git stash clear # clear all stashes
git stash drop stash@{<index>} # drop the stash at the specified index
git stash show -p stash@{<index>} # show the content of the stash at the specified index
git tag <tagName> <commitHasH> # tag a commit
git tag -d <tagName> # delete a tag
git show <tagName> # show tag content
git branch -m <new_branch> # rename current branch locally
git branch -m <old_branch> <new_branch> # rename branch locally
git push origin :<old_branch> <new_branch> # delete the old branch
git push --set-upstream origin <new_branch> # push the new branch, set local branch to track the new remote
git branch -d <branch_name> # delete local branch
git push <remote> -d <branch_name> # delete remote branch
git fetch <remote>
git reset --hard <remote>/<branch>
git diff <tag1>..<tag2> > <patchName>.patch
git apply <patchName>.patch