Git 使用教程

克隆Git项目

git clone git://git.kernel.org/pub/scm/git/git.git

cd git

更新

git fetch

3).执行清理 丢弃本地 对Git代码的改动

git clean -fdx

git reset --hard

4).git tag #查看git 的里程碑

git tag

5)检出该版本的代码

git checkout v1.8.5.1

6)执行安装

make prefix=/usr/local all doc info

sudo make prefix=/usr/local install install -doc install-html install-info

=======================================================================

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

$ git config --global user.email net.webjoy@gmail.com

输入git ci === git commit

       git st =====git status

设置

[jackluo@localhost ~]$ git config --global alias.st status
[jackluo@localhost ~]$ git config --global alias.ci commit
[jackluo@localhost ~]$ git config --global alias.co checkout
[jackluo@localhost ~]$ git config --global alias.cr branch

开启着色:[jackluo@localhost ~]$ git config --global color.ui true

============================================

重点开使学习

mkdir ~/workspace

cd ~/workspace

mkdir demo

cd demo

git init

也可以用 git init demo 会自动创建目录

echo "Hello." >welcome.txt 创建文件

git add welcome.txt 添加目录到文件

提交文件

git ci -m "initialized."

显示版本库所在的位置

[jackluo@localhost demo]$ mkdir -p a/b/c
[jackluo@localhost demo]$ cd a/b/c/
[jackluo@localhost c]$ git rev-parse --git-dir
/home/jackluo/workspace/demo/.git

显示工作区根目录

git rev-parse --show-toplevel

相对于工作区根目录 的相对目录

[jackluo@localhost c]$ git rev-parse --show-prefix
a/b/c/

显示从当前目录 (cd)后退(up)到工作区的深度

[jackluo@localhost c]$ git rev-parse --show-cdup
../../../

配置文件的区别

[jackluo@localhost demo]$ git config -e #版本库最高
[jackluo@localhost demo]$ git config -e --global#全局配置文件其次
[jackluo@localhost demo]$ git config -e --system#系统配置文件优先最低

读取参数:

git config core.bare

更改参数:

[jackluo@localhost demo]$ git config a.b something
[jackluo@localhost demo]$ git config x.y.z others
[jackluo@localhost demo]$ git config x.y.z
others

修改和配置,其它文件

[jackluo@localhost demo]$ GIT_CONFIG=test.ini git config a.b.c.d "hello, world"
[jackluo@localhost demo]$ GIT_CONFIG=test.ini git config a.b.c.d
hello, world

删除Git 全局配置变量

[jackluo@localhost demo]$ git config --unset --global user.name
[jackluo@localhost demo]$ git config --unset --global user.email
[jackluo@localhost demo]$ git config user.name
[jackluo@localhost demo]$ git config user.email

进行空白提交

git commit --allow-empty -m "who does commit?"

===================================

显示好多人,提交过的命令

git log --pretty=fuller

==========================

[jackluo@localhost demo]$ git config --global user.name "JackLuo"
[jackluo@localhost demo]$ git config --global user.email net.webjoy@gmail.com
[jackluo@localhost demo]$ git commit --amend --allow-empty --reset-author
======================================================

查看提交日志

$ git log --stat

=====================

$ git diff #查看版本文件差异

$git status -s 显示精简状态的输出

查看暂提缓区:

git diff --cached

查看版本库的目录 树

$ git ls-tree -l HEAD

============

$ git clean -fd 清除当前工作区中没有加入版本库的文件和目录

$checkout .刷新工作区

[jackluo@localhost demo]$ git ls-files -s
100644 18832d35117ef2f013c4009f5b2128dfaeff354f 0    a/b/c/Hello.txt
100644 4fe551d0ae4b9955eec1ee294a1e736797f19fe3 0    welcome.txt
[jackluo@localhost demo]$ git write-tree
1783aa293d27b3f8df2d89306f57b14643ef38a9
[jackluo@localhost demo]$ git ls-tree -l 1783aa293d27b3
040000 tree c7f1932f7e8a9a1c7e1ed528ce94afceee0be0b1       -    a
100644 blob 4fe551d0ae4b9955eec1ee294a1e736797f19fe3      43    welcome.txt
$ git write-tree |xargs git ls-tree -l -r -t #递归显示出来

git stash #保存当前工作进度

git log --graph --oneline# 查找提交记录

======================================================

找回历史版本

查看历史版本名称:

$ git log --graph --oneline

$ git reset --hard 版本号