git 常用操作流程实现
一. 基础git命令
1. 身份设置实现: git config
git config --global user.name "Your name"
git config --global user.email "Your email"
2. 版本查看实现: git version
git version
3. 储存库初始化实现: git init
$ git init
或者
$ git init <your repository name>
4. 储存库克隆: git clone
git clone <your project URL>
5. 储存库文件添加: git add
$ git add your_file_name
or
$ git add * # 此命令添加所有修改过的文件
6. 将更改添加到本地储存库: git commit
git commit -m 'your useful commit message'
7. 查看需要关注的文件: git status
git status
8. 分支管理: git branch
- 列出本地所有分支
git branch
- 列出云端所有分支
git branch -a
- 创建新的分支
git branch <branch_name>
- 删除分支
git branch -d <branch_name>
9. 分支切换: git checkout
git checkout <branch_name>
- 创建检出分支
git checkout -b <your_new_branch_name>
二. 中级git命令
1. 远程连接: git remote
- 将本地储存库连接到远程
git remote add <shortname> <url>
- 样例
git remote add origin https;//gitee.com/you_git_name
2. 远程推送: git push
git push -u <short_name> <your_branch_name>
3. 远程设置: git push --set-upstream
git push --set-upstream <short_name> <your_branch_name>
4. 下载更改: git fetch
git fetch
5. 更新本地储存库: git pull
git pull <remote_url>
6. 临时储存已修改文件: git stash
- 用法
git stash
- 查看所有stash
git stash list
- 应用stash到分支
git stash apply
7. git log
- 用法
git log
git log --all
8. git shortlog
- 用法
git shortlog
9. git show
- 用法
git show <your_commit_hash>
10. git rm
- 用法
git rm <your_file_name>
11. git merge
- 用法
git merge <branch_name>
注: 我们可以使用此命令实现合并内容到自己分支。
三. 高级Git命令
1. git rebase
- 用法
git rebase <base>
2. git bisect
- 用法
- 启动git bisect
git bisect start
- 让git bisect知道什么是好的提交
git bisect good a123
- 让git bisect知道什么是糟糕的提交
git bisect bad z123
3. git cherry-pick
- 用法
git cherry-pick <commit-hash>
4. git archive
- 用法
git archive --format zip HEAD > archive-HEAD.zip
5. git pull --rebase
- 用法
git pull --rebase
6. git blame
- 用法
git blame <your_file_name>
7. git tag
- 用法
git tag -a v1.0.0
8. git verify-commit
- 用法
git verify-commit <commit>
9. git verify-tag
- 用法
git verify-tag <tag>
10. git diff
- 用法
- 将工作目录与本地存储库进行比较:
git diff HEAD <filename>
- 比较两个分支:
git diff <source branch> <target branch>
11. git citool
- 用法
git citool
12. git mv
- 用法
git mv <old-file-name> <new-file-name>
13. git clean
- 用法
git clean
14. git help
- 用法
git help <git_command>
15. git whatchanged
- 用法
git whatchanged