actanble

导航

Git基本命令学习

地址

廖雪峰Git教程

实战代码块第一记

git init //看看当前挂载点
git add readme.txt

git commit -, "wrote a readme file"
#git file1.txt file2.txt file3.txt
#git commit "add 3 files" 
//modify readme.txt;
#git add readme "append banben2"

git reset --hard Head^
git reset --hard *^N0.
##git relog  //Find the Opreadtoion history

git cheakot -- readme.txt //gongzuoqu xiugai
git reset HEAD readme.txt// zancunqu

ssh-keygen -t rsa -C "actanble@163.com"
git remote add origin git@github.com:actanble/demoGit.git

//clone to local
git clone git@github.com:michaelliao/gitskills.git

fenzhiguanli
git checkout -b dev//new and check_change;
git merge dev
git branch -d dev


//kuaisu hebing

 git checkout -b dev
 //modify readme.txt;;
 git add readme.txt
 git commit -m "add merge"
 git checkout merge
 git merge --no-ff -m "merge with no-ff" dev

 git log --graph --pretty=oneline --abbrev-commit


//合并分支时,加上--no-ff参数就可以用普通模式合并,合并后的历史有分支,能看出来曾经做过合并,而fast forward合并就看不出来曾经做过合并。


//修复bug时,我们会通过创建新的bug分支进行修复,然后合并,最后删除;

//当手头工作没有完成时,先把工作现场git stash一下,然后去修复bug,修复后,再git stash pop,回到工作现场。

//开发一个新feature,最好新建一个分支;
//如果要丢弃一个没有被合并过的分支,可以通过git branch -D <name>强行删除。

HaveNoted:GitHub给出的地址不止一个,还可以用https://github.com/actanble/gitskills.git这样的地址。实际上,Git支持多种协议,默认的git://使用ssh,但也可以使用https等其他协议。

使用https除了速度慢以外,还有个最大的麻烦是每次推送都必须输入口令,但是在某些只开放http端口的公司内部就无法使用ssh协议而只能用https。

要克隆一个仓库,首先必须知道仓库的地址,然后使用git clone命令克隆。

Git鼓励大量使用分支:

分支管理基本命令

查看分支:git branch

创建分支:git branch

切换分支:git checkout

创建+切换分支:git checkout -b

合并某分支到当前分支:git merge

删除分支:git branch -d

多人协作

查看远程库信息,使用git remote -v;

本地新建的分支如果不推送到远程,对其他人就是不可见的;

从本地推送分支,使用git push origin branch-name,如果推送失败,先用git pull抓取远程的新提交;

在本地创建和远程分支对应的分支,使用git checkout -b branch-name origin/branch-name,本地和远程分支的名称最好一致;

建立本地分支和远程分支的关联,使用git branch --set-upstream branch-name origin/branch-name;

从远程抓取分支,使用git pull,如果有冲突,要先处理冲突。

其他的以后再弄;git 服务器搭建,个性化设置等。

 Git是分布式的代码管理工具,远程的代码管理是基于SSH的,所以要使用远程的Git则需要SSH的配置。
###SSH秘钥生成
github的SSH配置如下:

一 、

设置Git的user name和email:

$ git config --global user.name "actanble"

$ git config --global user.email "actanble@163.com"


二、生成SSH密钥过程:
1.查看是否已经有了ssh密钥:cd ~/.ssh
如果没有密钥则不会有此文件夹,有则备份删除
2.生存密钥:

    $ ssh-keygen -t rsa -C "actanble@163.com"3个回车,密码为空。


    Your identification has been saved in /home/tekkub/.ssh/id_rsa.
    Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.
    The key fingerprint is:
    ………………


最后得到了两个文件:id_rsa和id_rsa.pub


3.添加密钥到ssh:ssh-add 文件名
需要之前输入密码。
4.在github上添加ssh密钥,这要添加的是“id_rsa.pub”里面的公钥。

end

实用,又简单

posted on 2016-12-31 22:36  白于空  阅读(121)  评论(0编辑  收藏  举报