Git 指令练习仓库
- Ignored 忽略区
- Untracked 未跟踪区
- WorkSpace 工作区
- Index/Stage 暂存区
- Repository 本地仓库
- Remote 远程仓库
$ git config --list
$ git config -e <--global>
$ git config <--global> user.name 'user'
$ git config <--global> user.email 'email address'
$ cd ~/.ssh
id_rsa
id_rsa.pub
known_hosts
$ ssh-keygen -t rsa
$ cat ~/.ssh/id_rsa.pub
指令:git clone https://domain.com/user/repo.git
例子:git clone https://github.com/TimeAway/git-workbook.git
指令:git clone git@domain.com:user/repo.git
例子:git clone git@github.com:TimeAway/git-workbook.git
$ git init <project name>
指令:
$ git remote add origin git@domain.com:user/repo.git
$ git push -u origin master
例子:
$ git remote add origin git@github.com:TimeAway/git-workbook.git
$ git add <file1> <file2> ...
$ git add <dir1> <dir2>
-u
表示将已跟踪的修改和删除的文件添加到暂存区,不包括新增的未跟踪文件
-A
表示将所有已跟踪的修改和删除及新增的未跟踪文件添加到暂存区
$ git add <-u> <-A> .
$ git add -p
$ git rm <file1> <file2> ...
$ git rm -f <file>
$ git rm --cached <file>
$ git rm -r<-f> --cached <catalogue>
$ git mv <file-original> <file-renamed>
$ git commit -m <message>
$ git commit <file1> <file2> -m <message>
$ git commit -am <message>
$ git commit -v
$ git commit --amend -m <message>
$ git commit --amend <file1> <file2>
-r
表示列出所有远程分支
-a
表示列出所有本地分支与远程分支
$ git branch <-r> <-a>
$ git branch <branch-name>
$ git branch -b <branch-name>
$ git branch <branch-name> <commit>
$ git branch --track <branch-name> <remote-branch-name>
$ git checkout <branch-name>
$ git checkout -
$ git branch --set-upstream <branch-name> <remote-branch-name>
$ git branch -b <branch-name> origin/<remote-branch-name>
$ git merge <branch-name>
$ git cherry-pick <commit>
$ git cherry-pick <branch-name>
$ git cherry-pick --continue
$ git cherry-pick --abort
$ git branch -d <branch-name>
$ git branch -D <branch-name>
$ git push origin --delete <branch-name>
$ git branch -dr <remote/branch>
$ git tag
$ git tag <tag-name>
$ git tag <tag-name> <commit>
$ git tag -d <tag-name>
$ git push origin :refs/tags/<tag-name>
$ git show <tag-name>
$ git push <remote> <tag-name>
$ git push <remote> --tags
$ git checkout -b <branch-name> <tag-name>
git status
git log
git log --stat
git log -S <keyword>
$ git log <tag-name> HEAD --pretty=format:%s
$ git log <tag-name> HEAD --grep feature
$ git log --follow <file>
$ git whatchanged <file>
$ git log -p <file>
$ git log -5 --pretty --oneline
$ git shortlog -sn
$ git blame <file>
$ git diff
$ git diff --cached <file>
$ git diff HEAD
$ git diff <first-commit> <second-commit>
$ git diff --shortstat '@{0 day ago}'
$ git show <commit>
$ git show --name-only <commit>
$ git show <commit>:<filename>
$ git reflog
$ git fetch <remote>
$ git pull <remote> <branch-name>
$ git pull <remote> <branch-name> --rebase
简写
$ git pull --rebase
$ git remote -v
$ git remote add <shortname> <url>
$ git push <remote> <branch-name>
$ git push <remote> --force
简写
$ git push
$ git push <remote> --force
$ git push <remote> --all
$ git restore <file>
$ git restore --staged LICENSE
$ git checkout <commit> <file>
$ git reset <file>
$ git reset --hard
$ git reset --soft
$ git reset <commit>
$ git reset --hard <commit>
$ git reset --soft <commit>
$ git revert <commit>
$ git stash
$ git stash pop
$ git archive