git 使用中遇到的一些问题

SmartGit

是git的一种很好用的可视化工具,收费的。能够注册非商业用途无偿使用。注册地址 注意,使用git仓库用户的邮箱注册。若是注册邮箱和git仓库的用户邮箱不一致,会出现弹窗。linux

>> git使用中的一些问题:

  1. 使用SSH keys 免密操做git:
    • linux使用xshell等SSH客户端
    • windows使用Git Bash:
$ ssh-keygen -t rsa -C "yisangwu@hao123.com"  -b 4096  # 使用git帐号生成密钥
   $ cat ~/.ssh/id_rsa.pub  # 复制公钥,添加到我的设置的ssh key里面。
  1. 本地项目,关联git远程仓库:
```shell
$ git init  # 初始化一个新本地仓库
$ git remote add origin git_url  # 创建和远程仓库的链接
$ git remote -v  # 查看远程地址
$ git pull origin master  # 拉取远程master分支
  1. 修改git远程仓库地址:
$ git remote set-url origin new_git_url
  1. 拉取远程代码报错,fatal: refusing to merge unrelated histories:
# branch_name 对应远程分支名
$ git pull origin branch_name --allow-unrelated-histories  
# 再进行 git 操做
  1. git clone --depth=1 远程分支看不到的问题:

有些git仓库代码过大,达到几个G,初始化clone或者fetch分支时,常常timeout,或者bad header。即便修改了git的配置,仍是会出现拉取失败!!git

# depth指定克隆深度,为1即表示只克隆最近一次commit
$ git clone --depth 1 https://git123.com/group_name/coder.git
$ git remote -r   #查看远程分支, 此时看到的只有master
$ git remote set-branches origin remote_branch_name  # 添加远程分支
$ git fetch --depth 1 origin remote_branch_name  # fetch远程分支,深度为1
$ git checkout remote_branch_name
  1. git忽略文件权限修改,避免修改文件权限致使的文件冲突或修改:
$ git config core.filemode false  # 在仓库目录下执行
  1. 远程分支不存在,可是本地还有:
$ git pull -p  # 在仓库目录下执行
相关文章
相关标签/搜索