git之github笔记

来源:互联网 发布:大数据 普惠金融 论文 编辑:程序博客网 时间:2024/06/07 02:58

参考文章:

http://www.cnblogs.com/fnng/archive/2012/01/07/2315685.html

http://rangercyh.blog.51cto.com/1444712/749490/


1、注册github账号,安装windows版本git工具

2、在github New Repository

3、连接github,使用命令ssh-keygen –t rsa –C “jsjlgl@126.com”生成公钥,默认位置在个人文档的.ssh里面,复制id_rsa.pub中的文字到github的ssh key中

4、在使用命令ssh –T git@github.com测试是否连接上时,命令行报错Bad file number,参考第二篇文章添加config文件,将端口号指向443,可以成功连接了

5、因为我在创建Repository的时候github引导我创建了REDME和.gitignore文件,所以我想先将项目下载下来,将我原有的文件添加进去再上传

6、使用命令git clone git@github.com:liguanliang2014/dian24.git clone项目到当前文件夹,发现它又在我创建的dian24里面弄了一个dian24文件夹,重复了,下次注意。将我原来项目的代码和资源复制到了这里

7、使用命令git status查看当前的状态

8、使用git add 命令添加要提交的文件或文件夹

9、使用git commit -m"提交时的说明" 命令提交更改到本地。这里有个问题,一开始我直接使用git commit提交,进入一个类似vim的编辑界面,让我输入本次提交的说明,but我输完不知道怎么退出编辑,强行把命令窗口关了,哎

9、使用命令git push -u origin master将更改提交到github


#2016-01-07修改

我使用eclipse的git插件想要再次提交项目的时候,直接提交出现错误:rejected - non-fast-forward错误,找到解决方法(http://stackoverflow.com/questions/22636772/eclipse-repository-state-conflict-error),贴到这里:

I had this same problem and I was able to fix it. afk5min was right, the problem is the branch that you pulled code from has since changed on the remote repository. Per the standard git practices(http://git-scm.com/book/en/Git-Basics-Working-with-Remotes), you need to (now) merge those changes at the remote repository into your local changes before you can commit. This makes sense, this forces you to take other's changes and merge them into your code, ensuring that your code continues to function with the other changes in place.

Anyway, on to the steps.

  1. Configure the 'fetch' to fetch the branch you originally pulled from.

  2. Fetch the remote branch.

  3. Merge that remote branch onto your local branch.

  4. Commit the (merge) change in your local repo.

  5. Push the change to the remote repo.

In detail...

  1. In eclipse, open the view 'Git Repositories'.

  2. Ensure you see your local repository and can see the remote repository as a subfolder. In my version, it's called Remotes, and then I can see the remote project within that.

  3. Look for the green arrow pointing to the left, this is the 'fetch' arrow. Right click and select 'Configure Fetch'.

  4. You should see the URI, ensure that it points to the remote repository.

  5. Look in the ref mappings section of the pop-up. Mine was empty. This will indicate which remote references you want to fetch. Click 'Add'.

  6. Type in the branch name you need to fetch from the remote repository. Mine was 'master' (btw, a dropdown here would be great!!, for now, you have to type it). Continue through the pop-up, eventually clicking 'Finish'.

  7. Click 'Save and Fetch'. This will fetch that remote reference.

  8. Look in the 'Branches' folder of your local repository. You should now see that remote branch in the remote folder. Again, I see 'master'.

  9. Right-Click on the local branch in the 'Local' folder of 'Branches', which is named 'master'. Select 'Merge', and then select the remote branch, which is named 'origin/master'.

  10. Process through the merge.

  11. Commit any changes to your local repository.

  12. Push your changes to the remote repository.

  13. Go have a tasty beverage, congratulating yourself. Take the rest of the day off.


0 0
原创粉丝点击