Git practical sheet

Git practical sheet

Welcome to my blog. Help yourself.
----- perrin

2019-03-17 14:28


Find code change.

git log --reverse
git log -S 'code_added'  # get commits whose content contains the keyword
git log -S 'code_added' -p | grep 'code_added' -U5  # show the content with context lines preceding and following by 5 lines. 
git log v1.0..v2.0  # show commits between tag v1.0 and tag v2.0
git log -L <start>,<end>:<file> # need type full path of the file. A little annoying
git log -L :<funcname>:<file>  # ":funcname"  regex supported

Further reading

https://devhints.io/git-log

https://devhints.io/git-log-format

 

 

Regex

https://stackoverflow.com/questions/24879041/how-to-use-regex-in-git-checkout-command-to-specify-file-subsets

If there are no quotes, the shell will do the regex. Or it will be passed to git.

$rm a.c
$git checkout *.c  # not a.c
$git checkout '*.c'  # a.c will be checkout 
git checkout myBranch **/myFile.md
git checkout myBranch  **/*Test*

 

Merge

git merge origin/master --no-ff # create a new commit whether can be fast-forward or not

git checkout --ours word.txt    # << head
git checkout --theirs word.txt  # >> commit hash

# rebase # may be in reverse order, be cautious
git checkout --ours word.txt    # << head
git checkout --theirs word.txt  # >> commit hash

git pull/merge develop -X/s  theirs/ours

https://git-scm.com/docs/merge-strategies

 

Rebase

Change a commit's parent. It is useful when use gerrit and have two commits for review the same time.

https://stackoverflow.com/questions/3810348/setting-git-parent-pointer-to-a-different-parent

git rebase --onto new_parent_hash old_parent_hash

 


Commenter Name
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
Commenter Name
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
Commenter Name
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.
Search
Page view info
{'ip': '18.204.227.250', 'lat_lon': (39.0481, -77.4728), 'city': 'Ashburn', 'pv': 57922, 'cur_pv': 79, 'cur_daily_pv': 2, 'ur_pv': 6, 'ur_cur_all': 1, 'ur_today_all': 6, 'ur_today_cur': 1, 'daily_pv': 130, 'daily_ip': 81, 'whole_ip': 9791, 'ip_delta': 5}
AMap
Baidu Map