[关闭]
@wangwangheng 2015-05-10T10:21:01.000000Z 字数 2027 阅读 2013

Git笔记

开发工具


git --version 查看git的版本号
git config --global user.name "用户名"
git config --global user.email "email地址"
git config --global color.ui "auto" 配置不同颜色显示文字,特别是git diff的时候很有用

auto是可选文字,可以是auto(自动)、always(总是)、false(不变色)

git help < command > 查看指定的command的帮助信息(打开浏览器)


创建版本库:

1. mkdir temp_workspace
2. cd temp_workspace
3. mkdir temp_git
4. cd temp_git
5. git init 

打印出了下面这句话就表示git 版本库创建成功了:Initialized empty Git repository in D:/temp_workspace/temp_git/.git/


如果要让git跟踪一个文件,需要分两步走:


  1. 把文件添加到版本库的索引:git add < file >
  2. 提交文件:git commit -m "提交注释"

    git commit 命令创建了一个提交记录。提交记录式存储在版本中的历史记录,每提交一次创建一个记录,并标记版本的演进。


-m参数的意义是为提交添加注释
如果commit的时候有以下提示信息,说明提交成功

[master (root-commit) 3b7c94f] add in hello world HTML
1 file changed, 6 insertions(+)
create mode 100644 index.html


查看提交日志信息:git log

commit 3b7c94f9d2d4306dcd4249b36640aa63854ca8df
Author: wangheng <496303403@qq.com>
Date: Mon Nov 10 23:37:07 2014 +0800

add in hello world HTML

commit行显示提交名称,是由git自动产生的SHA-1码,git通过它来跟踪提交,是独一无二的,git log 提交名称前七位和git commit的相同,是因为git commit显示的是提交名称的缩写

第二行是提交者信息

第三行诗提交日期

最后是提交的Log,和commit的-m参数一致


一、git的代理设置
以下的--global均可以是以下的值--system 或 --global 或 --local
1、git 代理设置

git config --global http.proxy http://127.0.0.1:8580
git config --global https.proxy http://127.0.0.1:8580
git config --global http.sslverify false

2、git清除指定的设置
git config --global --unset http.sslverify
git config --global --unset http.proxy
git config --global --unset https.proxy

3、git查看指定的设置的值
git config --global http.sslverify
git config --global http.proxy
git config --global https.proxy


分支:
查看本地所有分支:git branch
查看远端所有分支:git branch -a
查看远端URL地址:git remote -v
克隆远端代码:git clone git@git.culiu.org:android/purchase.git
创建本地分支(和远端同名)并且把本地分支和远端分支绑定,然后切换到本地分支:git checkout -t origin/feature/optimize

查看与当前分支绑定的远端分支:git branch -vv
切换到主分支/指定分支:
git checkout master
git checkout feature/optimize

查看本地版本库状态(包含当前所处的分支):git status
提交到指定的分支:git push origin feature/optimize


github 每次都要输入密码的问题

在github.com上 建立了一个小项目,可是在每次push 的时候,都要输入用户名和密码,很是麻烦

原因是使用了https方式 push

在termail里边 输入 git remote -v

可以看到形如一下的返回结果

origin https://github.com/yuquan0821/demo.git (fetch)

origin https://github.com/yuquan0821/demo.git (push)

下面把它换成ssh方式的。

  1. git remote rm origin
  2. git remote add origin git@github.com:yuquan0821/demo.git
  3. git push origin
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注