git服务器的使用

来源:互联网 发布:js获取当前鼠标的位置 编辑:程序博客网 时间:2024/06/06 11:03
<span style="font-size:32px;"><a target=_blank href="http://blog.csdn.net/hgz_gs/article/details/52039469">何:http://blog.csdn.net/hgz_gs/article/details/52039469</a></span>
<span style="font-size:24px;">  git init仓库被初始化1.git add 添加文件到staged area(索引).2.git diff --cached/git status查看添加到索引的文件那些进行修改了   git diff master..test显示master与test版本的差别3.git commit 提示进程注释,完成后就会记录一个新的项目版本,提交git commit -a自动把所有内容被修改的文件(不包括新建的文件)添加到索引中,并提交4.git branch he创建一个he分支5.git branch查看分支,*表示当前工作分支   gitk显示项目的历史  git branch  -d he删除分支  git branch -Dhe强制删除分支6.git checkout he切换分支  git checkout -b mywork origin基于远程分支"origin",创建一个叫"mywork"的分支7.git merge he合并分支,把he合并到当前8.git reset --hard HEAD撒销一个合并9.git clone /home/alice/project myrepo克隆  git clone git://git.kernel.org/pub/scm/git/git.git  git clone http://www.kernel.org/pub/scm/git/git.git  git clone https://github.com/bugquella/cqc.git  git clone git@github.com:bugquella/cqc.git10.git pull /home/bob/myrepo mastergit pull命令执行两个操作: 它从远程分支(remote branch)抓取修改 的内容,然后把它合并进当前的分支11.git remote add bob /home/bob/myrepogit remote命令建立了Bob的运程仓库的缩写,用这个(缩写) 名字我从Bob那得到所有远程分支的历史记录   git fetch bob执行"git pull"前半部分的工作, 但是这条命令并不会把抓下来的修改合并到当前分支里   git remote show origin 查看远程消息   git remote add origin git@github.com:cqcre/cqc.git 建立远程分支   git remote -v查看远程分支   git fetch origin master从远程的origin仓库的master分支下载代码到本地的origin master12.git log -p master..bob/master上面的命令把Bob从Alice的主分支(master)中签出后所做的修改全部显示出来13.git merge bob/master把修改合并到她的主分支中   git merge origin/master把远程下载下来的代码合并到本地仓库,远程的和本地的合并14.git loggit log命令可以显示所有的提交15.git log v2.5.. Makefile fs/找出所有从"v2.5“开 始在fs目录下的所有Makefile的修改16.git log -p显示补丁17.git log --stat显示在每个提交(commit)中哪些文件被修改了, 这些文件分别添加或删除了多少行内容18.git push ssh://yourserver.com/~you/proj.git master:master 将修改推到一个公共仓库   git push -u origin master把本地库的所有内容推送到远程库   git push https://github.com/bugquella/cqc.git master:master   git push git@github.com:bugquella/cqc.git master:master   git push ssh://yourserver.com/~you/proj.git +master强制git-push在上传修改时先更新,只要在分支名前面加一个加号</span></span>

<pre name="code" class="python">/*******************************************************************/1、安装git服务器与ssh服务器:sudo apt-get install git-core openssh-server openssh-client  ssh安装与配置:<a target=_blank href="http://blog.csdn.net/hgz_gs/article/details/52039218">http://blog.csdn.net/hgz_gs/article/details/52039218</a>2、创建自己的仓库:用户共享,会在当前目录下创建.git目录<span style="white-space:pre"></span>git init
3、把当前的文件添加到staged area(索引)<span style="white-space:pre"></span>git add file1 file2
4、提交<span style="white-space:pre"></span>git commit -a //将会弹出一个窗口叫你注释本次修改的注释说明
5、访问(克隆):新建一个窗口 $su 用户名 登录另一个用户   ///home/alice/project 为刚才创建创库的地方;myrepo为克隆后文件所在的地方<span style="white-space:pre"></span>git clone /home/alice/project myrepo
6、查看文件有那些进行修改了<span style="white-space:pre"></span>git diff --cached查看添加到索引的文件哪些进行修改了,add之后<span style="white-space:pre"></span>git status<span style="white-space:pre"></span>查看那些文件进行了修改,就是没有add之前
7、图形界面查看文件的版本信息<span style="white-space:pre"></span>gitk
</pre><pre name="code" class="python">
/*******************************************************************/分支操作:
1、回到最开始创建仓库的地方/home/alice/projectcd /home/alice/project
</pre><pre name="code" class="python">2、查看当前分支<span style="white-space:pre"></span>git brabch
3、创建分支<span style="white-space:pre"></span>git branch mybran<span style="white-space:pre"></span>再使用git brabch就会看到刚创建的分支,其中带*的就是当前工作的分支
4、切换分支<span style="white-space:pre"></span>git checkout mybran 
<span style="white-space:pre"></span>//切换工作分支,使用git branck 查看分支,可以看到mybran带*号
</pre><pre name="code" class="python">5、修改文件<span style="white-space:pre"></span>vi file1
6、查看分支内容修改<span style="white-space:pre"></span>git diff --cached<span style="white-space:pre"></span>查看添加到索引的文件哪些进行修改了,add之后<span style="white-space:pre"></span>git status<span style="white-space:pre"></span>查看那些文件进行了修改,就是没有add之前
7、删除分支<span style="white-space:pre"></span>git branch  -d <span style="white-space:pre"></span>删除分支<span style="white-space:pre"></span>git branch -D<span style="white-space:pre"></span>强制删除分支,当修改内容没有提交时使用
8、合并分支<span style="white-space:pre"></span>git merge mybran<span style="white-space:pre"></span>合并分支,把mybran合并到当前
9、撤销合并<span style="white-space:pre"></span>git reset --hard HEAD撒销一个合并</span>
</pre><pre name="code" class="python">
/*******************************************************************/不同主机访问git:通过ssh服务器进行操作1、设置Git的user name 和email:(如果是第一次使用的话,这里的用户名与email随便)<span style="white-space:pre"></span>$ git config --global user.name "humingx"<span style="white-space:pre"></span>$ git config --global user.email "humingx@yeah.net"
2、注册github帐号<a target=_blank href="https://github.com/">https://github.com/</a><span style="white-space:pre"></span>sign up-->填写你的用户名.邮箱.密码-->create an account
3、生成密匙$ ssh-keygen -t rsa -C "hegaozhi@163.com"//hegaozhi@163.com你在 github注册的邮箱<span style="white-space:pre"></span>连续3个回车。如果不需要密码的话。最后得到了两个文件:id_rsa和id_rsa.pub。在家目录的.shh目录里,这里不要使用管理员权限
4、添加密钥到ssh-agent
<span style="white-space:pre"></span>$ ssh-add ~/.ssh/id_rsa<span style="white-space:pre"></span>//添加生成的 SSH key 到 ssh-agent。<span style="white-space:pre"></span>确保 ssh-agent 是可用的。ssh-agent是一种控制用来保存公钥身份验证所使用的私钥的程序,其实ssh-agent就是一个密钥管理器,运行ssh-agent以后,使用ssh-add将私钥交给ssh-agent保管,其他程序需要身份验证的时候可以将验证申请交给ssh-agent来完成整个认证过程。
 /*# start the ssh-agent in the background  eval "$(ssh-agent -s)"<span style="white-space:pre"></span>Agent pid 59566*/</span>
