使用代码管理工具(git)管理代码的常用指令合集

 create a new repository on the command line

echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:qq2216691777/test.git
git push -u origin master

push an existing repository from the command line

git remote add origin git@github.com:qq2216691777/test.git
git push -u origin master    //把本地仓库的master分支推送到Github上
git push origin --tags      //把本地标签推送到Github上

  

import code from another repository

You can initialize this repository with code from a Subversion, Mercurial, or TFS project.


如果电脑上刚刚安装上git,则需要配置git
a. 首先在本地生成ssh公钥

ssh-keygen -C 'your emaildress' -t rsa  

会在用户目录~/.ssh/下建立相应的密钥文件

b、上传公钥至github
       在账户的profile里,选择SSH KEYS 选项,然后Add SSH Key,将~/.ssh/id_rsa.pub中的内容复制进去,上传。
      上上传成功后,会收到确认邮件。 可以使用ssh -v git@github.com命令来测试链接是否畅通。

现在你就可以管理项目了

可以在目录下创建一个名为".gitignore"的wenj。里面的内容表示某文件将不会被提交到仓库。

可以给某个版本号打上标签。

 

git push origin local_branch:remote_branch    //如果远程分支remote_branch不存在,则会自动创建  如果本地为空,则为删除远程分支

 

通常的git push不会将标签对象提交到git服务器,我们需要进行显式的操作:
$ git push origin v0.1.2 # 将v0.1.2标签提交到git服务器
$ git push origin --tags # 将本地所有标签一次性提交到git服务器

 

 代码回滚:

git reset –hard b7057a9

 如果回滚后想再恢复回来

git reflog 
git reset –hard b7057a9

  将服务器最新的代码更新下来

git checkout [remote branch]     //[remote branch] 可以为 master

 

如何将GitHub上的代码下载下来并管理 

首先新建一个文件夹

git init //执行初始化
git remote add origin git@gitee.com:xxx.git  //添加远端的git
git fetch origin master      //从远端获取最新的版本信息到本地
git checkout master     // 将远端的代码下载下来 

  

 

如何将修改后的代码上传到github:

git add -A //更新工程中被修改过的代码 
git commit -m “first commit” //为本次提交注明说明 
git tag V3//为本次提交打上标签 
git push -u origin master //将代码提交到github中 
git push origin -–tags //将标签提交到GitHub中

如何将本地的库更新成远端库的最新分支

git fetch origin master    //从远程的origin的master主分支下载最新的版本到origin/master分支上
git merge origin/master   //进行合并

  

 

posted @ 2017-01-14 14:14  叶念西风  阅读(995)  评论(0编辑  收藏  举报
叶念西风 - 个人博客 & 电脑Run - 维修帮助软件教程安装