目录

Git-本地常见快捷操作

Git 本地常见快捷操作

Git 本地常见快捷操作

📌 1. 基本操作

操作命令
初始化 Git 仓库git init
查看 Git 状态git status
添加所有文件到暂存区git add .
添加指定文件git add <file>
提交更改git commit -m "提交信息"
修改最后一次提交信息git commit --amend -m "新提交信息"
显示提交历史git log --oneline --graph
显示修改的文件git diff

📌 2. 分支管理

操作命令
查看当前分支git branch
创建新分支git branch <branch-name>
切换分支git checkout <branch-name>
创建并切换到新分支git checkout -b <branch-name>
删除本地分支git branch -d <branch-name>
强制删除本地分支git branch -D <branch-name>

📌 3. 远程仓库

操作命令
查看远程仓库git remote -v
添加远程仓库git remote add origin <repo-url>
删除远程仓库git remote remove origin
推送到远程仓库git push origin <branch-name>
拉取远程分支git pull origin <branch-name>
获取远程更新但不合并git fetch origin

📌 4. 回退与撤销

操作命令
撤销 git add 操作git reset HEAD <file>
撤销最后一次提交git reset --soft HEAD~1
强制回退到某个提交git reset --hard <commit-hash>
撤销对文件的修改git checkout -- <file>

📌 5. 临时存储

操作命令
保存未提交的更改git stash
查看存储的更改git stash list
恢复最近的存储git stash pop
应用某个存储项git stash apply stash@{0}
删除某个存储项git stash drop stash@{0}

📌 6. 其他常用命令

操作命令
查看某个文件的修改历史git log -- <file>
查看某次提交的详细信息git show <commit-hash>
配置用户名git config --global user.name "你的名字"
配置邮箱git config --global user.email "你的邮箱"
列出所有别名git config --global --list
清除所有未跟踪的文件(慎用)git clean -fd