git基本操作,没有理论,纯干货,所见即所得。
查看当前git用户名: git config user.name
查看当前git邮箱: git config user.email
切换git用户名: git config --global user.name "xxx@qq.com"
切换git邮箱: git config --global user.email "xxx@qq.com"
命令:git init
示例:
hero@~ /d/git_study
$ git init
Initialized empty Git repository in D:/git_study/.git/
初始化以后当前目录称作
工作区(Working Directory)
如:git_study目录.且当前存在一个.git的文件,不属于工作区
,称作版本库
,版本库
中有一个称为stage(或者叫index)的暂存区
,还有一个Git为我们自动创建的第一个分支master
,以及指向master
的一个指针叫HEAD
git status
hero@~ /d/git_study (master)
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
工作区
下文件状态新建文件mylog.txt,再次查看状态,文件状态untracked files
hero@~ /d/git_study (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
mylog.txt
nothing added to commit but untracked files present (use "git add" to track)
git add <file>
示例:将文件添加到git暂存区,文件状态No commits
hero@~ /d/git_study (master)
$ git add mylog.txt
hero@~ /d/git_study (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: mylog.txt
git commit -m "说明信息"
示例:将暂存区
中的文件commit到对应分支如:master
hero@~ /d/git_study (master)
$ git commit -m "add mylog.txt"
[master (root-commit) 745d82d] add mylog.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 mylog.txt
hero@~ /d/git_study (master)
$ git status
On branch master
nothing to commit, working tree clean
hero@~ /d/git_study (master)