利用git提交代码的方法步骤
$ git push origin master Counting objects: 34, done. Delta compression using up to 4 threads. Compressing objects: 100% (29/29), done. Writing objects: 100% (34/34), 15.63 KiB | 0 bytes/s, done. Total 34 (delta 3), reused 0 (delta 0) To https://git.oschina.net/liuqiqiang/gitTest.git 5e2dda1..537ecfe master -> master 即将代码成功提交到远程库!!! 注:如果pull之后出现 “ refusing to merge unrelated histories ”这句,就证明你合并pull两个不同的项目 出现的问题如何去解决fatal: refusing to merge unrelated histories 我在Github新建一个仓库,写了License,然后把本地一个写了很久仓库上传。 先pull,因为两个仓库不同,发现refusing to merge unrelated histories,无法pull 因为他们是两个不同的项目,要把两个不同的项目合并,git需要添加一句代码,在git pull,这句代码是在git 2.9.2版本发生的,最新的版本需要添加--allow-unrelated-histories 假如我们的源是origin,分支是master,那么我们 需要这样写git pull origin master --allow-unrelated-histories需要知道,我们的源可以是本地的路径 接着到你的远程库查看,提交前: 提交成功后: 注意:操作的时候,指令不要输错了!!!! 下面这个是输错了 orgin的输出: git pull orgin master fatal: 'orgin' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 正确的应该是origin!! 如果在push的时候有如下输出: $ git push -u origin master To https://git.oschina.net/liuqiqiang/LQQCircleShowImage.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://git.oschina.net/liuqiqiang/LQQCircleShowImage.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. 看提示可知道,需要先pull一下,即执行一次:git pull origin master 然后再执行:git push origin master 分支管理 新建分支 $ git branch newbranch 查看分支 $ git branch 输出: * master newbranch *代表当前所在的分支 切换分支 $ git checkout new branch 输出 Switched to branch 'newbranch' 切换后可用git branch查看是否切换到当前分支 master * newbranch 提交改动到当前分支 $ git add . $ git commit -a 可使用git status查看提交状态 接着切回主分支 $ git checkout master 输出: Switched to branch 'master' 将新分支提交的改动合并到主分支上 $ git merge newbranch 输出: Updating cc73a48..93a1347 这里我提交了两个文件,即:test.h和test.m 如果合并后产生冲突,可输入以下指令查看冲突: $ git diff 修改之后,再次提交即可; 接下来,就可以push代码了: $ git push -u origin master 这时可能需要你输入你的github用户名和密码,按照提示输入即可; 删除分支 $ git branch -D newbranch 输出 Deleted branch newbranch (was 93a1347). 以上就是最简单的github操作了,也是在网上看着学的,注意在实际操作中多加练习,代码这东西,刚开始桥的多了也就记下了! (编辑:焦作站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |