git hub的一些基本操做

如下介绍GITHUB的一些基本操做和命令;没有什么理论,以实践为主git


准备工做github

①:在www.github.com网站注册本身的账号shell

②:在本地的机子上安排GIT HUB的客户端bash


GITHUB使用的情景一:服务器

在github网站上建立一个git仓库,Copy到本地ide

①:登陆到GITHUB工具

②:在[Repositories]页签中,找到New按钮,建立一个GIT仓库,假定名称为"HelloGIT"fetch

输入描述信息,点击"Create repository"完成在WebSite中建立Git仓库网站

建立HelloGit完成后,能够看到它其实是执行了如下命令:rem

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/zyguo1006/HelloGit.git
git push -u origin master

以上,是建立GIT仓库的代码,咱们在Git Shell中也能够直接用这些命令,建立一个Repository并Push到GitHub Website.如下是这些命令的说明:

1:建立一个readme的文件,

2:初始化github repository,

3:使readme.md文件处于Stage状态, (若是修改了文件,也须要使用git add "xxx.txt"提交这些变动)

4:提交上面的修改,并添加信息.

5:建立一个origin在git上,

6:建立主分支.


操做场景二: 把这个新建立的仓库Clone到本地,并在本地建立一个文件,提交到Git Hub

打开Git Shell窗口,找到要放置Git仓库的文件夹,我假设放在E盘:先进入到E盘.


 
 
git clone https://github.com/zyguo1006/HelloGit.git

把GitHub中的仓库Copy到了E盘. 而后,在HelloGit文件夹下建立一个readme.txt文件,并写入一些内容.如今要把readme.txt文件提交到GitHub服务器的HelloGit仓库中.则执行如下操做便可:


cd E: ./HelloGit
git add "readme.txt"
git commit -m "add readme file by git shell"
git push

操做场景三: 对同一文件进行修改,冲突的解决

①:先在WebSite中修改readme.txt文件夹的内容,并提交.

②:而后在本地修改readme.txt的内容,

执行如下操做:


git add "readme.txt"
git commit -m "update readme file at local then submit"
git push

以上,是把修改的readme.txt的内容提交到GitHUB master.可是因为原来这个文件已经有修改,故冲突,产生了如下问题:

! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/zyguo1006/HelloGit.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 merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

如何解决冲突呢?

第一种方法是强制覆盖:


git push -f

这样,就会把原来的修改给覆盖掉,只剩下Client提交的修改

第二种方法是先取得已经提交的修改,比较冲突,修改完成后,再提交:


git pull

这样,readme.txt文件出现如下状况:

HelloGIT at client
<<<<<<< HEAD
Update readme file at local and submit to test reslove the confict.
hubert
=======
Update readme file at local and submit to test reslove the confict
testsdfsdfsdfsdfsdfsd
>>>>>>> 239b3c2cedd978fdd9f567ce6920fc17e7110daa

其中 <<<<<<< Head和========之间的部分是本次要提交的

=======和>>>>>>>是服务器上如今的,

把这些符号去掉后,就执行


git add "readme.txt"
git commit -m "meger readme"
git push


就能够提交成功.


第三种是在第二种的基础上用代码比较工具,完成比较和合并和再提交.

相关文章
相关标签/搜索