git、githup使用
一、git安装、配置
git安装:
root@ubuntu~# apt-get install git
git配置githup/自己的git服务器端账号, 即在用户的home目录下生成.gitcofig文件,可手动修改:
root@ubuntu~# git config --global user.name "Your Name Here"
root@ubuntu~# git config --global user.email your_email@example.com
root@ubuntu~# git config --global color.ui true
查看已有的配置信息:
root@ubuntu~# git config --list
二、git使用:
git创建仓库(repository,老外简写repo):
新建项目目录,eg: cd /root/mygit
1、首次将本地的项目初始化到git服务器:
root@ubuntu~# git init #创建一个空的repository,在当前目录下生成了.git文件夹
root@ubuntu~# git add *
root@ubuntu~# git commit -m 'initial project version'
root@ubuntu~# git remote add origin git@github.com:username/project_name.git # 即刚刚创建的仓库的地址
root@ubuntu~# git push -u origin master #推送代码到远程代码库
2、将git服务器代码初始化到本地:
root@ubuntu~#git status #查看状态
root@ubuntu~#git commit -m "log here" #不加参数-m,则默认使用vi打开一个文件写入log #等同于svn的commit
root@ubuntu~#git status
_______________________________
| |
| histroy |
|_______________________________|
|
|
| git commit
_______________|_______________
| |
| staging area |
|_______________________________|
|
|
| git add
________________|_______________
| |
| working dir |
|_______________________________|
root@ubuntu~#git status -s #查看三者之间的是否相同,标记位:M , MM,
root@ubuntu~#git diff #比较working dir 与staging area之间的差异
root@ubuntu~#git diff --staged #比较staging area 与 history之间的差异,用于add之后检测
撤销误操作:
root@ubuntu~#git add demo #add一版代码到staging area
root@ubuntu~#git status -s
M demo
root@ubuntu~#git reset demo #将history中的demo覆盖staging area
root@ubuntu~#git checkout demo #将staging area中文件覆盖到working dir
直接从history覆盖到working dir:
root@ubuntu~#git checkout HEAD demo
同理将working dir中改动直接提交到history:
root@ubuntu~#git commit -am "update log"
删除以及重命名:
root@ubuntu~#git rm demo
root@ubuntu~#git status -s
root@ubuntu~#git commit -m 'delete demo'
保存working dir中的demo文件
root@ubuntu~#git rm --cached demo #只是把staging area中demo删除了
root@ubuntu~#git reset demo #把history中的demo覆盖到staging area中
root@ubuntu~#git mv demo demo.bak #把working dir和staging area中重命名
root@ubuntu~#git commit -m 'rename demo' #history也重命名了
root@ubuntu~# git rm --cached demo.bak #只修改了staging area部分
root@ubuntu~#mv demo.bak demo
root@ubuntu~#git add demo
root@ubuntu~#git status -s
root@ubuntu~#git commit -m 'rename demo.bak'
赞存工作区:在代码修改之后,马上需要在原版本上修改bug,此时就可以将此时的工作区临时保存起来;
root@ubuntu~#git stash #此时working dir是history中的内容
root@ubuntu~#vim demo
root@ubuntu~#git commit -am 'quick fix' #紧急提交,修改bug
root@ubuntu~#git stash list
root@ubuntu~#git stash pop #将临时工作区恢复到working dir
分支管理:
root@ubuntu~# git branch #列出当前所有分支
* master #*表示当前使用的分支
root@ubuntu:~# git branch try_idea #创建branch
root@ubuntu:~# git branch
* master
try_idea
root@ubuntu~# git checkout try_idea #切换到try_idea分支
D aaa.py
Switched to branch 'try_idea'
root@ubuntu-ceph-06:~/cp/git# git branch
mater
* try_idea #当前分支
root@ubuntu~#git branch -d try_idea #删除分支
联合操作,创建分支并切换到新建的分支上:
root@ubuntu~#git checkout -b try_idea
版本合并:
root@ubuntu~#git branch mybranch
root@ubuntu~#git checkout mybranch
root@ubuntu~#vim demo #做下修改;
root@ubuntu~#git commit -am "mybranch commit"
root@ubuntu~#git checkout master
root@ubuntu~#git merge mybranch #将mybranch分支合并到master分支
root@ubuntu~#git branch -d mybranch #只有在合并之后才能删除分支,否则报错
分支版本合并:如图
master branch
____ ____ ____ ____
| | | | | | | |
| a | <--- | b | <--- | c | <---- | e |
|____| |____| |____| |____|
|
| bugfix branch
__|_ ____
| | | |
| d | <---- | f |
|____| |____|
root@ubuntu~#git merge buffix #在master版本上,并提交版本,到达了e版
出现需要合成临时版本的情况,即c版合并f版,生成临时版本之后,再于e版本合并;
出现的对话框,选择ctrl+x即可;若有冲突则提交不成功;需要手动vim修改
git log, 如果嫌输出信息太多,看得眼花缭乱的,可以试试加上--pretty=oneline参数:
用带参数的git log也可以看到分支的合并情况:
root@ubuntu-ceph-:~/cp/mygit# git log --graph --pretty=oneline --abbrev-commit
* f0be77e configct fixed
|\
| * 290e5e3 change master
| * c539383 branche test
* | a315058 aa.txt
|/
* e51e421 msg
* 6c84560 init msg
git分枝策略:
git、githup使用的更多相关文章
- 1.Git & GitHup
1.常见的版本控制(管理代码的版本迭代)工具: @ svn:集中式版本控制系统: SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以首先要从中央服务器哪里 ...
- JAVA视频链接
Java基础Java马士兵:链接:https://pan.baidu.com/s/1jJRvxGi密码:v3xb Java刘意:链接:https://pan.baidu.com/s/1kVZQCqr密 ...
- Java视频教程免费分享(网盘直接取)
Java基础 Java马士兵:链接:https://pan.baidu.com/s/1jJRvxGi密码:v3xb Java刘意:链接:https://pan.baidu.com/s/1kVZQCqr ...
- git学习记录——远程仓库(说白了就是代码放到githup上)
远程仓库 现在讲述的这些SVN都已经做到了,并没什么稀奇的地方 所以这节课赘述的是杀手级的东西——远程仓库githup ssh-keygen -t rsa -C "xxxxxxxxxxx@ ...
- git关联githup和码云
1.与已有的本地仓库关联git remote add origin git@github.com:michaelliao/learngit.git然后就可以协作开发push与pull 2.第二种方法直 ...
- git的使用学习(七)githup和码云的使用
1.使用GitHub 我们一直用GitHub作为免费的远程仓库,如果是个人的开源项目,放到GitHub上是完全没有问题的.其实GitHub还是一个开源协作社区,通过GitHub,既可以让别人参与你的开 ...
- git和githup
一:Git简介 1.1:VCS的历史 Git是一款代码管理工具(Version Control System),傲视群雄,是目前世界上最先进的免费开源的分布式版本控制系统,没有之一! VCS版本控制系 ...
- git分布式版本控制玩法
git分布式版本控制玩法 Git distributed version control play github的配置安装步骤:1.下载git bash(从http://www.git-scm.com ...
- Git下载Spring项目源码并编译为Eclipse
1)当前系统中安装了gradle,如果为安装,可以从:http://www.gradle.org/downloads,,下载完后进行解压到任意盘符,然后增加环境变量GRADLE_HOME,并在环境变量 ...
随机推荐
- android,在fragment中使用listview,不使用listfragment
public class LeftFragment extends Fragment{ private ListView listView; @Override public View onCreat ...
- Codeforces 235E
Codeforces 235E 原题 题目描述:设\(d(n)\)表示\(n\)的因子个数, 给定\(a, b, c\), 求: \[\sum_{i=1}^{a} \sum_{j=1}^{b} \su ...
- 矩形嵌套(LIS)
矩形嵌套 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 有n个矩形,每个矩形可以用a,b来描述,表示长和宽.矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅当a& ...
- HDU 4729 An Easy Problem for Elfness (主席树,树上第K大)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题意:给出一个带边权的图.对于每一个询问(S , ...
- ShareSDK的简化压缩和使用样例
share sdk 太大了 于是自己 開始简化, 删除了 ipad 的图片和 framework , 压缩了 sharesdk 中的 图片,用几k的图片 替换了几个 200多k 的图片 仅仅保留 ...
- 如何更快速加载你的JS页面
确保代码尽量简洁 不要什么都依赖JavaScript.不要编写重复性的脚本.要把JavaScript当作糖果工具,只是起到美化作用.别给你的网站添加大量的JavaScript代码.只有必要的时候用一下 ...
- JAVA责任链设计模式
<JAVA与模式>之责任链模式 在阎宏博士的<JAVA与模式>一书中开头是这样描述责任链(Chain of Responsibility)模式的: 责任链模式是一种对象的行为模 ...
- HTTP头信息(转)--1
转自:http://www.cnblogs.com/9988/archive/2012/03/21/2409086.html 我用抓包软件抓了http的包,发现accept大多数有两种情况. 第一种: ...
- DEV控件自定义排序实现
一般的控件或者组件都支持按照某一列进行排序.但是,这种排序是根据数据源里的数据默认按照降序或升序排序的,同时这样的排序与字段的类型有关. 假设现在字段的类型是字符串类型 ,但是,存储的数据时数字加一些 ...
- EC读书笔记系列之2:条款4 确定对象被使用前已先被初始化
条款4:确定对象被使用前已先被初始化 记住: ★为内置对象进行手工初始化,因为C++不保证初始他们 ★构造函数最好使用初始化列表,而不要在构造函数本体内使用赋值操作.初始化列表列出的成员变量,其排列次 ...
