git基本操作

git基本操作,没有理论,纯干货,所见即所得。

git账号管理

查看账号

查看当前git用户名: git config user.name
查看当前git邮箱: git config user.email

切换账号

切换git用户名: git config --global user.name "[email protected]"
切换git邮箱: git config --global user.email "[email protected]"

git初始化

命令: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状态查看

git status

查看git分支

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)

git工作区下文件状态

新建文件mylog.txt,再次查看状态,文件状态untracked files

hero@~ /d/git_study (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add ..." to include in what will be committed)

        mylog.txt

nothing added to commit but untracked files present (use "git add" to track)

git add 命令

git add 

示例:将文件添加到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 ..." to unstage)

        new file:   mylog.txt

git commit命令

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)

你可能感兴趣的:(提高开发效率工具类,git)