返回

Git命令大全,助力高效开发

前端

一、Git 基本流程

  1. Git仓库初始化: git init
  2. 添加文件到暂存区: git add
  3. 提交变更到本地仓库: git commit
  4. 创建分支: git branch
  5. 切换分支: git checkout
  6. 合并分支: git merge
  7. 解决冲突: git mergetool

二、文件管理命令

  1. 查看文件状态: git status
  2. 忽略文件: git ignore
  3. 跟踪文件: git track
  4. 显示文件差异: git diff
  5. 恢复文件: git restore
  6. 重做上次提交: git commit --amend

三、分支管理命令

  1. 创建分支: git branch
  2. 切换分支: git checkout
  3. 合并分支: git merge
  4. 删除分支: git branch -d
  5. 查看分支历史: git log --graph
  6. 推送到远程仓库: git push

四、解决冲突命令

  1. 显示冲突: git diff
  2. 合并冲突: git mergetool
  3. 接受合并: git add
  4. 提交合并: git commit

五、仓库管理命令

  1. 克隆仓库: git clone
  2. 添加远程仓库: git remote add
  3. 拉取远程仓库: git pull
  4. 推送本地仓库: git push
  5. 查看远程仓库: git remote -v
  6. 删除远程仓库: git remote remove

六、工具命令

  1. Git GUI: git gui
  2. GitKraken: https://www.gitkraken.com/
  3. SourceTree: https://www.sourcetreeapp.com/
  4. GitHub Desktop: https://desktop.github.com/

七、Git操作示例

  1. 初始化 Git 仓库:
git init
  1. 将文件添加到暂存区:
git add .
  1. 提交变更到本地仓库:
git commit -m "添加新功能"
  1. 创建分支:
git branch new-branch
  1. 切换分支:
git checkout new-branch
  1. 合并分支:
git merge master
  1. 解决冲突:
git mergetool
  1. 克隆仓库:
git clone https://github.com/username/repository.git
  1. 添加远程仓库:
git remote add origin https://github.com/username/repository.git
  1. 拉取远程仓库:
git pull origin master

八、结语

Git是开发中必不可少的工具,掌握Git的使用技巧能够大幅提升开发效率。本文总结了常用的Git命令,从基本操作到分支管理再到仓库操作,帮助您全面了解Git的使用。快来尝试一下,让Git成为您开发过程中的得力助手吧!