初始github——git的简单使用
初学者~
有两篇吧,一篇在github上 https://github.com/DefaultYuan/Git-Pro/wiki/Introduction
文章来源:《git的简单使用》http://www.jianshu.com/p/4105f1f21490(下面是此链接的直接copy)
之前用svn的,但是愕然发现好多公司都开始用git ,一开始不知道为什么,想想那么多公司用它,肯定有它的优点啥,带着好奇的心态,慢慢开始去研究它,由于我们公司,就我一个iOS,所以暂时好多git的好多优点都是持续发掘的,本文也会持续更新中····
一、安装
我们用的都是Mac,所以可以直接通过homebrew安装Git,具体方法请参考homebrew的文档:http://brew.sh/
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
然后再检查
$ git version // 判断是否安装成功,查看版本号
然后,设置你的个人信息
$ git config --global user.name "YourName"
$ git config --global user.email "YourEmail"
注意'git config'命令的'--global'参数,用了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地址。
二、基本使用
2-1、可以新建一个文件夹,mkdir testGit, 然后cd testGit
$ git init // 创建仓库
Initialized empty Git repository in /Users/testGit/.git/
2-2、增加你需要改变的东西,放到testGit中去,添加到仓库中去
$ git add . // 注意 . 是增加所有的
2-3、提交到仓库中去 -m “这里面是需要注释的内容”
$ git commit -m "first init "
2-4、接下来就是看,你的远程仓库建在什么地方啦,我在github 和 coding 上都有,个人认为刚开始在coding 上使用还是不错的
$ git remote add origin git@coding.com....
假如此时遇到这个问题,
fatal: Authentication failed for,那么有可能是没有添加ssh key导致的,具体可以参考这文章git ssh key 的生成
2-5、把内容推送到远程库上
$ git push -u origin master //由于远程库是空的,我们第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令
$ git push origin master // 后期,当然在分支的情况,另论
2-6、然后每次用之前
$ git pull origin master // 每次使用之前最好刷新一下
实际上现在到目前为止就可以开始用起来啦,当然分支管理这个大部分我们后期在讨论。
常用的命令
$ git status // 查看每次变化的
$ git log // 查看每次记录的
$ git log --pretty=oneline // 查看记录更清晰
$ git clone git@github.com:****.git // 从远程仓库克隆,常用
2-7、建立分支并切换
$ git branch 分支名字 // 建立分支
$ git checkout 分支名字 // 切换到分支
$ git branch // 查看分支
2-8、合并分支
//先切换主支
$ git checkout master
$ git merge --no-ff 分支名字
三、理解
工作区-----仓库----远程仓库(git add; git commit ; git push )
四、常见问题(陆续增加中···)
4-1(问)、合并的时候遇到的冲突
error: There was a problem with the editor 'vi'.
Not committing merge; use 'git commit' to complete the merge.
E325: ATTENTION
Found a swap file by the name ".git/.MERGE_MSG.swp"
owned by: eladb dated: Tue Aug 20 10:52:03 2013
file name: ~eladb/MyWorkspace/Client/.git/MERGE_MSG
modified: no
user name: eladb host name: Elads-MacBook-Pro-2.local
process ID: 29959 (still running)
While opening file ".git/MERGE_MSG"
dated: Tue Aug 20 10:53:11 2013
NEWER than swap file!
(1) Another program may be editing the same file.
If this is the case, be careful not to end up with two
different instances of the same file when making changes.
Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r .git/MERGE_MSG"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".git/.MERGE_MSG.swp"
to avoid this message.
Swap file ".git/.MERGE_MSG.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)born:
4-1(答)解决方法:
找到".git/.MERGE_MSG.swp",之后删除即可,然后重新git add .;
git commit -m "";git push master 之后,再执行 git merge branchName 就好啦
4-2 git push 出现的警告问题
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior,use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.
解决:
git config --global push.default matching或者git config --global push.default simple命令,以后再push就不会有警告了。
下面说一下push.default matching和push.default simple的区别:
push.default设置maching的意思是:git push 会把你本地所有分支push到名称相对应的远程主机上。这意味着可能你会在不经意间push一些你原本没打算push的分支。
push.default设置成simple的意思是:git push仅仅把当前所在分支push到从当初git pull pull下来的那个对应分支上,另外,这个过程也会同时检查各个分支的名称是否相对应。
平常最好用 $ git push origin BRANCH #BRANCH是你远程分支的名字
相应的 git pull
git pull origin BRANCH #BRANCH是你远程分支的名字
4-3 git merge 合并时遇到的冲突, Automatic merge failed; fix conflicts and then commit the result
$ git merge secondDev
Auto-merging myTest.txt
CONFLICT (content): Merge conflict in myTest.txt
Automatic merge failed; fix conflicts and then commit the result.
自动合并失败。由于在同一行进行了修改,所以产生了冲突。
在冲突处
add 把变更录入到索引中
commit 记录索引的状态
pull 取得远端数据库的内容
然后重新提交
$ git add myTest.txt
$ git commit -m "合并secondDev分支"
# On branch master
nothing to commit (working directory clean)
五、一张很好用git 的图
参考链接(安装中配置和使用的基本)
1、http://blog.csdn.net/matrixhero/article/details/8214156
// 基本的安装及配置
2、http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137396287703354d8c6c01c904c7d9ff056ae23da865a000 // 详细的讲解和说明,初始github——git的简单使用的更多相关文章
- Linux下的GitHub安装与简单配置教程 ~ 转载
Linux下的GitHub安装与简单配置教程 1.GitHub简介 Git是一个分布式版本控制系统,与其相对的是CVS.SVN等集中式的版本控制系统. 2.Git的安装 1)安装Git a.查看与 ...
- linux下git的简单运用
linux下git的简单运用 windows下也有git,是git公司出的bash,基本上模拟了linux下命令行.许多常用的命令和linux下操作一样.也就是说,windows下的git命令操作和l ...
- Linux下的GitHub安装与简单配置教程
1.GitHub简介 Git是一个分布式版本控制系统,与其相对的是CVS.SVN等集中式的版本控制系统. 2.Git的安装 1)安装Git a.查看与使用 在ubuntu下可以使用如下命令进行查看系统 ...
- GitBook是一个命令行工具(Node.js库),我们可以借用该工具使用Github/Git和Markdown来制作精美的图书,但它并不是一本关于Git的教程哟。
GitBook是一个命令行工具(Node.js库),我们可以借用该工具使用Github/Git和Markdown来制作精美的图书,但它并不是一本关于Git的教程哟. 支持输出多种格式 GitBook支 ...
- eclipse IDE使用git方法简单介绍
eclipse下使用git插件上传代码至github 1.eclipse下安装git eclipse git 插件的安装. 点击 Help->Install New Software-> ...
- (转)初学Git及简单搭建git服务器和客户端
终于搞定,mac自己作为git服务器,mac也是客户端,如何免登 从另外一个linux服务器的上传公钥得到提示 ssh-copy-id -i ~/.ssh/id_rsa.pub git@192.168 ...
- Git 命令简单罗列
源教程出自 廖雪峰的官方网站 https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 整 ...
- 【转载】手把手教你使用Git(简单,实用)
手把手教你使用Git(简单,实用) 标签: git 2016年04月21日 20:51:45 1328人阅读 评论(0) 收藏 举报 一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. ...
- git的简单使用方式(基本操作部分)
git的简单使用方式(基本操作部分) 1.简单介绍GIT的工作流程 git一般的工作流程: 克隆git的资源作为工作目录(一般会使用命令git clone进行克隆); 在克隆的资源上对文件进行增加或者 ...
随机推荐
- [剑指Offer] 35.数组中的逆序对
题目描述 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数P.并将P对1000000007取模的结果输出. 即输出P%1000 ...
- 【bzoj4817】[Sdoi2017]树点涂色 LCT+LCA+线段树
题目描述 给出一棵n个点,以1为根的有根树,每个点初始染有互不相同的颜色.定义一条路径的权值为路径上的颜色种类数.现有m次操作,每次操作为以下三种之一: 1 x: 把点x到根节点的路径上所有的点染上一 ...
- sublime text : The emmet plugin doesn't work when tab key was pressed
Today, I switched my sublime text to version 3. And then I found that the emmet plugin doesn't work ...
- [Leetcode] Remove duplicate from sorted list ii 从已排序的链表中删除重复结点
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- POJ2396:Budget(带下界的网络流)
Budget Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 8946 Accepted: 3327 Special ...
- Fragmenttabhost的使用教程
1.准备tab的图标,放到mipmap目录下面,大小64x64,准备2种,一种是选中的,一种是未选中的,如下图 2.重写fragmentabhost,防止调用fragment每次点击tab都要重新调用 ...
- HDU 1698 Just a Hook(线段树
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- tomcat内存配置及配置参数详解
1.jvm内存管理机制: 1)堆(Heap)和非堆(Non-heap)内存 按照官方的说法:“Java 虚拟机具有一个堆,堆是运行时数据区域,所有类实例和数组的内存均从此处分配.堆是在 Java 虚拟 ...
- 前端跨域之jsonp跨域
jsonp跨域原理 原理:因为通过script标签引入的js是不受同源策略的限制的(比如baidu.com的页面加载了google.com的js).所以我们可以通过script标签引入一个js或者一个 ...
- hashlib模块加密用法
hashlib 加密模块 hashlib.md5() 构建一个md5的对象,用于调用对象的update方法去加密 例子: import hashlib hash = hashlib.md5() h ...