1. 配置
git config --global user.name "your name"
git config --global user.email mail@box.com
git config --global color.ui true
git config --global core.editor vi
git config --global alias.lol "log --graph --all" 设置alias,这样lol就是自己新的命令了。
2.基本使用
1.显示当前的配置信息
git config --list
2. 创建repo
从别的地方获取
git clone git://git.kernel.org/pub/scm/git/git.git
自己建立
mkdir test
cd test
git init
3. 显示状态
git status
4. commit
git add file.1 file.2 先增加文件,增加到index中。这样commit的时候才知道要commit哪些文件。
或者
git add -p 用来interactively选择哪些改变需要被commit
git commit -m "log message"
或者
git commit -a 自动检查应该commit什么文件。如果是新增的文件,仍然要使用git add来添加。
5. 显示以前的工作
git log 输出格式
git log
git log -p 显示patch
git log --stat 显示改动的一个总结
git log --graph 只显示当前branch的
git log --graph --all 显示所有branch的
git log --graph --all --decorate 显示branch的名字
git log --pretty=oneline, short, full, fuller 输出的log 形式不同
git log --pretty=format:"%h - %an, %ar : %s" 按照指定的格式输出。
关于--pretty的其他选项和具体的format格式,参考 git log --help中PRETTY FORMAT这部分。
git log --follow file.c
这个功能很有意思,尤其是当file.c被移动后。
通常我们会移动某个文件到某个目录下。如果这么做,git log是不能显示目录移动前的记录的。
那就加上 --follow吧。
git log的筛选
git log -2 -p 显示最近两次commit的log 和 diff
git log --author="Author Name" 筛选特定作者的log
git log --since="2012-2-23" --before="2012-2-24" 筛选时间段
git log --grep="key word" 在commit 的message中查找关键字
git log branch --not master 查看在branch上的,但不在master上的记录。
git log -S"func_name" 查找某个字符出现,或者移出的commit。 比如可以查找一个函数是什么时候添加,或者删除的。
git show sha1 这个sha1是