1. 将代码回退到特定时间点
背景:当项目代码在开发过程中出现了问题,而清楚记得某一个时间的的代码未出现该问题。于是想将代码回退到该时间节点前。
可使用如下命令:
repo forall -c 'commitID=`git log --before "yyyy-mm-dd hh:mm" -1 --pretty=format:"%H"`; git reset --hard $commitID'
2. 解决打补丁时的冲突
背景: 当在打补丁的过程中遇到冲突时,可以通过如下方式解决冲突:
git am xxxxx.patch //Error because of conflict
git apply --reject xxxxx.patch //then files not conflict in this commit will merge into local
git status//find which files is modified
//fix the conflicts
git add -u
git am --resolved xxxx.patch
3. 使用代理下载git仓库
背景:当下载国外代码时下载不动时,比如Android系统源码,可以通过代理方式下载:
git config --global http.proxy 'socks5://127.0.0.1:1080'
4. 设置git的颜色
背景:当使用git diff时,发现代码颜相同难以区分时:
git config --global color.ui auto
5. 迁移上传gerrit代码