返回
Git命令大全,助力高效开发
前端
2023-11-10 07:56:42
一、Git 基本流程
- Git仓库初始化: git init
- 添加文件到暂存区: git add
- 提交变更到本地仓库: git commit
- 创建分支: git branch
- 切换分支: git checkout
- 合并分支: git merge
- 解决冲突: git mergetool
二、文件管理命令
- 查看文件状态: git status
- 忽略文件: git ignore
- 跟踪文件: git track
- 显示文件差异: git diff
- 恢复文件: git restore
- 重做上次提交: git commit --amend
三、分支管理命令
- 创建分支: git branch
- 切换分支: git checkout
- 合并分支: git merge
- 删除分支: git branch -d
- 查看分支历史: git log --graph
- 推送到远程仓库: git push
四、解决冲突命令
- 显示冲突: git diff
- 合并冲突: git mergetool
- 接受合并: git add
- 提交合并: git commit
五、仓库管理命令
- 克隆仓库: git clone
- 添加远程仓库: git remote add
- 拉取远程仓库: git pull
- 推送本地仓库: git push
- 查看远程仓库: git remote -v
- 删除远程仓库: git remote remove
六、工具命令
- Git GUI: git gui
- GitKraken: https://www.gitkraken.com/
- SourceTree: https://www.sourcetreeapp.com/
- GitHub Desktop: https://desktop.github.com/
七、Git操作示例
- 初始化 Git 仓库:
git init
- 将文件添加到暂存区:
git add .
- 提交变更到本地仓库:
git commit -m "添加新功能"
- 创建分支:
git branch new-branch
- 切换分支:
git checkout new-branch
- 合并分支:
git merge master
- 解决冲突:
git mergetool
- 克隆仓库:
git clone https://github.com/username/repository.git
- 添加远程仓库:
git remote add origin https://github.com/username/repository.git
- 拉取远程仓库:
git pull origin master
八、结语
Git是开发中必不可少的工具,掌握Git的使用技巧能够大幅提升开发效率。本文总结了常用的Git命令,从基本操作到分支管理再到仓库操作,帮助您全面了解Git的使用。快来尝试一下,让Git成为您开发过程中的得力助手吧!