reset author on any commit

// update user.name user.email to new person 
git rebase -i
// change first word to edit on the line of that commit 
git commit --amend --reset-author
git rebase --continue

patch

# format a patch from git log
git format-patch COMMITID
# apply patch
git am 00001-xxxx.patch

find files been changed since a commit

To find files been changed since a commit, we can use git-diff

git diff --name-only commitID...HEAD   #show file name only
 a.py
 b.sh
git diff --name-status commitID...HEAD #show file name and status(modified, added...)
M a.py
M b.sh
git diff --stat commitID...HEAD        # inclue lines change statistics
 a.py    | 1 +
 b.sh    | 2 +-
 2 files changed, 2 insertions(+), 1 deletions(-)
 
git diff --name-only HEAD~2            # changes from last 2 commit to HEAD

cherry-pick

After make a commit on one branch, if you want to make the same commit on the other branch, cherry-pick is what you needed.

#eg: abcd is the commit id of branch A
#on branch B
git cherry-pick abcd
git reset --merge ORIG_HEAD  #cancel the commit picked.
#other useful command
#man git-cherry-pick
git cherry-pick topic^

#Apply the changes introduced by the fifth and third last commits pointed to by master and create 2 new commits with these changes.
git cherry-pick master~4 master~2

Add tag

Add a tag with signature, and push tag to origin.

git tag -s -u YOURNAME -m "COMMENT FOR TAG"  x.y.z  xxxxxcommitid
git push origin --tags

git-dir & work-tree

git-dir(.git dir) and work-tree is the same by default, sometime are not. We can define them with cmd switch.

git --git-dir=./.git --work-tree=../newtree_for_some_commit status
# Lots of file will be seen lost in newtree_for_some_commit dir
git --git-dir=./.git --work-tree=../newtree_for_some_commit checkout -b tmp -f master
# force checkout master to newtree_some_commit
git --git-dir=./.git --work-tree=../newtree_for_some_commit branch -d tmp

git log

Show commit between two tags:

git log --pretty=oneline tagA...tagB
git log --oneline tagA...tagB

If you just wanted commits reachable from tagB but not tagA:

git log --pretty=oneline tagA..tagB    

or

git log --pretty=oneline ^tagA tagB

Search branch contains a commit:

git branch -r --contains commitXXX

Show log graph

git log --oneline --decorate --graph --all
   --all will show all logs other than logs on current branch
   

If you want to find all commits where commit message contains given word, use

$ git log --grep=word

how-do-i-blame-a-deleted-line

If you know the contents of the line, this is an ideal use case for:

git log -S <string> path/to/file