• 使用 Git@OSC 管理代码


    开源中国的 git 服务的地址是:http://git.oschina.net/

    以下记录 push 本地已有的项目至 git@osc 的过程。

    ① 注册登录之后,创建一个自己的项目:

    创建好的默认项目中包含一个 README.md 文件,用于项目的描述,使用 Markdown 编辑。

    ② 生成 ssh-key

    在 linux 下生成 ssh 公钥:

    [root@localhost ~]# ssh-keygen

    公钥保存的位置是 ~/.ssh/id_rsa.pub

    查看并复制公钥:

    [root@localhost ~]# cat ~/.ssh/id_rsa.pub

    把公钥的内容复制到 oschina 的 SSH 公钥中:

    保存。

    可以通过下面的命令查看公钥是否配置成功。

    [root@localhost ~]# ssh -T git@git.oschina.net

    输出:

    ③ 提交代码

    进入本地项目,将目录转化为 Git 版本库

    [root@localhost practise]# git init

    添加项目中所有的 file 至版本库

    [root@localhost practise]# git add .

    提交:

    [root@localhost practise]# git commit -m 'add practise files'

    添加到远程版本库,也就是 git@osc

    [root@localhost practise]# git remote add origin git@git.oschina.net:dee0912/practise.git
    [root@localhost practise]# git push -u origin master

    如果版本库中已有文件,在使用 push 命令的时候报错:

    To git@git.oschina.net:dee0912/practise.git
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'git@git.oschina.net:dee0912/practise.git'
    To prevent you from losing history, non-fast-forward updates were rejected
    Merge the remote changes before pushing again.  See the 'Note about
    fast-forwards' section of 'git push --help' for details.

    则先要把远程仓库中的文件 fetch 到本地然后再 merge,这两步相当于 git pull

    [root@localhost practise]# git fetch
    [root@localhost practise]# git merge

    如果出现以下信息:

    [root@localhost practise]# git merge
    usage: git merge [options] <remote>...
       or: git merge [options] <msg> HEAD <remote>

    则输入以下命令即可:

    [root@localhost practise]# git config branch.master.remote origin
    [root@localhost practise]# git config branch.master.merge refs/heads/master
    [root@localhost practise]# git pull

    说明:

    1 当你处于 master branch,默认的 remote 就是 origin

    2 当你在 master branch 上使用 git pull 时,没有指定 remote 和 branch,那么 git 就会采用默认的 remote(也就是origin)来 merge 在 master branch 上所有的改变

    参考:

    http://git.oschina.net/oschina/git-osc/wikis/home

    http://git.oschina.net/wzw/git-quick-start

    配置ssh公钥访问oschina

    github上传时出现error: src refspec master does not match any解决办法

    Git错误non-fast-forward后的冲突解决

    git pull 失败 ,提示:fatal: refusing to merge unrelated histories

  • 相关阅读:
    什么是 Native、Web App、Hybrid、React Native和Weex?
    什么是 Native、Web App、Hybrid、React Native和Weex?
    线性表—使用链表实现
    Twins:眼红红
    产品中心
    Koa 学习
    乐山大佛
    Ftp Centos · GitBook
    install jekyll
    MIZ702N开发环境的准备1
  • 原文地址:https://www.cnblogs.com/dee0912/p/5268011.html
Copyright © 2020-2023  润新知