https://blog.csdn.net/web_csdn_share/article/details/79243308
一、新建代码库
1 2 3 4 5 6 7 8
| $ git init
$ git init [project-name]
$ git clone [url]
|
二、配置
Git 自带一个 git config 的工具来帮助设置控制 Git 外观和行为的配置变量。 这些变量存储在三个不同的位置:
/etc/gitconfig 文件: 包含系统上每一个用户及他们仓库的通用配置。 如果在执行 git config 时带上 --system 选项,那么它就会读写该文件中的配置变量。 (由于它是系统配置文件,因此你需要管理员或超级用户权限来修改它。)
~/.gitconfig 或 ~/.config/git/config 文件:只针对当前用户。 你可以传递 --global 选项让 Git 读写此文件,这会对你系统上 所有 的仓库生效。
- 当前使用仓库的 Git 目录中的
config 文件(即 .git/config):针对该仓库。 你可以传递 --local 选项让 Git 强制读写此文件,虽然默认情况下用的就是它。。 (当然,你需要进入某个 Git 仓库中才能让该选项生效。)
每一个级别会覆盖上一级别的配置,所以 .git/config 的配置变量会覆盖 /etc/gitconfig 中的配置变量。
1 2 3 4 5 6 7 8 9 10
| $ git config --list
$ git config -e [--global]
$ git config [--global] user.name "[name]"
$ git config [--global] user.email "[email address]"
|
三、增加/删除文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| $ git add [file1] [file2] ...
$ git add [dir]
$ git add .
$ git add -p
$ git rm [file1] [file2] ...
$ git rm --cached [file]
$ git mv [file-original] [file-renamed]
|
四、代码提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| $ git commit -m [message]
$ git commit [file1] [file2] ... -m [message]
$ git commit -a
$ git commit -v
$ git commit --amend -m [message]
$ git commit --amend [file1] [file2] ...
|
五、分支
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
| $ git branch
$ git branch -r
$ git branch -a
$ git branch [branch-name]
$ git checkout -b [branch] origin/[remote-branch]
$ git branch [branch] [commit]
$ git branch --track [branch] [remote-branch]
$ git checkout [branch-name]
$ git checkout -
$ git branch --set-upstream [branch] [remote-branch]
$ git merge [branch]
$ 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
| $ git tag
$ git tag [tag]
$ git tag [tag] [commit]
$ git tag -d [tag]
$ git push origin :refs/tags/[tagName]
$ git show [tag]
$ git push [remote] [tag]
$ git push [remote] --tags
$ git checkout -b [branch] [tag]
|
七、查看信息
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 61
| $ 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
|
1 2 3 4
| $ git reset HEAD name
$ git checkout -- name
|
1 2 3 4
| $ git commit -m 'initial commit' $ git add forgotten_file $ git commit --amend
|
origin是服务器的名字