Skip to content
破仑的博客
Go back

Git备忘

部分命令参考了这篇文章

命令

配置命令别名:

git config --system alias.{short name} {origin name}

列出所有别名配置:

git config --get-regexp alias

解决Git命令输出中文文件名的显示问题: git config --system core.quotepath false

Git命令输出中开启颜色显示: git config --system color.ui true

打标签:

重命名分支:

设置默认编辑器

删除远程分支:

删除文件:

删除远程不存在的本地分支引用:

git fetch -p(—prune)

合并最近n次提交:

git rebase --interactive HEAD~n http://stackoverflow.com/questions/2563632/how-can-i-merge-two-commits-into-one

列出没有合并的文件

git diff --name-status --diff-filter=U

rebase

应用场景1—将当前分支重新base到最新master

这样就不用merge了,保持当前分支的纯净。根据需要rebase到合适的分支。

git rebase {branch name}

应用场景2—合并提交

根据习惯/要求不同,可以删除一些当前分支临时性的提交,以保持提交记录的漂亮。

git rebase --interactive HEAD~n # 以交互的方式rebase最近n次提交

日志

git shortlog -sne

# output
$ git shortlog -sne
    54  zhenqiang <zhangzq@zigzen.cn>
    13  polun <965076377@qq.com>
    12  polunzh <polunzh@gmail.com>
     9  zhangzhenqiang <zhangzq@zhicang.market>
     1  polunzh <polunzh@gmailc.com>

配置相关

问题

  1. git status 乱码 git config --global core.quotepath false

工具

存储凭证

存储选项

  1. 默认不存储
  2. cache 存储在内存, 15 分钟后从内从中清除,该选项后有一个 --timeout <seconds> 参数
  3. store 以明文的方式存储在磁盘,永远不会过期, 该选项后有个 --file <path> 参数

还有其它两种分别针对于 WindowsOSX 平台的配置,但是我从来没用过,所以我就不在这里记了。

Example:

git config --global credential.helper cache --timeout 9000
git config --global credential.helper store --file '~/.myfile'

refusing to merge unrelated histories 错误

From: http://blog.csdn.net/lindexi_gd/article/details/52554159

pull 远程数据的时候出现 refusing to merge unrelated histories 错误,这是因为远程仓库和本地仓库不是同一个仓库的原因,如果确信要合并,可以在 pull 的时候使用 --allow-unrelated-histories 参数:

git pull origin master --allow-unrelated-histories

RPC failed; result=22, HTTP code = 411 错误

From: https://stackoverflow.com/questions/12651749/git-push-fails-rpc-failed-result-22-http-code-411

这是因为 Git 默认的配置将某些 HTTP 操做限制为 1M 字节,修改默认限制:

git config http.postBuffer *bytes*

有用的命令

  1. 搜索IP: git grep -E "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"

Share this post on:

Previous Post
ES6 Exploring 笔记
Next Post
JavaScript常用数组迭代方法