Git 安装/设置/使用
2015-03-30 11:20
288 查看
安装
shell $sudo apt-get install git $git version
设置
设置文件包括以下三个:1. 系统级: /etc/gitconfig ==
$git config --system
2. 全局: ~/.gitconfig ==
$git config --global
3. 仓库级: .git/config ==
$git config
Note: .git/config 最后被执行,它可以覆盖前面配置文件变量。
配置语法:
'git config' [<file-option>] [type] [-z|--null] name [value [value_regex]] 'git config' [<file-option>] [type] --add name value 'git config' [<file-option>] [type] --replace-all name value [value_regex] 'git config' [<file-option>] [type] [-z|--null] --get name [value_regex] 'git config' [<file-option>] [type] [-z|--null] --get-all name [value_regex] 'git config' [<file-option>] [type] [-z|--null] --get-regexp name_regex [value_regex] 'git config' [<file-option>] [type] [-z|--null] --get-urlmatch name URL 'git config' [<file-option>] --unset name [value_regex] 'git config' [<file-option>] --unset-all name [value_regex] 'git config' [<file-option>] --rename-section old_name new_name 'git config' [<file-option>] --remove-section name 'git config' [<file-option>] [-z|--null] -l | --list 'git config' [<file-option>] --get-color name [default] 'git config' [<file-option>] --get-colorbool name [stdout-is-tty] 'git config' [<file-option>] -e | --edit
usage:
usage: git config [options] Config file location --global use global config file --system use system config file --local use repository config file -f, --file <file> use given config file Action --get get value: name [value-regex] --get-all get all values: key [value-regex] --get-regexp get values for regexp: name-regex [value-regex] --replace-all replace all matching variables: name value [value_regex] --add adds a new variable: name value --unset removes a variable: name [value-regex] --unset-all removes all matches: name [value-regex] --rename-section rename section: old-name new-name --remove-section remove a section: name -l, --list list all -e, --edit opens an editor --get-color <slot> find the color configured: [default] --get-colorbool <slot> find the color setting: [stdout-is-tty] Type --bool value is "true" or "false" --int value is decimal number --bool-or-int value is --bool or --int --path value is a path (file or directory name) Other -z, --null terminate values with NUL byte
例如:
1. 查看配置:
git config -l
- 查看某个变量:
git config color.ui
- 查看global变量:
git config -l --global
- 查看包含字符串变量:
git config --get-regexp color
2. 添加删除修改变量
- 添加变量:
git config add cat.name Jerry
- 修改变量 :
git config --replace-all cat.name Tom
- 删除变量 :
git config unset cat.name Tom
3. 读取特定值
- 读取int 值:
git config --get cat.number --int
- 读取bool 值:
git config --get cat.coming --bool
- 读取path值:
git config --get cat.namelist --path
使用
这里仅仅列举下自己常用的功能。1. 情景一: 拉代码–> 修改–> 提交 –> push
$git pull $git add --> git commit -m "xxx" / git commit -a -m "xxx" $git push origin HEAD:xxxx
情景二: 新建branch fix bug,再merge到 HEAD
$git checkout -b new_branch $git branch -a #查看branch 信息,确认当前和master branch $git add --> git commit $git checkout master $git pull --> git merge new_branch
情景三: 已经commit,但由于某某某,需要对上次commit 修改、更新
$git add #要更新的 $git commit --amend #当然你也可以先reset 再重新commit. #如果是update 远程如gerrit的patch,那就得用到Change-ID了。 #Chenge-ID 必须在提交msg的最后一行 $git push origin HEAD:xxxx
情景四: 时光机(版本回退和前进)
#回退用git log 找过去的id,前进就得用git reflog去看了。 $git log/reflog # 得到commit ID $git rebase <commit ID>#可以用"--hard"/"--soft" 来决定是否保留change #当想废弃一切改变,退回到master 版本就可以用 $git reset origin master
情景五: 已经commit了,但发现本地代码太旧
#先pull--> 解决conflict --> 再push $git pull $git diff #解决conflict $git pull #觉得pull有风险可以用fetch+ rebase $git fetch $git rebase #解决conflict
情景六: 想把当前的修改暂存起来,到用的时候再拿出来
#暂存 $git stash #提取 $git stash pop# 最后一次 $git stash list#查看暂存的 $git stash apply stash@{2}#取第二个 $git stash clear#清除
参考大神wiki
廖雪峰 git wiki
官网Docs
相关文章推荐
- Ant安装设置,简单使用测试
- 此数据库没有有效所有者,因此无法安装数据库关系图支持对象。若要继续,请首先使用“数据库属性”对话框的“文件”页或 ALTER AUTHORIZATION 语句将数据库所有者设置为有效登录名,然后再添加数据库关系图支持对象。
- ASP-kingCMS-v5.1 LTS使用(一)下载,安装,简单设置
- Ubuntu9.10安装Git,Git 和Github初次使用
- Ubantu安装虚拟机VirtualBox使用Windows XP |设置文件夹共享| USB2.0虚实共用
- SATA硬盘使用设置与系统安装
- 【转】ubuntu 中科大源设置&ssh 安装与使用
- 如何安装和使用SATA硬盘(BIOS设置)
- Ubuntu中软件的安装和卸载,以及WINE的使用 && Ubuntu更新源设置更新 && 装12.04 vmware easy install ubuntu 进不去
- Git服务器Gitosis安装设置
- CASIO DT900/dt930数据采集器设置安装使用操作
- Git安装使用笔记 [转]
- Git的安装使用(centos)
- windows下sqlite安装使用和性能优化及设置
- windows下sqlite安装使用和性能优化及设置
- 打造实用Fedora 8(安装后使用设置说明)
- 版本控制系统Git安装使用方法
- Git安装以及使用Git 管理个人文档
- 使用CentOS安装盘在局域网中设置CentOS源
- Git安装使用笔记 [转]