ubuntu12.04.4下git的安装及配置

来源:互联网 发布:太湖水利设计院知乎 编辑:程序博客网 时间:2024/05/01 09:22
1. 到github官网上注册一个github账号:https://github.com/
2. git安装, 终端执行以下命令:
sudo apt-get install git
3. 在本地创建ssh key, 在/home/用户名/下, 执行命令:
ssh-keygen -t rsa -C "这里填你在github官网注册的邮箱"
(1) 输入key文件名, 比如:github
(2) 设置密码
(3) 确认密码
(4) 在/home/用户名/下会生成github和github.pub, 其中github打开需要输入上面设置的密码才能打开, github.pub文件可以直接打开, 里面保存的是key的信息, 下面要在github官网账号里创建版本库里要用的该key信息
操作如下:
xx@ubuntu:~$ ssh-keygen -t rsa -C "youremail@example.com"Generating public/private rsa key pair.Enter file in which to save the key (/home/xx/.ssh/id_rsa): gditcEnter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in gditc.Your public key has been saved in gditc.pub.The key fingerprint is:a7:cb:71:7a:d1:14:9e:cf:14:62:53:28:55:62:16:31 youremail@example.comThe key's randomart image is:+--[ RSA 2048]----+|           .E*o  ||          .o*o.  ||           + = . ||            + .  ||        S .o +   ||         o. . o  ||        o ..     ||       . =.      ||        +.       |+-----------------+xx@ubuntu:~$ lsexamples.desktopgditcgditc.pub公共的模板视频图片文档下载音乐桌面xx@ubuntu:~$ 
4. 在github账号里添加ssh key:
github右上角点击Account Settings进入-->在左边找到SSH Keys并点击-->点击Add SSH Key-->填写SSH Key的Title和key-->Title可以随便填个有意义的名字,接着将github.pub里的全部内容拷贝到key里-->点击Add key, 即可完成SSH Key的创建。
5. 测试是否可成功连接上github:
ssh -T git@github.com
执行完上面的命令后, 在用户的根目录下会生成一个隐藏文件夹.ssh, 快捷键ctrl + h或终端命令ls -la可以查看确认。
如果出现像如下这样的信息, 表明可成功连接上github:
cryhelyxx@ada:~$ ssh -T git@github.comHi Cryhelyxx! You've successfully authenticated, but GitHub does not provide shell access.
如果出现如下信息, 表明连接失败:
xx@ubuntu:~$ ssh -T git@github.comPermission denied (publickey).
这时, 我们将上面生成的两个文件gditc和gditc.pub移动到~/.ssh/目录下, 再次执行$ ssh -T git@github.com, 
这时会弹出以下的窗口, 输入上面操作设置的密码
即可连接成功, 如下:
xx@ubuntu:~$ ssh -T git@github.comWarning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.Hi Cryhelyxx! You've successfully authenticated, but GitHub does not provide shell access.xx@ubuntu:~$ 
6. 新建版本库new repository
新建版本库new repository, 然后获得https://github.com/Cryhelyxx/Multimedia-Management-System.git
We recommend every repository include a READMELICENSE, and .gitignore.
Create a new repository on the command linetouch README.mdgit initgit add README.mdgit commit -m "first commit"git remote add origin https://github.com/Cryhelyxx/blog.gitgit push -u origin master
Push an existing repository from the command linegit remote add origin https://github.com/Cryhelyxx/blog.gitgit push -u origin master
 …or create a new repository on the command line
echo "# blog" >> README.mdgit initgit add README.mdgit commit -m "first commit"git remote add origin https://github.com/Cryhelyxx/blog.gitgit push -u origin master
7. Git为你的每一个提交都记录你的名字与电子邮箱地址
$ git config --global user.name YourName$ git config --global user.email you@somedomain.com
 
8. 强制提交
error: 无法推送一些引用到 'https://github.com/Cryhelyxx/ETS.git'提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。提示:再次推送前,先与远程变更合并(如 'git pull ...')。详见提示:'git push --help' 中的 'Note about fast-forwards' 小节。xx@ubuntu:~/git_workspace/ETS$ git push origin +master对象计数中: 1, 完成.写入对象中: 100% (1/1), 153 bytes | 0 bytes/s, 完成.Total 1 (delta 0), reused 0 (delta 0)To https://github.com/Cryhelyxx/ETS.git + 1fc1ccb...b8a6ed2 master -> master (forced update)xx@ubuntu:~/git_workspace/ETS$ 
git直观命令表:
9. git tag标签的使用
(1) 创建标签:git tag 标签名
(2) 显示所有标签:git tag
(3) 共享所有标签到远程库:git push --tags(p.s. 如果有人克隆或者在线同步你的git仓库的话, 标签也会一并同步了)
(4) 删除本地标签:git tag -d 标签名
(5) 删除远程标签:git push origin :refs/tags/标签名
(6) 检出标签:git checkout 标签名
(7) 查看相应标签的版本信息, 并连同显示标签的提交对象: git show 标签名
(8) 推送标签:git push origin 标签名
(9) 查看提交的历史日志: git log
 
事实上Git的推送和删除远程标签命令是相同的, 删除操作实际上就是推送空的源标签refs:
git push origin 标签名
相当于
git push origin refs/tags/源标签名:refs/tags/目标标签名
 
 
10. 为开源项目推送版本
每当我们的项目有了新的里程碑后, 我们就为项目推送一个版本, 这里用git tag命令来完成。
假设我们对项目进行了修改, 现在先推送到代码托管网站上, 如github, 以下是常用的推送操作命令:
$ git add *$ git commit -m '推送的信息'$ git push origin master
当最新源代码推送完毕后, 我们就用 git tag 标签名 来为刚刚提交的最新源代码创建新版本, 假设将刚刚提交的最新源代码设定版本为v2.3.7, 则进行以下常用命令操作:
$ git tag$ git tag v2.3.7$ git push --tags
 其中, git tag表示显示所有的版本号, 即显示所有标签, git tag v2.3.7表示为本地创建新的版本(标签), git push --tags表示将本地的所有版本(标签)推送到远程库上(即共享标签)
 
 
 
git官网:http://git-scm.com/
git官方文档:http://git-scm.com/docs
git手册:https://www.kernel.org/pub/software/scm/git/docs/
git中文参考手册:http://gitref.justjavac.com/basic/#commit
待续...
0 0
原创粉丝点击