git操作
设置用户名:
git config --global user.name "cxp"
设置邮箱:
git config --global user.email "cxp@qax.com"
生成ssh秘钥:
ssh-keygen -t rsa -C "cxp@qax.com"
clone代码:
git clone git地址
clone指定分之代码:
git clone -b 分之名 git地址
切换分支:
git checkout 分之名
代码回退到指定版本
场景1:修改了文件/path/to/file,没有提交,但是觉得改的不好,想还原。
解决:git checkout -- /path/to/file
场景2:修改了文件/path/to/file,已经提交,但是觉得改的不好,想还原到上衣版本。
解决:
1. 首先查看文件的历史版本。git log /path/to/file
2. 找到你想要还原的版本。如commit 052c0233bcaef35bbf6e6ebd43bfd6a648e3d93b
Author:11<111@gmail.com>
Date: Wed Nov 8 11:48:31 2017 +0800
commit modify/path/to/file
3. 将文件还原到你想要还原的版本。$ git checkout ${commit} /path/to/file
。即$ git checkout 052c0233bcaef35bbf6e6ebd43bfd6a648e3d93b /path/to/file
4. 这时查看文件,会发现文件已经还原了。(如果没有还原,请刷新再看。)
5. commit、push。
git撤回到某条记录并推送远程分支:
git reset --hard loghash值
git push origin 分支名 --force
重新定义起点(更方便的解决代码merge的冲突):
git rebase
查询指定当前文件夹下指定时间范围内代码负责人为cxp的添加代码行数,删除代码行数,最终代码行数
git log --since='2020-12-01' --until='2020-12-03' --author="cxp" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -