文章目录
- 本地新建一个仓库要push到github上
- git pull拒绝合并无关历史
- git pull: 当前分之没有跟踪信息
- 想要统计github仓库代码
- 每次git clone过慢
- 每次提交都要输用户名和密码
- git 的撤销操作
- git的分支管理
- 由于没有公钥,无法验证下列签名
- 删除远程仓库文件
- git切换到指定远程分支
- github仓库迁移
- 子模块增删
- 子模块更新报错Server does not allow request for unadvertised object
- 子模块更新到最新
- 忽略本地更新git pull
- 将当前修改的内容提交到新的分支上
- 合并后查看哪些文件有冲突
- Cherry-pick
- 将一个feature合并到一个release,并只保留一次提交记录
本地新建一个仓库要push到github上
- 在
github
上创建一个同名空仓库 - 在本地仓库中执行 :
$: git init
$: git add
$: git commit
$: git remote add origin "本地分支名:远程分支名"
$: git push -u origin master
一般本地分支名和远程分支名一样
git pull拒绝合并无关历史
执行 git pull 报错:
fatal: refusing to merge unrelated histories // 拒绝合并无关历史
执行 :
git pull origin master --allow-unrelated-histories
//更新:温馨提示,暴力手法,我记得这个命令应该是和线上保持一致
git pull: 当前分之没有跟踪信息
- 可以指定为:
git pull origin master
- 或者可以设置它, 使你的本地主分之跟踪 github 主分支作为上游:
git branch --set-upstream-to=origin/master master
git pull
想要统计github仓库代码
- 查看github仓库代码量 :
在本地仓库中运行:git log --author="username" --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 }' -
username为你的用户名
-
统计每个人增删行数
git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --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 }' -; done
-
查看仓库提交者排名前五的人
git log --pretty='%aN' | sort | uniq -c | sort -k1 -n -r | head -n 5
-
添加或修改的代码行数:
git log --stat|perl -ne 'END { print $c } $c += $1 if /(\d+) insertions/'
每次git clone过慢
加参数--depth=1
,
$: github clone --depth=1 仓库地址
只拉取最近一次的 commit