Git Commands

Git Version

$ git --version

Git Config

1. set user name,email

$ git config --global user.name MudOnTire

$ git config --global user.email 895157882@qq.com

2. get config

$ git config user.name

$ git config user.email

Repository

1. git init

$ git init

2. git status

$ git status

3. stage file

single file

$ git add index.html 

all changed files

$ git add .

4. unstage file

$ git rm --cache index.html

5. commit

make commit

$ git commit -m "add index and style files"

show history

$ git log

show condensed commit

$ git log --oneline

Undo Commits

1. checkout commit

$ git checkout 0e2a5f3

2. reattach to branch

$ git checkout master

3. revert commit (undo one particular commit)

$ git revert eb95c64

4. reset commits

soft (retain changes)

$ git reset eb95c64

hard (erase all changes)

$ git reset eb95c64 --hard

create branch

1. show branches

$ git branch -a

2. create a branch

$ git branch feature-1

3. switch to a branch

$ git checkout feature-1

4. delete a branch

$ git branch -D feature-1

5. create and then switch to a branch

$ git checkout -b feature-1

merge branch

1. merge target branch to current branch

$ git merge [name_of_target_branch]

2. push local branch to remote

$ git push origin [name_of_your_new_branch]

相关文章

Git安装和使用 Git安装和使用 刚开始用git的小白适用,,转自...
fatal: remote origin already exists.解决方法 第一个问题g...
git常用命令(二)查看历史记录 git log [--pretty=oneline]...
git之如何把本地文件上传到远程仓库的指定位置 git专栏收录该...
代码规范之 lint-staged 在代码提交之前,进行代码规则检查能...
方法:1、文件没有git操作时用“git checkout--文件”命令还...