5、登录Github,添加ssh<span style="white-space:pre"></span><a target=_blank href="https://github.com/">https://github.com/</a><span style="white-space:pre"></span>登录你的帐号Settings--》ssh and gpg keys -->new ssh key在title中随便命名一个key的名字<span style="white-space:pre"></span>把id_rsa.pub文件里的内容复制到这key中
6、测试<span style="white-space:pre"></span>$ ssh -T git@github.com你将会看到:    The authenticity of host 'github.com (207.97.227.239)' can't be established.    RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.    Are you sure you want to continue connecting (yes/no)?选择 yes如果看到Hi后面是你的用注意:输入密码时如果输错一个字就会不正确,使用删除键是无法更正的。密码正确后你会看到下面这段话,如:Hi username! You've successfully authenticated, but GitHub does not# provide shell access.如果用户名是正确的,你已经成功设置SSH密钥。如果你看到 “access denied” ,者表示拒绝访问,那么你就需要使用 https 去访问,而不是 SSH 。户名,就说明成功了。
7、修改.git文件夹下config中的url。修改前    [remote "origin"]    url = https://github.com/humingx/humingx.github.io.git    fetch = +refs/heads/*:refs/remotes/origin/*修改后    [remote "origin"]    url = git@github.com:humingx/humingx.github.io.git    fetch = +refs/heads/*:refs/remotes/origin/*</span>
8、发布什么GitHub需要SSH Key呢?因为GitHub需要识别出你推送的提交确实是你推送的,而不是别人冒充的,而Git支持SSH协议,所以,GitHub只要知道了你的公钥,就可以确认只有你自己才能推送。当然,GitHub允许你添加多个Key。假定你有若干电脑,你一会儿在公司提交,一会儿在家里提交,只要把每台电脑的Key都添加到GitHub,就可以在每台电脑上往GitHub推送了。现在,我们根据GitHub的提示,在本地的learngit仓库下运行命令:
</pre><pre name="code" class="python">先在GitHub官网中新建一个repository名称为cqc点击右上角的+号:new repository<span style="white-space:pre"></span>Repository nam:cqc<span style="white-space:pre"></span>create repository在终端你要发布的文件的目录中<span style="white-space:pre"></span>$ git remote add origin git@github.com:bugquella/cqc.git
<span style="white-space:pre"></span>请千万注意,把上面的 bugquella 替换成你自己的GitHub账户名,否则,你在本地关联的就是我的远程库,关联没有问题,但是你以后推送是推不上去的,因为你的SSH Key公钥不在我的账户列表中。添加后,远程库的名字就是origin,这是Git默认的叫法,也可以改成别的,但是origin这个名字一看就知道是远程库。
</pre><pre name="code" class="python">下一步,就可以把本地库的所有内容推送到远程库上:<span style="white-space:pre"></span>$ git push -u origin master</span></span>好啦,静静等待git把你的代码Push上去吧~是不是很简单?
9、测试
<span style="font-family: Arial, Helvetica, sans-serif;">在另一台电脑把ssh的服务打开 :网络连上</span>
<span style="white-space:pre"></span>$sudo service ssh restart把远程仓库的代码克隆下来:<span style="white-space:pre"></span>$git clone git@github.com:bugquella/cqc.git或者:<span style="white-space:pre"></span>git clone https://github.com/bugquella/cqc.git

                                             
0 0
原创粉丝点击