美文网首页
git 常用问题和命令总结

git 常用问题和命令总结

作者: superlee01 | 来源:发表于2018-12-26 20:03 被阅读0次

拉取指定tag的代码

  • 查看仓库所有tag
    git tag ls
  • 切到指定tag
    git checkout tags/<tag_name>
  • 将tag切换到本地指定分支
    git checkout tags/<tag_name> -b <branch_name>

解决error: RPC failed; curl transfer closed with outstanding read data remaining问题

出现这个问题的原因一般是git仓库比较大,或者git clone网速缓慢,导致连接关闭。

解决思路是先进行浅层克隆,然后使用历史记录更新存储库

git clone http://github.com/large-repository --depth 1
cd large-repository
git fetch --unshallow

上面的方式虽然可以拉下代码,但是使用git branch -a只能看到本地master分支和远程master 分支,使用git fetch命令并不能拉取所有远程分支,这是因为配置远程fetch,使用如下命令即可解决这个问题:

//$表示输入的命令,->表示命令行的响应
$ git config --get remote.origin.fetch
-> +refs/heads/*:refs/remotes/origin/*
$ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
$ git config --get remote.origin.fetch
-> +refs/heads/*:refs/remotes/origin/*

git push的时候报the remote end hung up unexpectedly

原因

git push包含大于1m的打包对象时,Smart HTTP协议在post请求的时候使用Transfer-Encoding: chunked,也就是说推的文件里包含大文件。

解决方法

增加repo最大单个文件的缓冲区大小:
git config http.postBuffer 524288000

git远程仓库迁移到新的仓库

  • 先将旧的仓库拉本地
  • 使用如下脚本,将所有分支拉到本地
#!/bin/bash
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
    git branch --track "${branch##*/}" "$branch"
done
  • 查看所有tag和分支
git tag
git branch -a
  • 移除旧的仓库
git remote rm origin
  • 添加新的仓库
git remote add origin <url to NEW repo>
  • 将所有分支和tags推到远程仓库
git push origin --all
git push --tags

多远程仓库情况下,从某一个仓库拉取某一个tag

git fetch your_remote --tags
git checkout tags/xxx -b xxx

使用git rebase合并多次commit

首先查看git提交历史

git log --oneline

会看到如下数据

91beb50c  [REF] 重构
8d227653 [REF] 重构
26db0f5b [REF] 重构
6fc3d376 [REF] 重构
...

我们需要把这四个提交信息合并为一个commit,使用如下命令:

git rebase -i HEAD~4

表示合并从head往前数四条commit,之后会有如下弹窗

pick 6fc3d376 [REF] 重构
pick 26db0f5b [REF] 重构
pick 8d227653 [REF] 重构
pick 91beb50c [REF] 重构

# Rebase 031ab44d..91beb50c onto 031ab44d (4 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message

编辑该文件,将后面三个pick改为s,s表示将该commit与前一个commit合并。修改如下:

pick 6fc3d376 [REF] 重构
s 26db0f5b [REF] 重构
s 8d227653 [REF] 重构
s 91beb50c [REF] 重构

# Rebase 031ab44d..91beb50c onto 031ab44d (4 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message

然后wq保存退出即可。如果有冲突,解决冲突,然后git add .再执行 git rebase --contine提交。没有冲突或者冲突解决,会弹出如下界面,保存即可将commit合并。

# This is the 1st commit message:

[REF] 重构

# This is the commit message #2:

[REF] 重构

# This is the commit message #3:

[REF] 重构

wq保存退出即可合并commit了

相关文章

  • git 常用问题和命令总结

    拉取指定tag的代码 查看仓库所有taggit tag ls 切到指定taggit checkout tags/<...

  • git 命令

    Git常用命令总结Git常用命令总结 git init 在本地新建一个repo,进入一个项目目录,执行git ...

  • git相关教程汇总

    1. git常用命令 git常用命令总结git常用命令讲解 2. git教程相关网站 廖雪峰的git教程猴子都能懂...

  • Git 常用指令

    Git常用命令总结 Git常用命令总结 git init 在本地新建一个repo,进入一个项目目录,执行git i...

  • GIT 常用命令总结

    GIT 常用命令总结 GIT 初始化命令 命令描述git init初始化本地 git 仓库git config -...

  • git 命令汇总

    git 命令汇总 常用总结 1.$ git help 查看git所有命令的帮助 2.$ git config --...

  • Git与Github的使用总结 - day 03

    git常用命令总结 git配置(config): git仓库(repository): git分支(branch)...

  • Git常用命令

    Git 常用命令总结 git的一些基础命令 Git常用命令 一般配置 登录git 创建一个文件夹 初始化git仓库...

  • 个人git知识总结

    个人常用的git命令以及相关知识总结,具体git命令的介绍可以查看官网。 1.常用命令一览 2.常用命令使用场景 ...

  • git常用命令

    对git常用命令做个总结,以便以后使用:

网友评论

      本文标题:git 常用问题和命令总结

      本文链接:https://www.haomeiwen.com/subject/vuyklqtx.html