配置与帮助
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| $ git config -l
$ git config -e
$ git config user.name "[name]" $ git config user.email "[email]"
$ git help
$ git config --help
|
版本库创建
1 2 3 4 5 6 7 8 9 10 11
| $ git init
$ git init [repo-name]
$ git clone git@github.com:Coder-ZJQ/Test-Git.git
$ git clone https://github.com/Coder-ZJQ/Test-Git.git
|
文件操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| $ touch [file-name]
$ mkdir [dir-name]
$ cat [file-name]
$ vi [file-name]
$ git add [file1] [file2] ...
$ git add [dir1] [dir2] ...
$ git add ./
$ git rm [file1] [file2] ...
$ git rm -r [dir]
$ git mv [file-original] [file-renamed]
|
修改管理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| $ git status
$ git commit -m "[message]"
$ git commit [file] | [dir] ... -m "[message]"
$ git commit -a -m "[message]"
$ git commit --amend -m "[message]"
$ git checkout [file] | [dir] ...
$ git reset HEAD [file] | [dir] ...
$ git reset --hard [commit-id]
$ git stash
$ git stash apply
$ git stash drop
$ git stash pop
$ git stash list
|
分支管理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| $ git branch
$ git branch -r
$ git branch -a
$ git branch [branch-name]
$ git branch [branch-name] [commit-id]
$ git branch [branch-name] [tag-name]
$ git branch --track [branch-name] [remote-branch-name]
$ git branch --set-upstream [branch-name] [remote-branch-name] $ git branch -f --track test [branch-name] [remote-branch-name]
$ git checkout [branch-name]
$ git checkout -
$ git checkout -b [branch-name]
$ git merge [branch-name]
$ git cherry-pick [commit]
$ git branch -d [branch-name]
$ git push origin --delete [branch-name] $ git branch -dr [remote-branch]
|
远程仓库操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| $ ssh-keygen -t rsa -C "youremail@example.com"
$ git remote add [remote-name] [remote-SSG | remote-URL]
$ git fetch [remote-name]
$ git pull [remote-name] [branch-name]
$ git push [remote-name] [branch-name]
$ git push [remote-name] --force
$ git push [remote-name] --all
$ git remote -v
$ git remote show [remote-name]
|
标签管理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| $ git tag
$ git show [tag-name]
$ git tag [tag-name]
$ git tag [tag-name] [commit-id]
$ git tag -a [tag-name] -m "[message]" [commit-id]
$ git tag -d [tag-name]
$ git push [remote-name] [tag-name]
$ git push [remote-name] --tags
$ git tag -d [tag-name] $ git push [remote-name] :refs/tags/[tag-name]
|
信息查看
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| $ git status
$ git log
$ git log --stat
$ git log -S [keyword]
$ git log [tag] HEAD --pretty=format:%s
$ git log [tag] 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-branch]...[second-branch]
$ git diff --shortstat "@{0 day ago}"
$ git show [commit]
$ git show --name-only [commit]
$ git show [commit]:[filename]
$ git reflog
|
其他
参考资料:
廖雪峰的官方网站 - Git 教程
阮一峰 - 常用 Git 清单
git-scm