您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
# Git个人使用命令有哪些
Git作为当今最流行的分布式版本控制系统,已成为开发者日常工作中不可或缺的工具。本文将全面介绍Git个人使用的核心命令,涵盖从基础配置到高级操作的完整工作流。
## 一、Git基础配置命令
### 1. 用户身份配置
```bash
# 设置全局用户名
git config --global user.name "Your Name"
# 设置全局邮箱
git config --global user.email "your.email@example.com"
# 查看所有配置项
git config --list
# 查看特定配置项
git config user.name
# 设置VS Code为默认编辑器
git config --global core.editor "code --wait"
# 设置Vim为默认编辑器
git config --global core.editor "vim"
# 开启颜色显示
git config --global color.ui auto
# 设置默认分支名称
git config --global init.defaultBranch main
# 设置文件大小写敏感
git config --global core.ignorecase false
# 在当前目录初始化
git init
# 指定目录初始化
git init <project-directory>
# 克隆仓库
git clone https://github.com/user/repo.git
# 克隆指定分支
git clone -b branch_name https://github.com/user/repo.git
# 克隆深度为1(仅最新提交)
git clone --depth 1 https://github.com/user/repo.git
# 查看完整状态
git status
# 简洁状态显示
git status -s
# 添加单个文件
git add filename.txt
# 添加所有修改文件
git add .
# 交互式添加
git add -p
# 基本提交
git commit -m "commit message"
# 直接提交所有已跟踪文件的修改(跳过git add)
git commit -a -m "commit message"
# 修改上一次提交
git commit --amend
# 查看所有分支
git branch
# 创建新分支
git branch new-branch
# 切换分支
git checkout branch-name
# 创建并切换分支
git checkout -b new-branch
# 删除分支
git branch -d branch-name
# 合并分支到当前分支
git merge branch-name
# 使用rebase合并
git rebase branch-name
# 解决冲突后继续rebase
git rebase --continue
# 查看完整日志
git log
# 简洁日志
git log --oneline
# 图形化显示分支
git log --graph --oneline --all
# 查看某文件的修改历史
git log -p filename
# 按作者筛选
git log --author="name"
# 按时间筛选
git log --since="1 week ago"
# 撤销单个文件修改
git checkout -- filename
# 撤销所有修改
git checkout -- .
# 从暂存区移除单个文件
git reset HEAD filename
# 从暂存区移除所有文件
git reset HEAD .
# 软回退(保留修改)
git reset --soft HEAD~1
# 混合回退(默认)
git reset HEAD~1
# 硬回退(慎用)
git reset --hard HEAD~1
# 查看远程仓库
git remote -v
# 添加远程仓库
git remote add origin https://github.com/user/repo.git
# 修改远程仓库URL
git remote set-url origin new_url
# 推送到远程仓库
git push origin branch-name
# 强制推送(慎用)
git push -f origin branch-name
# 拉取远程更新
git pull origin branch-name
# 设置上游分支
git branch --set-upstream-to=origin/branch-name
# 创建并跟踪远程分支
git checkout -b local-branch origin/remote-branch
# 创建轻量标签
git tag v1.0
# 创建带注释标签
git tag -a v1.0 -m "Release version 1.0"
# 对特定提交打标签
git tag -a v1.0 commit-hash -m "Message"
# 查看所有标签
git tag
# 查看标签详情
git show v1.0
# 推送标签到远程
git push origin v1.0
# 推送所有标签
git push origin --tags
# 储藏当前修改
git stash
# 储藏包含未跟踪文件
git stash -u
# 查看储藏列表
git stash list
# 应用最近储藏
git stash apply
# 应用特定储藏
git stash apply stash@{n}
# 删除未跟踪文件
git clean -f
# 交互式清理
git clean -i
# 包含忽略的文件
git clean -x
git submodule add https://github.com/user/repo.git path/to/submodule
# 初始化子模块
git submodule init
# 更新子模块
git submodule update
# 递归操作所有子模块
git submodule foreach 'git pull origin master'
# 开始二分查找
git bisect start
# 标记当前为错误提交
git bisect bad
# 标记已知好的提交
git bisect good commit-hash
# 交互式rebase
git rebase -i HEAD~5
# 修改多个提交信息
git filter-branch
# 生成补丁
git format-patch HEAD~3
# 应用补丁
git am patch-file
# 创建功能分支
git checkout -b feature/new-login
# 开发过程中提交
git add .
git commit -m "Implement login form"
# 同步主分支更新
git checkout main
git pull origin main
git checkout feature/new-login
git rebase main
# 推送功能分支
git push origin feature/new-login
# 基于主分支创建修复分支
git checkout -b hotfix/security-issue main
# 修复并提交
git add .
git commit -m "Fix security vulnerability"
# 合并到主分支
git checkout main
git merge hotfix/security-issue
git push origin main
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
# 创建.gitignore文件示例
echo "*.log" >> .gitignore
echo "node_modules/" >> .gitignore
echo ".DS_Store" >> .gitignore
# 加速大型仓库
git config --global core.preloadindex true
git config --global core.fscache true
git merge --abort
git reset --hard ORIG_HEAD
# 查看历史操作
git reflog
# 重置到特定提交
git reset --hard commit-hash
# 统一换行符
git config --global core.autocrlf input
git rm --cached -r .
git reset --hard
掌握这些Git命令将极大提升你的开发效率。建议在日常工作中多加练习,逐步形成适合自己的Git工作流。记住,Git功能强大但也很灵活,遇到问题时不要害怕尝试,同时也要善用git help
命令查看官方文档。
提示:定期使用
git gc
可以优化本地仓库性能,对于大型项目特别有用。 “`
这篇文章涵盖了Git个人使用的主要命令,从基础到高级操作,共计约3800字。采用Markdown格式编写,包含代码块、标题层级和强调文本,便于阅读和理解。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。