zoukankan      html  css  js  c++  java
  • github

    Github

    New repository

    点击右上角加号,选择 New repository

    163账号被封

    Install client msysgit

    github是服务端,要想在自己电脑上使用git我们还需要一个git客户端,我这里选用msysgit,这个只是提供了git的核心功能,而且是基于命令行的。如果想要图形界面的话只要在msysgit的基础上安装TortoiseGit即可。

    Congiure git

    spreading为例

    Create ssh key

    ssh-keygen -t rsa -C your_email@youremail.com
    #Example
    ssh-keygen -t rsa -C navicester@qq.com
    

    后面的 your_email@youremail.com 改为自己的邮箱,之后会要求确认路径和输入密码,这里使用默认的一路回车就行。成功的话会在 ~/ 下生成 .ssh 文件夹,打开 id_rsa.pub,复制里面的 key,回到 github,进入 settings,左边选择 SSH keys,Add SSH Key,title 随便填,粘贴 key。

    Verify ssh key

    ssh -T git@github.com
    ssh -T -v git@github.com 可以打印debug信息
    

    如果是第一次的会提示是否 continue,输入 yes 就会看到:You've successfully authenticated, but GitHub does not provide shell access,这就表示已成功连上 github。

    常见问题1:关于ssh连接主机,git连接github失败的问题

    Clone your project

    接下来我们要做的就是把 github 上面建立的仓库克隆到本地,在此之前还需要设置 username 和 email,因为 github 每次 commit 都会记录他们。

    git config --global user.name your name
    git config --global user.email your_email@youremail.com
    #Example
    git config --global user.name navicester
    git config --global user.email navicester@qq.com
    

    第一次:添加远程地址

    git remote add origin git@github.com:navicester/spreading.git
    

    克隆到本地 (spreading)

    git clone git@github.com:navicester/spreading.git
    

    需要注意的是:github 提供了 3 种 url 路径(HTTPS,SSH,Subversion),一般如果账号处于登录状态,那么我们可以用 SSH,就像上面的代码,如果没有登录的话,只能用 HTTPS 的 url 了,如图所示:
    克隆成功,如下所示:

    modify your project

    方法1:直接修改.git/config

    [core]
    	repositoryformatversion = 0
    	filemode = false
    	bare = false
    	logallrefupdates = true
    	symlinks = false
    	ignorecase = true
    	hideDotFiles = dotGitOnly
    [remote "origin"]
    	url = git@github.com:navicester/lwc.git
    	fetch = +refs/heads/*:refs/remotes/origin/*
    [branch "master"]
    	remote = origin
    	merge = refs/heads/master
    [remote "heroku"]
    	url = https://git.heroku.com/lwc-ws.git
    	fetch = +refs/heads/*:refs/remotes/heroku/*
    

    方法2:(没试)

    git remote rm origin
    git remote add origin git@github.com:Liutos/foobar.git
    

    Pull

    git pull <远程主机名> <远程分支名>:<本地分支名>
    
    git pull username@ipaddr:远端repository名 <远端分支名> <本地分支名> 
    或者是:
    git pull origin <远端分支名> <本地分支名>
    

    git pull https://git.oschina.net/beckwen/WinFingerprintDriver.git wk:LocalBin

    这条命令将从远端git库的远端分支名获取到本地git库的一个本地分支中。其中,如果不写本地分支名,则默认pull到本地当前分支。

    1. 运行时碰到错误
    D:eclipse-workspacevirtualdirlwc_testlwc>git push
    ......
    To git@github.com:navicester/lwc.git
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'git@github.com:navicester/lwc.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    

    Issue : updates were rejected because the tip of your current branch is behind its remote counterpart
    有如下几种解决方法:
    1.使用强制push的方法:

    $ git push -u origin master -f 
    

    这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。
    2.push前先将远程repository修改pull下来

    $ git pull origin master
    $ git push -u origin master
    

    3.若不想merge远程和本地修改,可以先创建新的分支:

    $ git branch [name]
    

    然后push

    $ git push -u origin [name]
    

    Modify, Commit, Push

    我们可以修改克隆到本地的项目,修改完成后先要 add 修改的文件(. 表示全部),然后填写 commit,最后在 push 到 github。

    git push <远程主机名> <本地分支名>:<远程分支名>
    git push https://git.oschina.net/beckwen/WinFingerprintDriver.git LocalBin:wk
    
    git add .
    git commit -m 'update'
    git push [origin master]
    

    remote

    remote server/remote repository/remote branch
    local repository/local branch

    master就是local branch,origin/master是remote branch(master is a branch in the local repository. remotes/origin/master is a branch named master on the remote named origin)
    需要注意的是,remotes/origin/master和origin/master的指向是相同的

    git remote -v
    

    log

    D:eclipse-workspacegit_python_spreadingspreading>git remote -v
    origin  git@github.com:navicester/spreading.git (fetch)
    origin  git@github.com:navicester/spreading.git (push)
    

    gitignore

    比如我要忽略sumlime项目文件
    lwc.sublime-project
    lwc.sublime-workspace

    touch  .gitignore     #创建gitignore隱藏文件  
    vim    .gitignore     #编辑文件,加入指定文件 
    #下面是我的gitignore文件的内容  
    #忽略gitignore文件  
    .gitignore  
    #忽略后缀缀名为.o和.a的文件  
    *.[oa]  
    #或有sublime项目文件  
    lwc.sublime-project
    lwc.sublime-workspace
    

    git status

    git log

    SAE Git代码部署说明

    用户名 SAE安全邮箱
    密码 SAE安全密码

    在你应用的git代码目录里,添加一个新的git远程仓库 sae

    $ git remote add sae https://git.sinacloud.com/papillon
    

    编辑代码并将代码部署到 sae 的版本1。

    $ git add .
    $ git commit -am "make it better"
    $ git push sae master:1
    
    $ git pull sae 2
    

    SAE支持Git、SVN、代码打包上传三种提交方式,具体请参考:http://www.sinacloud.com/doc/sae/tutorial/code-deploy.html#git

    http://www.codingsoho.com
  • 相关阅读:
    RK3288 GMAC整理
    Linux电源管理-Linux regulator framework概述
    SRAM、DRAM、SDRAM、DDR、DDR2、DDR3
    内核错误值
    module_param和module_param_array用法
    VGA
    如何获取显示器的EDID信息
    进程间通信--共享内存
    Java 中的 CAS 简述及原理解析
    volatile 关键字特性解析及单例模式下的使用
  • 原文地址:https://www.cnblogs.com/2dogslife/p/5763518.html
Copyright © 2011-2022 走看看