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,并在环境变量 ...
随机推荐
- Codeforces 339E
#include <cstdio> #include <algorithm> #include <cmath> #include <cstring> # ...
- CentOS安装与配置LNMP
本文PDF文档下载:http://www.coderblog.cn/doc/Install_and_config_LNMP_under_CentOS.pdf 本文EPUB文档下载:http://www ...
- poj1484---判断保险丝是否烧断
题目输入要求: 2 2 10 //设备数n 接下来的操作数m 保险丝能承受最大电流c5 //电器1的电流7 //2的电流1 //反转开关12 //反转开关2 思路:设置一个flag数组,记得每次 ...
- JQuery UI 精品UI推荐
1.JQuery MiniUi http://www.miniui.com/
- 使用Vitamio打造自己的Android万能播放器(2)—— 手势控制亮度、音量、缩放
前言 本章继续完善播放相关播放器的核心功能,为后续扩展打好基础. 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民伯伯: http://ove ...
- Repeater的ItemCommand事件和ItemCreated事件,高手请跳过~
捣鼓这几天,我终于比之前更能区别Repeater的ItemCommand事件和ItemCreated事件了 当Repeater的dataSource是sqldataSource的话,要想触发ItemC ...
- 后台程序控制js弹出框
public void jsWindow(String msg, int i){ HttpServletResponse response=ServletActionContext.getRespon ...
- oracle日期函数集锦
oracle 中select TO_CHAR(sysdate,'Mon') from dual; Question:出来是中文的“6月” 我想要英文的怎么办? Answer:select to_cha ...
- hive 配置MySQL库
chkconfig mysqld on MySQL开机自启动 建库: --hive数据库2create database hive DEFAULT CHARSET utf8 COLLATE utf8_ ...
- C++_内部类
C++ 内部类和外部类之间的相互调用