查看常用的帮助信息
$ git help
查看所有的帮助信息
$ git help -a
查看git 配置信息
$ git config --list
$ mkdir work && cd work
$ git init
$ git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
$ touch REANDE.md
$ git status
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
index.html
nothing added to commit but untracked files present (use "git add" to track)
$ git add index.html
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: index.html
$ git commit -m '提交的描述信息, 添加 index.html 文件'
master (root-commit) 09d7829] 提交的描述信息, 添加 index.html 文件
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 index.html
$ git log
$ git log --online
$ git log --online --decorate
$ git diff <file>
$ git diff --staged
# 暂存区和上次提交的比较
$ git checkout HEAD -- <file>
$ git checkout HEAD^ -- <file>
$ git revert <id>
$ git reset <id>
reset可以设置头部指针,之后的一些提交会从当前指针开始,以前的提交将会被覆盖(相当于消失)
$ git branch
* master
$ git branch <branch-name>
$ git checkout <branch-name>
Switched to branch 'branch-name'
- 查看分支:
$ git branch
- 创建分支:
$ git branch <name>
- 切换分支:
$ git checkout <name>
- 创建+切换分支:
$ git checkout -b <name>
- 合并某分支到当前分支:
$ git merge <name>
- 删除分支:
$ git branch -d <name>
- 强制删除分支:
$ git branch -D <name>
$ git status
On branch dev
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.html
nothing added to commit but untracked files present (use "git add" to track)
$ git stash
Saved working directory and index state WIP on dev: 09d7829 add index.html file
HEAD is now at 09d7829 add index.html file
$ git stash list
stash@{0}: WIP on dev: 09d7829 add index.html file
$ git stash pop
On branch dev
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: test.html
Dropped refs/stash@{0} (fa28f0641a4f1a1fcaf19d31bbf57409986be72e)
$ git stash apply stash@{0}
$ git stash drop stash@{0}
$ git stash pop stash@{0}