0%
![git工作流程图]()
1. 新建代码库
1 2 3 4 5
| git init
git clone [url]
|
2. 配置
git的设置文件为.gitconfig
1 2 3 4 5 6 7 8 9
| $ git config --list
$ git config -e [--global]
$ git config --global user.name "[name]" $ git config --global user.email "[email address]"
|
3. 增加or删除文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| git add [file1] [file2] ...
git add [dir]
git add .
git rm [file1 [file2]] ...
git mv [file-original] [file-renamed]
git rm --cache [file]
git rm -f [file]
|
4. 代码提交
1 2 3 4 5 6 7 8
| git commit -m [description]
git commit [file1] [file2] ... -m [description]
git commit -a
|
5. 撤销
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| git checkout [file]
git checkout .
git checkout [commit] [file]
git reset [file]
git reset --hard
git reset [commit]
git reset --hard [commit]
git reset --keep [commit]
|
6. 分支
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
| git branch
git branch -r
git branch -a
git branch [branch-name]
git checkout -b [branch]
git branch [branch] [commit]
git checkout [branch-name]
git checkout -
git merga [branch]
git branch -d [branch-name]
|
7.查看信息
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 status
git log
git log --stat
git log -5 --pretty --oneline
git diff
git diff --cached [file]
git diff HEAD
git diff [first-branch]...[second-branch]
git reflog
|
8. 远程同步
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| git fetch [remote]
git remote -v
git remote show [remote]
git remote add [shortname] [url]
git pull [remote] [branch]
git push [remote] [branch]
git push [remote] --force
git push [remote] --all
|