3
git和github简介(下)
source link: https://jiongks.name/blog/2011-06-26-2
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
git和github简介(下)
本文摘自 勾三股四 更早时期的 不老歌 博客。
接上一篇git和github简介(上)
创建一个git仓库
$ git init
初始化仓库$ git status
查看当前仓库状态# On branch master nothing ot commit (...)
$ git add . $ git add index.htm style.css ...
添加文件到临时区域,前者为添加全部$ git commit --all --message "xxx" $ git commit -am "xxx"
提交修改记录。两者效果相同$ git log
查看修改记录.gitignore
文件
用来记录自动忽略添加的文件,如config.php
$ git mv ... ...
移动$ git rm ... ...
删除
注意区分git mv/rm
和mv/rm
管理分支和标签
$ git branch
列出所有分支* master xxx yyy
$ git branch xxx
创建名为xxx的分支$ git checkout xxx
切换至名为xxx的分支$ git merge xxx
合并xxx分支的修改$ git tag
列出所有标签v3.1 v3.0 v2.5 v2.0 v1.0
$ git tag v2.0
生成一个新标签$ git show v2.0
tag v2.0 Tagger: Jinks Zhao ... Date: Sat Jul 3 10:06:16 2010 -0400
查看该标签的相信情况
half-way to release 1
commit 08eaf7c6b... Merge: be96dbe 39a1b50 Author: Jinks Zhao ... Date: Sat Jul 3 07:28:16 2010 -0400
Merge branch 'xxx'$ git describe
v2.0-2-g8ee0f4a
显示以上一个标签为基础的提交情况
部分git高级操作
$ git add -i
交互式添加$ git reset --hard HEAD $ git reset --soft xxx $ git checkout -- <file.ext>
恢复版本或文件$ git diff $ git diff <file.ext> $ git diff <commit> $ git diff <commit> >file.ext> $ git diff <branch1>..>branch2> $ git diff <branch1>...>branch2>
比较文件或版本之间的差异,有多种参数用法$ git stash $ git stash apply
如果你在完成一个功能特性的时候发现之前代码里有一个bug,但是这个bug又和你正在开发的功能特性无关,你想在完成整个功能特性开发之前就修复这个bug。但是现在功能特性已经开发一半了,这时候该如何处理呢?
更多的git操作
git + github.com配合使用
发布、管理、派生
远程操作相关的git命令
$ git clone git://github.com/nickname/projectname.git [localprojectname]
克隆一个远程的仓库$ git remote add <remoteName> <remoteURL>
添加远程跟踪的分支$ git fetch origin master
获取远程最新的代码$ git merge origin/master
合并远程最新的代码$ git pull origin master
获取并合并远程最新的代码,前两者的快捷组合命令$ git push origin master
将本地最新的代码推送至远程仓库
在github.com创建自己的仓库
在github.com创建自己的仓库
在github.com创建自己的仓库
- 登录 github.com 并新建一个仓库
- 起好名字,完成配置
- 本地是否已经有现成的代码?
- 添加本地现有的代码
- 或者创建全新的空仓库
$ cd existing_git_repo $ git remote add origin [email protected]:nickname/projectname.git $ git push origin master
发布、同步本地的代码
$ git pull origin master
$ git push origin master
- 注:直接pull/push主分支并不是很好的习惯
创建自己的github pages
- 项目的 "landing page"
- 形如:http://user.github.com/project/
- 做法:
- 创建一个名为 gh-pages 的远程分支
$ git push origin gh-pages
- 或者利用 Project Page Generator 自动生成
- 创建一个名为 gh-pages 的远程分支
- 实例:实例1 实例2
- 官方说明:http://pages.github.com/
从github.com派生别人的仓库
从github.com派生别人的仓库
- 在别人仓库的主页,点击 "fork" 按钮派生别人的仓库
- 完成自己的开发之后,点击 "pull request" 按钮,申请原作者将自己的改动合并到原仓库中
相关资源和参考文献
方便后续学习、实践
Getting Good with GIT
其它学习资料
Related Issues not found
Please contact @jinjiang to initialize the comment
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK