git 版本控制

参考博客:

http://www.cnblogs.com/ximiaomiao/p/7140456.html

http://www.cnblogs.com/smuxiaolei/p/7484678.html

 

1.注册GitHub账户

https://github.com/

 

2.登录成功

 

3.创建仓库

 

#…or create a new repository on the command line

echo "# 02" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/venicid/02.git
git push -u origin master


#…or push an existing repository from the command line

git remote add origin https://github.com/venicid/02.git
git push -u origin master

  

 

2.电脑安装git版本控制软件

  安装步骤:http://www.cnblogs.com/smuxiaolei/p/7484678.html

  

 

 

 

 

 

 

3.上传文件到GitHub

 

 

 

 

 

 

 5.进入项目目录

 

1. 通过命令 git init 把这个目录变成git可以管理的仓库,如下:

2.创建文件

 

3.暂存区:添加README.md到暂存区

 

 5.过命令git status来查看是否还有文件未提交,

 

 

4.:本地仓库:用命令 git commit告诉Git,把文件提交到本地仓库。  提交注释

  本地仓库是.git

 

 

 5.过命令git status来查看是否还有文件未提交,

 

 

 

6.给远程仓库起个别名,此处需要登录

 

 

 7.push带远程仓库

 

8.刷新远程库

 

 

4.下载GitHub远程仓库目录到本地文件

1.进入一个目录

 

3.使用命令git clone克隆远程库下来

 

 

2.创建本地库

 

 

 3.修改文件

 

4.提交到暂存区

 

5.提交到本地仓库,报错,tell me who you are

 

 方法1:见提示就知道, 要您填上你得注册的邮箱和昵称,例如:

1 git config --global user.email "652081631@qq.com"
2 git config --global user.name "pys"

 

方法2:进入.git隐藏文件

 输入你的name emai

.git/config文件修改完成

 

 

6.提交到本地仓库 .git

 

7.push到远程仓库

 

 

 

5.回退到上个版本

1.使用git log命令查看所有的历史版本,

 

2.获取某个版本的id,下载下来

 

3.查看历史版本,只剩下2个了

 

 4.通过git pull命令,从远程仓库把项目拉下来

 

5.git log重新查看历史版本

 

 

6.错误


在使用git 对源代码进行push到gitHub时可能会出错,信息如下

$ git push -u origin master
To https://github.com/venicid/03--whole-bloger.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/venicid/03--whole-bloger.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 


出现错误的主要原因是github中的README.md文件不在本地代码目录中

 

方法/步骤

可以通过如下命令进行代码合并【注:pull=fetch+merge]

git pull --rebase origin master

 


执行上面代码后可以看到本地代码库中多了README.md文件

此时再执行语句 git push -u origin master即可完成代码上传到github

 

posted @ 2017-12-21 21:41  venicid  阅读(433)  评论(0编辑  收藏  举报